Sunday, July 16, 2006

HongKong Visit

This was my first visit to Hong Kong and I was really pleasantly surprised. Everything was very organized, and very clean. It was almost like a bigger Singapore, but with more high risers. We traveled every where on the sub way (called MTR) it was really easy to get around and cheap. They had a smart card called the Octopus card that made cash handling a real breeze. It could be used in busses, MTRs and even most grocery shops. It saved me from returning home with a pocket full of HK coins that I may never use again.

What amazed us most was the way how in which people were really organized. People always walked on the left "lane" when walking inside the MTR station. The stations had elevators, which had been divided into two lanes with a white line in between. The left lane was for people who were lazy to climb the steps, while the right was for people who were in a hurry.

Our main goal was shopping, which was a bit of a disappointment. Everything was very expensive. We did find a lot of counterfeit clothes, but they weren't as cheap as you would find in Bangkok or Singapore. I had big aspirations of being able to buy some really cool electronic gadgets. However, the mp3 player in particular that I wanted to purchase was almost the same price as what I would get in New Zealand. So I was really disappointed.

I did manage to take some interesting photos while we were there: Link

Sunday, June 18, 2006

MP3 players and Hong Kong

I will be traveling to Hong Kong (HK) in three days and one of my goals is to find a good MP3 player. As per my previous post, I had almost made up my mind to buy a Sandisk Sansa e260. However, the MP3 market has been really active in the recent past, and a few really exciting new players have come out. One example is the iriver clix. Reviewers have been raving about this player, but have also pointed out its lack of storage (only 2GB). So, it almost back to square one for me. I haven't made up a decision yet. I guess I'll just go there and see what's available. Besides, I was told that Sandisk may not be that popular in Hong Kong. We'll just have to wait and see.

Although I have traveled to other Asian countries such as Singapore and Thailand, traveling to a Chinese country would be interesting. The main aim of this trip is to travel to Taiwan, where I will be attending the ITS 2006 conference. I will be presenting a research paper there. The stop over at HK is mainly for shopping and tourism.

Thursday, May 11, 2006

Flash-based MP3 players

This blog seems to be turning out to be dedicated to JavaScript. So I thought of adding something completely different. I've been looking for an MP3 player. More specifically, my requirement is to listen to music during my exercise (mostly). I already have a cheap Chinese MP3 player that I picked up while I was in Singapore, but it's battery is useless. It has an average battery life of about one hour, which is really annoying. So I've been reading reviews on what's available and trying to figure out the best value for money player out there. I of course love gadgets, so the new gadget should be flashy and packed with extra features that I may never use!!

After reading about hard-disk based players and learning about their problems with skipping I decided to focus on a flash memory based player. Another reason for focusing on a flash memory based player is the weight factor. Hard disk players are always heaver and would feel bulky in my pocket. Hopefully, the flash-based players also have a better battery life as they do not have any moving parts.

My research revealed that there are currently three top of the range flash-based players with over 4GB memory: iPod nano, Sandisk e200 series, Samsung YP Z5. Sandisk are the only company to have a 6GB flash player. The iPod is the thinnest player and then the other two are similar in size. The Sandisk is the thickest (slightly). While investigating the different features that each player offered, I realised that the features can be divided into hardware features and software. To me the extra software that the player comes with is irrelevant. I'm sure I will be able to find the necessary converters etc. So features that I've labelled as software are features offered by the player itself.

In terms of hardware features, all three come up with standard features expected from a portable music player. All three have colour screens; the screen of the ipod is smaller (1.5") compared to the others (1.8"). The ipod and samsung player both have very simillar features. The sandisk player has extras like an FM tuner and video playback. Ipod has a few neat extra software features like a calendar, contacts and games.

To me, battery life is paramount. In the end, I decided to go with the Sandisk player, because it had a battery rated 20 hours and was removable. I've heard so many horror stories about ipod batteries. I think most problems are because of its instant-on feature which keeps draining battery life by going into hibernation mode. The iPod can never be completely turned off, it always goes to hibernation mode. The Samsung player has a really good battery, but it doesn't have the extras such as radio and movie playback.

Now, only if I can buy a Sandisk sansa e260 or e270 in New Zealand!!

Syntax highlighting using Javascript

I've been looking around for a web-based source code editor. My search was for an editor embedded in a web page which would allow the modification of code stored in a server. This does not mean an editor for editing web-technology related source files. Searching the web mostly resulted in editors for JavaScript, html etc.

Currently About:Edit is a very good source code editor. It is commercial product that provides a lot of features including syntax highlighting. Its impossible to hide the source code of JavaScript apps, so my inquisitiveness got the better of me. I had a look at their source code. The code is very complicated and they have tried very very hard to make it as obfuscated as possible.

I came across some guy who had a post on their blog (I can’t acknowledge the source as I've lost it), a nice proof-of-concept of using JavaScript for syntax highlighting a static page. His idea was simple; use regular expressions to search for keywords in a document and then replace them with formatted text. Here’s an example,

var keywordPattern = /\band|not|null|equalp|match\b/g;

var text = document.getElementById("constraints").innerHTML;
document.getElementById("constraints").innerHTML =
text.replace(keywordPattern, function(text) {
return "" + text + ""

The code looks for a set of keywords (and, not etc) and adds a span tag around it. It works like a charm.

This is no solution to my intial problem of an code editor. However, it does provide a nice way of displaying code.

Wednesday, April 05, 2006

Object and their methods in Javascript

I've been looking around to find a really nice way of defining classes and their methods in JavaScript. I am aware that there are numerous libraries out that have defined their own syntax for defining classes and their methods etc. However, my quest was to find a solution that did not require any extra libraries.

I'll explain it with an example;

function Student(name){ = name;

/*toString method of student class */
Student.prototype.toString = function (){
return "My name is " +;

The example outlines a very basic "Student" class that has a 'name' property and a 'toString' method. Since properties and functions are both objects in Javasctip we can define a class using the function keyword. It basically involves defining a constructor for the class. Since the "Student" class takes in 'name' as an argument, the "Student" class can be instantiated as;

studentObj = new Student("Bob");

The "Student" class also contains a method called 'toString'. The method is assigned to Student.prototype to ensure that there is only a single copy of the method for each instance. I found an artitle, which suggested that this.prototype.toString = function() {} is the right syntax. However, it does not work with Firefox. Firefox complains about prototype not having any properties.

Once an instance has been created its methods or properties can be accessed by using the '.' (dot) operator.


Objects in JavaScript makes it easier to reuse JavaScript code. As a lot of interface code is written in JavaScript, using an object oriented programming style would be advantages in the long-run.

On a side note; I discovered the proper way to check whether the a variable is null in JavaScript.
if(!someVariable) instead of if(someVariable!=null)

Tuesday, April 04, 2006

Javascript Syntax Validation

I am real fan of AJAX (not the cleaning product - I think my wife is a fan of that!). The really annoying thing about producing an AJAX front end for a web application is the lack of good free tools for Javascript. I recently stumbled upon the Web tool project (WTP) of the Eclipse foundation, who's goal is to produce a plugin for Eclipse (the greatest editor) to handle all AJAX languages like HTML, Javascript, CSS etc. Although the WTP plugin adds syntax highlighting functionality for Javascript, it does not perform any of the useful features that Eclipse has been synonymous for Java like Syntax checking, highlighting variable occurrences etc.

I searched on the web for a syntax checker for Javascript. I know that Firefox has a plugin which outlines syntax errors while running the script. However, I wanted to eradicate syntax errors before running a script, because there are other errors to worry about when running a script.

I came across Javascript Lint, which has a really neat utility for checking for Javascript syntax errors. It also provide a downloadable little app that can check the syntax of scripts as a command line utility or even as a right click option in the windows file explorer.

Javascript Lint uses Firefoxe's Javascript engine to check for syntax errors. I came across this article which seems to say that the Firefox JS engine was very strict. However, my experiences with it have been ok so far.

Monday, April 03, 2006

Using awk to calculate the total times by parsing a log file

I came across a problem that I imaged would be very common to anyone trying to run an experiment with a software product: 'Analysing a log file and calculating a the total time a user has been performing a certain task'. A number of solutions exist, one of which is to export the whole log to a spreadsheet app like Excel and calculate the differences of time using a simple formula. However, using spreadsheets can be very tedious. The Linux shell command, Awk allows the creation of small scripts that completely automates the whole process. For windows users like me, cygwin is freely available (

Here's the script that I used;

BEGIN {total = 0}
/.*system_login/ { sprintf("date +%%s -d '%s %s'", $1, $2) |
getline tmstamp1;}
/.*system_logout/ { sprintf("date +%%s -d '%s %s'", $1, $2) |
getline tmstamp2;
print (user " " $1 " " tmstamp2 - tmstamp1);
total += tmstamp2 - tmstamp1;
END{print (user " total " total);}

The awk language is a bit cryptic but nothing to be afraid of. The main idea of awk is it searches for a patter and performs a command on the found line. Each command is formatted /search pattern/action/. More information available at So the second line of the script decodes, search for occurrences of "system_login" (with any thing in front) and perform the date extraction command that follows.

An awk script has a begin part, a body part and an end part. The being part is executed prior to anything else, so initialisation goes there and ending is just before the script quits. The body is where the actual logic is performed.

I've used the shell "date" command to convert a date to a value in seconds. However, you can't simply go result = system("date ...") (system can be used to execute a shell command within awk). It only returns result of command 1 or 0. So the command has to executed using sprintf and piped to getline.

Since I had a log file under the name log.dat in a directory created that corresponds their login name, I had to loop through all the directories using a for loop;

for i in *; do awk -f process-times.awk user=$i $i/log.dat ; done

Thursday, March 30, 2006

Compacting email folders in thunderbird

My email client, thunderbird, was extremely slow last night and I thought it may be because I had too many emails in my inbox. 'Fair enough' I thought and started deleting some of them. Thunderbird started behaving very strangely and labeling some of my old emails as 'unread' and being extremely unresponsive. This spurred my inquisitiveness and I tried to figure out what was going on but looking at the files that contained my emails. Thunderbird creates a file for each email 'folder', which contains a text file containing all emails. It also contains an msf file for each email 'folder' that keeps track of only headers (basically a list of pointers to emails in email file).

Although I kept deleting emails from thunderbird, it didn't seem to be affecting the size of the email file. I came across this 'compact' feature in thunderbird and tried it. However, no luck! No change to the size of my email file. I decided to consult my the oracle, "Google". It told found me an article of some one who had a similar problem or not deleting emails from the email file although they were deleted. That led me to a page at Mozilla ( which explained that Thunderbird actually kept the deleted emails labelled as deleted. It also had a description of how to 'compact' a folder if the 'compact' option does not work. It told me to delete the msf file and restart thunderbird. Thunderbird then rebuild the msf file and I was managed to use the compact folder option to get rid of all the crap that was already deleted.

Why in the world do we need emails to be labeled as deleted in the inbox while the trash folder also contains a copy? I realized that thunderbird actually has an option that can be set to automatically compact folders if it gets beyond a certain point. Why can't this be automatically enabled? I think what put me off more what the message that asked "Do you want to compact the folder and save space?". My hard disk is about 80Gbs. Why would I need to save a few Kbs? But then again, what I didn't know was that if the email file gets beyond a certain point, the whole mail client starts playing up!!

Moral of the story, compact your email folders regularly. Or set the option which performs it automatically.