Showing posts from 2012

GitHub Wiki - Anchor link for page headers

Was trying to do a table of content in Github Wiki just now and realize there aren't much guide on that. After searching for a while, I found this comment on Github that shows how to do it.

1. Add anchor for the header that you want to link to
# <a name="heading1"/> Heading 1
2. Add the link to the anchor
[link to heading 1](#wiki-heading1)

Example usage:

Amazon AMI install MongoDB Driver

Did an installation of MongoDB driver for PHP on my Amazon EC2 AMI just now. And thought of noting the steps down.

Prerequisites  Make sure the following packages are installed.
$ sudo yum install gcc $ sudo yum install make $ sudo yum install httpd mod_ssl $ sudo yum install php $ sudo yum install php-devel php-pear $ sudo yum install pcre-devel
Install MongoDB driver for Amazon Linux Installing Mongo driver.
$ sudo pecl install mongo

Enable the driver
$ sudo vi /etc/php.d/mongo.ini $ $ sudo /sbin/service httpd restart

Testing The simplest way to check whether the installation is successful is via phpinfo().
<?php phpinfo(); ?> And you should see the following section:

Or test the connection using the code snippet below :)
<?php // connect $m = new Mongo("mongodb://"); // select a database $db = $m->{"sample-test-mongodb"}; // select a collection (ana…

Encoding issue with Chinese characters

Was having issue with encoding on PHP (server side) to be printed out on via Javascript (client side).

The problem The Chinese characters were fine when output directly from PHP, became garbled after encoded and decoded on using javascript.
printf('document.write(unescape("%s"));', rawurlencode($data)); 

Solution After Googled for a while I realize the best solution, I think, is to convert the foreign characters to unicode numeric entities. Example:
Numeric CodeHTML Entity CodeResult256&#256Ā
Solution for PHP For PHP there's a simple solution: mb_encode_numericentity(). Luckily the convmap for conversion (excluding HTML character) are in the comment. (As pointed in

function convertToNumericEntities($string) {     $convmap = array(0x80, 0x10ffff, 0, 0xffffff);     return mb_encode_numericentity($string, $convmap, "UTF-8"); }

Solution TinyMCE If you are using TinyMCE, this can be solved by enabling "numeric" fo…

Uncaught SyntaxError: Unexpected token ILLEGAL

Was coding in NetBeans just now and stumbled upon this error:
Uncaught SyntaxError: Unexpected token ILLEGAL  I'm very sure there is no syntax error on that line. But chrome just wouldn't stop complaining about it.
After debugging for a while, I realize its the extra unidentified character (space/eol) that is causing the error.

Deleting that solves the problem :)

Macbook Pro - Signals the Transitions of Computing Devices

Just read a post on the new Retina MPB to buy or not to buy,
...we just happen to be at the beginning of a transition of the Mac into its next phase. In some ways, this is a mid-life crisis.
and Robert Scoble's Facebook post on touch screen devices.
Looking at my life and that of my coworkers I'm seeing less and less of a reason to stick with a traditional laptop. 
I'm also very certain that this is the transition period for computing devices. Transitions from traditional laptops to ultra-portable high performance touchscreen devices.

High Performance Computing Notebook Looking at the new MBP :

Ultra-portable - 0.71", 2kg512GB flash storage You can almost anything on-the-go with this new notebook - compile source codes, render HD videos, or even play games. It would be hard to imagine any would still get an iMac, unless you are going for serious 3D/HD graphics rendering with 16GB RAM and SSDs. 
Looking at the trend, I couldn't agree more with MG Siegler that its ju…

Setting up Repo on Amazon EC2 for Git Push

Was trying to setup an instance on Amazon which I can do a git push to update the /var/www/html folder. Decided to share the steps here, so that other beginners like me can benefit too!

PrerequisitesSetting up Amazone Instance 
This article basically covers all the steps need to fire-up an instance and set the Security Group and SSH.

Install LAMP + phpMyAdmin
Install LAMP stack is easy, but install phpMyAdmin is slightly tricky. Luckily this github gist explained the steps very well.

The only missing part that you might want to take note is the part to change the user of the html directory.
sudo chown -R ec2-user /var/www/html/

Setting up GitSetting Up Git Repo to work with /var/www/html folder
At first I tried this solution from stackoverflow post. The method is:
Copying .git folder to /var/www/html/ folder.Then use a post-update script to update the git repo.The idea looks logical, and easy to understand, but I just couldn't get it to work.

Then I found this article, by Abhijit Menon-…

Installing Redis: jemalloc/jemalloc.h: No such file or directory

Was trying to install Redis on my EC2 test server just now and bump into this error.
zmalloc.h:51:31: error: jemalloc/jemalloc.h: No such file or directory I was very sure that jemalloc was installed.

After searching for a while, I found the solution from redis-db Google Group.

Apparently, running
make distclean solves the problem. It remove all compilation artifacts, and dependencies.


Reintialize TinyMCE after jQuery Load

Bump into the problem of reintializing TinyMCE textbox after replacing the DOM with jQuery load.

The Problem
After saving a form on a page (with multiple forms), I did a jQuery.load() to replace the DOM of the particular section.Then I run the initialization function to reinitialize all DOMs, including TinyMCE. I realized TinyMCE contents is not saved after this.
Solution: Initial attempt

After Google-ed for a while, I found this solution from StackOverflow.

tinymce.execCommand('mceRemoveControl', true, 'editor_id');
So, to use it, it would be...

_init = function() { /* Some other initialization code here */ tinymce.execCommand('mceRemoveControl', true, 'editor_id');tinyMCE.init({ /* TinyMCE options */ }); }
Oh, wait...

Some issues:
My 'editor_id' is dynamic... I have multiple textboxes
Solution: Second attempt.

Easy. Just use jQuery.each() to loop through all the textbox and remove TinyMCE control from each of them.

_init = function() { jQuery(&…

[Guide] Samsung Galaxy S2 ICS

For those of you who are like me - too impatient to wait for Samsung Singapore to release ICS update for i9100 Galaxy S2, can follow the following steps to flash to ICS (and in addition, flash to CM9).

Ice Cream Sandwich 

1. Download ICS firmware

2. Boot into Download Mode
Turn off phone.Vol Down + Home + Power

3. Odin Flash Guide

ICS is cool, but... the official ROM is still laggy. So I decided to take further steps to mod it to CyanogenMod.
So if you are like me, want a smooth UX, follow the following optional steps :)

3. CF-root by Chainfire.

4. Remove Yellow Triangle during startup, using TriangleAway from Chainfire.


5. Download CM Bui…

Why Hotmail SmartScreen Should do Better

Got this spam mail that looks as if its from my other email account (Yahoo Mail).

Further inspect on the header reveals that the mail is from hotmail_631448ecb4add0e [at] And the mail server is actually from the IP

Why Hotmail SmartScreen not doing its job

SmartScreen should have filtered the email content, based on EITHER one of the following criteria, that can be implemented by checking just the email header.

1. The email content is obviously spam content. Nuff said.

2. The sender is obviously from a "anonymous" email that pretends to be another email.

3. The IP ( of the mail server is OBVIOUSLY hosted on a spam source. This can be easily detected by cross-check with one of the spam database out there. For example

These are simple methods to provide minimal layers protection for Hotmail users. 

(Notice I haven't even go into advanced SPAM fighting techniques like using DMARC)


SmartScreen team s…

Bootstrap Tools

Biggest Mistakes

The biggest mistakes for new (or inexperienced) developers, like me, is to jump straight into coding a website.
There are so many bootstrap tools (or so caller boilerplates) out there for you to start, without falling into the pitfalls of bad (really bad) designs. I'm speaking from my personal experience, with Lunchsparks.

Along the way of "designing" and coding, both at the same time, I poorly designed the elements in the website, from layouts (grids, containers, tables) to buttons (color, states).

The Tools

These are two tools that I came across recently, which I think its awesome! These tools encapsulated the almost (if not all) the elements for designing a great (responsive) website.

Bootstrap, from Twitter
A very clear demo site that demonstrate what the tools (javascripts, and css) does. Recommended for new learners.

HTML5 Boilerplates
By Paul Irish. A very cool Googler that I follow on social networks and blogs.


Here are some other tools that I…

[CodeIgniter] MySQL NOW()

Was trying to do insert/update using CodeIgniter Active Record helpers, and realize the usual way of inserting doesn't work, because the helper functions actually escaped the values to prevent SQL injection.

So we can't do the just group all the data together the easy way.
$data['field1'] = $data1; $data['field1'] = $data2 $data['created_date'] = 'NOW()'; $this -> db -> insert($this -> tables['some_table'], $data);
There are two possible ways to go around this.

1. Use CodeIgniter $db -> set() function, with the additional FALSE parameter to prevent data from being escaped.
$this -> db -> set('created_date', 'NOW()', FALSE); $this -> db -> insert($this -> tables['some_table'], $data);
2. Use PHP data function to generate datetime string. The only thing to note with this method is, in most cases, the PHP server time and the MySQL time is different.
$data['created_date'] = date('…

[Template] Javascript Functions

Been dealing with Javascript functions lately, I find that these are the most-frequently-used input parameters for all a typical function:
data url (optional) callback (optional)
A good JS function should readily accept these parameters. And a typical Javascript function call would be like:
somefunction( {data: value, data2: value2 }, [url], [callback()] ); We know that in PHP we can use the following method to write a "optional" second (or third) input parameter.
function somefunction( $data, $callback = FALSE); This way, if the second argument is not supplied, $callback will be automatically assigned to FALSE. Its a good practice to set a default value for a variable.

After Googling around, I found that Javascript is event better at handling such case. We can take in as many optional input parameters, in no specific order. But the trade-off is, we need a check for the input parameter type.

Stackoverflow has this excellent post on the template for checking input argument typ…

CSS text-overflow

Notice: This is a beginner post (that some of you might think is a waste of time)
CSS3 has tons of awesome improvement, which a lot of them I don't know or notice. Today, I discovered "text-overflow" style, which is super handy for hiding overflowing text.

I discovered while browsing the source for (Actually I was looking a the scrollbar for the side panel wondering how it works and accidentally stumble upon this :p ).

Notice the the longer text "Acquaintances" changes to "Acquaintan" when the width of the parent container shrinks.

The style behind this is

overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
You might wonder why I'm so excited about this? Because in the past, I used to do a lot of text-length-checking on the server side before outputting the text, reducing the number of characters and append "...".

Now this can be done easily on the browser part using just CSS!

No more inefficient coding with the b…

[ROM] Galaxy S2 i9100DXKL3 Firmware

New (Dec 2011) official firmware (South East Asia) for Samsung Galaxy S2.

PDA: i9100DXKL3

Build Info: Thu Dec 15 18:59:02 KST 2011

Firmware Download :


Q: How to check the current firmware version of my phone?

There are several ways:
1. Key in *#1234# in the dialer. You'll get the PDA, Phone, and CSC version of your firmware, or
2. Download Z-Device Test from Android Market.