Prefer Collections over Arrays


How to Make Money with the Amazon Associates Program


How to Make Money with the Amazon Associates Program

Amazon Affiliate Program provides different kinds of ads.

Native Shopping Ads

  • amzn_assoc_placement should be unique.
  • amzn_assoc_search_bar: false/true to whetehr show the search bar.

Custom Ads

Custom Ads allows us to curate specific products from Amazon that you would like to recommend and place the ad unit into your webpage. All we need is find a list ASINs of products and add them into amzn_assoc_asins.

<script type="text/javascript">
amzn_assoc_placement = "adunit0";
amzn_assoc_search_bar = "false";
amzn_assoc_tracking_id = "the_tracking_id";
amzn_assoc_ad_mode = "manual";
amzn_assoc_ad_type = "smart";
amzn_assoc_marketplace = "amazon";
amzn_assoc_region = "US";
amzn_assoc_title = "Best books for algorithms interview";
amzn_assoc_linkid = "the_amzn_assoc_linkid";
amzn_assoc_asins = "0984782850,1517671272,1617292230,032157351X,1537713949,0262033844,111941847X,819324527X";
</script>
<script src="//z-na.amazon-adsystem.com/widgets/onejs?MarketPlace=US"></script>

<div id="amzn-assoc-ad-19c89cc6-6f8f-485d-a31a-7bc49e98e831"></div><script async src="//z-na.amazon-adsystem.com/widgets/onejs?MarketPlace=US&adInstanceId=19c89cc6-6f8f-485d-a31a-7bc49e98e831"></script>

Recommendation Ads

  • Displays products related to your page content and visitors
  • We can choose “Emphasize Categories”.

Search Ads

  • Display search results from Amazon.com by specifying a search phrase and selecting a relevant category to your page content in a responsive ad unit that works across screen sizes.

  • We can specify a list of search phrases and sort them by priority, random pick one search phrase and stick to it in the X(10) days.

<script type="text/javascript">
  function createCookie(name, value, days) {
    if (days) {
      var date = new Date();
      date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
      var expires = "; expires=" + date.toGMTString();
    } else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
  }

  function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(";");
    for (var i = 0; i < ca.length; i++) {
      var c = ca[i];
      while (c.charAt(0) == " ") c = c.substring(1, c.length);
      if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
  }

  function deleteCookie(name, path, domain) {
    if (readCookie(name)) createCookie(name, "", -1, path, domain);
  }

  function pickOne(weightedPosts) {
    var totalWeight = 0;
    for (let post of weightedPosts) {
      totalWeight += post.weight;
    }
    var randomWeight = Math.random() * totalWeight;
    var currWeight = 0;
    for (let post of weightedPosts) {
      currWeight += post.weight;
      if (currWeight > randomWeight) {
        return post;
      }
    }
  }
</script>

<script type="text/javascript">
var pos = readCookie("amazonItemPos")
var products = Array("iphone",  "iPad Pro", "iPad Mini", "apple watch series 4", "MacBook Pro", "MacBook Air", "google pixel 3", "chromebook", "Amazon Echo");

var items = new Set();
var totalCount = products.length;
for (var i = 0; i < products.length; i++) {
  items.add(
    {
      product: products[i],
      weight: totalCount - i,
      pos: i
    }
  );
}
// var item = items[Math.floor(Math.random() * items.length)];
if (pos == null || pos <0 || pos > products.length) {
  // pos = Math.floor(Math.random() * items.length);
  pos = pickOne(items).pos
  createCookie("amazonItemPos", pos, 10);  
}

var item = products[pos];
amzn_assoc_placement = "adunit3";
amzn_assoc_search_bar = "true";
amzn_assoc_tracking_id = "the_tracking_id";
amzn_assoc_search_bar_position = "bottom";
amzn_assoc_ad_mode = "search";
amzn_assoc_ad_type = "smart";
amzn_assoc_marketplace = "amazon";
amzn_assoc_region = "US";
amzn_assoc_title = "";
amzn_assoc_default_search_phrase = item;
amzn_assoc_default_category = "All";
amzn_assoc_linkid = "the_amzn_assoc_linkid";
</script>
<script src="//z-na.amazon-adsystem.com/widgets/onejs?MarketPlace=US"></script>

Tips

Mockito Best Practices


User Scripts to Change Html5 Video Player Speed


The Goal

I Would like to change the speed of HTML5 video player at pan.baidu.com, so I can spend less time on the video and finish it sooner.

The Implementation

I found some user script at greasyfork for Chrome with tampermonkey extension

Based on these 2 script, I made the following simple user script that can change video speed to 1.5, 1.75, 2.0.

Other Ideas

  • Able to resume playback of a video at the point in time it was left.

Labels

adsense (5) Algorithm (69) Algorithm Series (35) Android (7) ANT (6) bat (8) Big Data (7) Blogger (14) Bugs (6) Cache (5) Chrome (19) Code Example (29) Code Quality (7) Coding Skills (5) Database (7) Debug (16) Design (5) Dev Tips (63) Eclipse (32) Git (5) Google (33) Guava (7) How to (9) Http Client (8) IDE (7) Interview (88) J2EE (13) J2SE (49) Java (186) JavaScript (27) JSON (7) Learning code (9) Lesson Learned (6) Linux (26) Lucene-Solr (112) Mac (10) Maven (8) Network (9) Nutch2 (18) Performance (9) PowerShell (11) Problem Solving (11) Programmer Skills (6) regex (5) Scala (6) Security (9) Soft Skills (38) Spring (22) System Design (11) Testing (7) Text Mining (14) Tips (17) Tools (24) Troubleshooting (29) UIMA (9) Web Development (19) Windows (21) xml (5)