Disable 3rd Party Cookie In Chrome Will Also Disable 3rd Party Flash Cookie

I have just found out when you disable third party cookie in Chrome settings, the third party flash cookies will also be disabled. This applies when you are using Chrome’s native flash player, but the third party flash cookie will still be avaiable if you are using Adobe’s flash player in Chrome.


This gives you quite inconsistant behaviour if your application is using flash cookie (shared objects).

It took me quite a while to figure out, hopefully it can help for other people.

Hive Export/Import Command – Transfering Data Between Hive Instances

When working with Hive, there are lots of scenarios that we need to move data from one cluster to another. For instance, sometimes we need to copy some production data into alpha/dev environment for testing purpose. Luckily that Hive provides two easy commands for us to do it.

Since version 0.8, Hive supports EXPORT and IMPORT features that allows you to export the metadata as well as the data for the corresponding table to a directory in HDFS, which can then be imported back to another database or Hive instance.

The command looks like this:

EXPORT TABLE <table_name> TO 'path/to/hdfs';

Please note that you don’t need the “/” in front, otherwise Hive will complain about invalid path or target is not an empty directory. And the final data will be written to /user/<user_name>/path/to/hdfs directory in HDFS (of course, it will need to be writable by the current user).

The next step is to copy the data across to another Hive instance, you can use the “distcp” command from Hadoop:

hadoop distcp hdfs://:8020/path/to/hdfs hdfs:///path/to/hdfs

Once the copy is finished, you can then use the IMPORT command on the new cluster to load the data into a new table:

IMPORT TABLE <table_name> FROM 'path/to/another/hdfs';

Now you will have the exact same data in the new cluster as the old one. The transfer should be smooth, the only thing is that if the data is big, it might take a while for “distcp” to copy the data across.

For more information, you can have a look at the Apache Hive’s Confluence Page

Keypress Event Does Not Work in Chrome For Escape Key

It is very common these days to allow your web page to respond to your website users using key shortcuts. Recently I was working on a project to display an overlay on top of a page (lightbox style), and the third party that I used is called iBox. It worked great and very light weight, but it had a problem with “Escape” key to get user back to the web page, i.e., hide the overlay. This is what the coder used (slightly modified version):

    window.addEventListener('keypress', function(e){
        if (e.keyCode == (window.event ? 27 : e.DOM_VK_ESCAPE)) {

The code is simple, We just want when user presses the “Escape” key on the keyboard to hide the overlay that was displayed on the screen. This worked in latest FF, but not in Chrome. And looks like it does not work for all the keys on the first line of my keyboard (I use Mac keyboard, not sure whether this is the cause of the issue or not).

In order to capture the this event, I need to use “keydown” instead:

    window.addEventListener('keydown', function(e){
        if (e.keyCode == (window.event ? 27 : e.DOM_VK_ESCAPE)) {

Problem solved, but not an obvious one. Hope this helps.

Javascript Array Map With ParseInt Function

When you want to turn all elements in an array from strings to integers, it comes to common sense that you want to use the Array.prototype.map function with Javascript’s built-in function parseInt:







var numbers = ["1", "2", "3"];
var new_numbers = numbers.map(parseInt);

However, this will give you unexpected output of:

[ 1, NaN, NaN ]


Well, this is because "map" passes more arguments into the callback function:

callback(item, index, array);

This works fine if your callback function only accepts one arguments, which will be “item”. However, “parseInt” function receives two arguments:

parseInt(string, base)

So in our case the actual value of “index” got interpreted as “base” in the parseInt function, and of course it will give you very unexpected result.

The solution is to create a small function which wraps the “parseInt”:

var numbers = [“1”, “2”, “3”];
var new_numbers = numbers.map(function(x) { return parseInt(x, 10) })

This should get you green lights in your test cases :).

onTouchMove Caused iFrame Scrolling Slow in iPad

In the last few days I needed to build a modal which loads a iFrame inside to display a third party content, and the target devices includes desktops, mobiles and tablets.

There is no problems to display the content on desktop, scrolling works, modal popup works. However, the frustration comes when testing on iPad and mobiles. Even when I have added “overflow: hidden” to the body tag, iPad and mobile browsers still allow users to scroll the background when modal is popped up. To fix this, I need to disable the “touchmove” event at the document level:

document.ontouchmove = function(e) { e.preventDefault(); };

This actually works on iPad, though not entirely in Android. However, this actually caused another issue which causes the scrolling in the iframe very slow. It took me quite a while to find the root cause.

In the end I had to remove the “touchmove” event handling because this scrolling slowness issue is far more serious than the background content scrolling when modal is in place (my modal is about 100% over the background anyway).