Monthly Archives: October 2008

Sprinkle more AJAX for usability study

Recently I have developed a website that has a rich user interaction on the client side. A lot of dynamic html, javascript, DOM manipulation and mashups with JSON. After all that, as days passed by and I notice people visiting to the website, I had no way of knowing what the users were doing. Or the using the system the way it’s intended? Are they even aware of how to use it?

In the meantime I introduced a new AJAX call to the system to record a particular end action as that’s important to me and then observed that people were eventually reaching that end action. That’s when I realized that, by sprinkling the AJAX calls at the appropriate places, it would be possible to get a lot more information about how such highly interactive and complex user interfaces on the website are being used by the end users.

Leave a comment

Filed under AJAX, Usability

UTF-16 to UTF-8

I recently downloaded a csv file of a report from a report generating system and tried opening it in vi editor and all I saw was some garbage like a binary file. When opened in notepad, it looked fine as expected, as a plain text file. I thought there was problem with the ftp and I tried different things like zipping the file and then doing the ftp and so on. But nothing worked. Opening with emacs didn’t work either. Then, I tried opening it with some notepad like application on Linux and the first thing it did was show an error saying that it didn’t understand the encoding and asked me to pick one. I picked UTF-16 and then it started showing up.

Well, now that I knew what the problem was, how do I convert it to UTF-8? I need to convert it to UTF-8 because, the version of perl I was using didn’t support various encodings (research on the web indicated the need to compile with perlio option or something like that and that wasn’t the case for me). So, I used Java to achieve this. It’s really very simple. Here is what it would look like.


public class UTF16toUTF8 {
  public static void main(String[] args) {
     BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(args[0]),"utf16"));
     String line;
     while((line = br.readLine()) != null)

That’s it. This simple piece of code was a real time saver for me.


Filed under Tech - Tips, UTF

Don’t Be Evil, Locally, The New Google Motto

This article says that Google is reversing it’s self imposed policy of not allowing gambling related ads in the UK. The article says

[Google has been reviewing its gambling advertising policy “to ensure it is as consistent as possible with local business practices”, said James Cashmore, industry leader, entertainment and media, at the company. “We hope this change will enhance the search experience for users and help advertisers connect with interested consumers.”]

There are many local businesses that are illegal in most parts of the world. But, hae, if there are millions of dollars at stake, why not? So, the “Don’t be evil” all of a sudden got qualified with geography.

Leave a comment

Filed under Google

DHTML: removeChild or div.innerHTML?

I ended up with a strange issue today, a difference in behavior between IE and FF (tell me something new huh?).

I have some dom nodes and they are dynamically inserted into a popup div as needed. So, before they are inserted, I first need to clear the popup div itself. I was doming (made a typo for doing but thought this is appropriate as well, “doming”) like

div.innerHTML = ”;
// add the existing nodes by context

This worked in Firefox. In IE, it did work, but subsequent popups started not showing the inner nodes being added. So, I changed the above to

for(var i=div.childNodes.length-1;i>=0;i–) div.removeChild(div.childNodes[i]);
// add the existing nodes by context

And this started working. So, it looks like when div.innerHTML is set to blank, or may be some other value for that matter, the existing nodes in the div and their content is being cleared up by IE, while firefox doesn’t clear up the contained nodes.

1 Comment

Filed under DHTML, javascript

JavaScript Associative Arrays (HashMaps) & Prototype.js & Object

Today I spent a lot of time figuring out what’s going on with the for loop over an Array. Finally realized what’s going on and hence this post.

In JavaScript, if you need to create associative arrays (hashmaps), then there are two ways to do it. Actually, there is only one way, but I will get to that in a minute.

var hmap = new Array();
hmap[0] = “hello”;
hmap[1] = “world”;

Here, the hmap array is used as a normal array.

var hmap = new Array();
hmap[“abc”] = “hello”;
hmap[“def”] = “world”;

is perfectly valid. Here, the hmap is used as an associative array. So far so good.

I had a bit of code where I loop through the keys of the hashmap and need to make use of both the keys and the values. So, the code was something like

for(var key in hmap) {
// do something with key and hmap[key]

I remember doing this several times in the past without any problem. But today, when using this pattern along with prototype.js, I ended up getting, in addition to the keys I put in, additional keys starting with “each”. Where the heck is this “each” and a whole bunch of other keys coming from? After a bit of digging I found Array @ article that the prototype.js script actually adds several useful methods to the Array. And the right way to access the elements in the Array is to use the hmap.each method that enumerates all the elements. But in my case, I want both the key and value, so I couldn’t use this method.

After some more reading, I finally realized that it’s actually the Objects that are associative arrays in JavaScript. That means, rather than using Array for the hmap, I could simply use Object. So, by changing the code from

var hmap = new Array();


var hmap = new Object();

I could use the regular

for(var key in hmap) { /* do something with key and hmap[key] */ }

without any problem inspite of using prototype.js

Interesting how things could go wrong with prototype based languages, no pun intended.

1 Comment

Filed under javascript