Dec 3, 2012

[Solved] JQuery File Upload is Not Working with Express 3

Posted Dec 3, 2012
I tried to incorporate the Node js implementation of JQuery File Upload with Express 3. It uses Formidable middleware for parsing multi-part data which is not compatible with Express 3's body parser. Fortunately, there's a quick fix:

//just replace express.bodyParser() with:

From Myk's explanation in StackOverflow, Express uses express.bodyParser() as a convenience method to wrap 3 parsers (express.json, express.urlencoded and express.multipart) into one.

Alternative Solution:

Another approach is to redefine the multipart parser of Express (co elmigranto):

var express = require('express');
var bodyParser = express.bodyParser;

bodyParser.parse('multipart/form-data') = function(req, options, next) {
 //custom parser or:

//don't forget to use the variable bodyParser in your configuration

Dec 1, 2012

Cute and Geeky Anniversary Gift

Posted Dec 1, 2012
My friend bought a domain for his interior-designer girlfriend on their second anniversary. Awwwww, cute.. and geeky :) Don't you love how technology brings us closer?

Even comes with a lovely poem . You may check the site at

Nov 29, 2012

How to Hide the Share Buttons of Blogger

Posted Nov 29, 2012
If you are using third-party sharing buttons such as Add This, you'll notice that the default share button of Blogger is left behind:

Fortunately, removing this is very easy. You just need to find where the setting is:
  1. Go to Layout Setting of Blogger

  2. Click the Edit link

  3. Untick Show Share Buttons option in the pop-up setting

Congratulations, your default share buttons are now hidden from view. 

Nov 27, 2012

SVN Revert a file to a Previous Version

Posted Nov 27, 2012
svn merge -c -[revision number] [file]

svn merge -c -80 Classes/MyClass.m
80 is the revision number

Or if you want your entire revert your workspace:
svn merge -c -80 .

Nov 25, 2012

Node JS - Listen to External IP Address

Posted Nov 25, 2012
I wanted to try my local server in an iPad device and when I accessed its external port ( in our intranet, it's not working. At first I changed the listen address from to and it worked, the problem was I cannot access http://localhost:3000 after. In addition, this approach of hardcoding the address is not an acceptable solution in the long run; there must be another way.

How to make your node js server listen to external ip

The fix is easy but not very intuitive. Just change the listen address from to

I encountered a minor hiccup: I stored the address in a global variable and used it in a special function that accessed my own server. So my function was trying to access and it wouldn't work this way. So I just retained the for my special functions.

I wonder why node js decided to implement it this way (or I'm not sure if it's Express js that's the culprit here). Why not just listen to all available IP Addresses when you specify Maybe it's a security issue; I don't know.

[Update 18-Feb-2013] As "Reality Check" pointed out, NodeJS can listen to any IP address if you don't specify the host parameter. It's right here in NodeJs API:

server.listen(port, [hostname], [backlog], [callback])
Begin accepting connections on the specified port and hostname. If the hostname is omitted, the server will accept connections directed to any IPv4 address (INADDR_ANY).

Nov 15, 2012

Change the Back button Title in iOS UINavigation

Posted Nov 15, 2012

I thought it was straightforward to alter the title of the back bar button item. Turns out you need to define the entire back bar button item in the calling screen.

In the calling controller (meaning, the parent controller where you will push the new controller), add this in viewdidload:

self.navigationItem.backBarButtonItem =  [[[UIBarButtonItem alloc] initWithTitle:@"Custom Back Title"
                                   action:nil] autorelease];

My mistake was I keep changing the backBarButtonItem of the new controller! Sheesh, Apple.

Nov 11, 2012

Chrome reloads sprite image on CSS image hover

Posted Nov 11, 2012
The image flickers on hover in Google Chrome when I have the following code:
#MAIN_MENU a.foodMenu {
 background: #000 url('../images/home_icons.jpg') -525px -176px no-repeat;

#MAIN_MENU a.foodMenu:hover {
 background: #000 url('../images/home_icons.jpg') -525px 0  no-repeat;

It seemed that my image was not preloaded fully so I tried preloading the image using javascript or css but to no avail. Found out that the problem is not in the preloading of image, it's the css definition. Apparently, Google Chrome thoughts it needs to reload the image even if you are using the same one.

The solution:
#MAIN_MENU a.foodMenu:hover {
 background-position: -525px 0;

Do not use background property to re-define the hover. Use background-position only to re-position the sprite. That's it!

Nov 10, 2012

Node.js: exports vs module.exports

Posted Nov 10, 2012
If you've been using node.js, you're probably familiar with the following scenario:

exports.title = 'The Alchemist'

var book = require('./book');
console.log(book.title); // prints "The Alchemist" to console

In the above, "exports" allows us to call the property "title" of book.js. However, this approach always requires us to define and call a method or property. The object returned by "require('./book')" is the exports object which is created by the node.js framework but what if we want our own custom object returned?

This when "module.exports" becomes useful:

module.exports = 'The Alchemist';

var book = require('./book');
console.log(book); // prints "The Alchemist" to console

In the above, notice that we don't need to call any method of book to be able to use it. In some cases, module.exports may be more convenient. In Express js, I use this approach to modularize my routes.

Nov 8, 2012

Use Node.js 0.8.14 or any custom version in Openshift

Posted Nov 8, 2012
It's relatively easy to set-up a different version of node js in Openshift:

1. rhc app create -a nodeapp -t nodejs-0.6
-- you can add "-s" to make the app scalable e.g. rhc app create -a nodeapp -t nodejs-0.6 -s

cd nodeapp
git remote add upstream -m master git://
git pull -s recursive -X theirs upstream master

3. Edit .openshift/markers/NODEJS_VERSION and specify the version you want, e.g. 0.8.14

4. Commit then git push

That's it! Happy coding!

[Updated March 2013] Created a Swig, Mongoose, Passport, Zurb Foundation and Node JS 0.10.1 package in github for OpenShift. I confirm that OpenShift works with Node JS 0.10.1

> rhc app create -a nodeapp -t nodejs-0.6

> rhc cartridge add mongodb-2.2 --app nodeapp

> cd nodeapp
> git remote add upstream -m master

> git pull -s recursive -X theirs upstream master

-- Edit .openshift/markers/NODEJS_VERSION commit then git push

Nov 6, 2012

[Solved] iOS didrotatefrominterfaceorientation is not called

Posted Nov 6, 2012
There are cases that did rotate method (didRotateFromInterfaceOrientation:) of a view controller is not triggered. A workaround is to manually call it from you main view controller, but if you don't have time, an easier fix is to use notifications:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];

Place the above in your controllers view will appear, and don't forget to unregister it in view did disappear.

- (void)didRotate:(NSNotification *)notification {
  //do your post-rotation logic here


Oct 23, 2012

Top iOS programming bloopers for this week

Posted Oct 23, 2012

These are my top iOS bloopers for this week (and corresponding fixes):

  1. For proper spacing of Toolbar Items in iOS you can use

    UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

    //this will center-align myButton
    [self setToolbarItems:[NSArray arrayWithObjects: flexibleSpace, myButton, flexibleSpace, nil]];

    or you can also use

    UIBarButtonSystemItemFixedSpace system item and set the width.
  2. 2nd or Bottom Navigation Toolbar in a popover (UIPopoverController)

    It is actually the toolbar item of the navigation controller.

    Assuming you added a navigation controller in a popover for the title,
    using initWithContentViewController: [UINavigationController]

    To show bottom toolbar, just set the navigation controller's toolbarHidden to NO.
  3. When changing the width of a UIBarButton, I often try to find the frame, but it's not there. Apparently, just set it directly using setWidth method.
  4. Change Navigation Controller's Back Button Title or Text
    Just accessing the backBarButtonItem will not work, you have to set the button entirely.
     self.navigationItem.backBarButtonItem =
          [[[UIBarButtonItem alloc] initWithTitle:@"Back"
                   style: UIBarButtonItemStyleBordered
                   action:nil] autorelease];
  5. UIButton is not showing , also related topic: UIBarButtonItem not showing UIButton custom view

    [btn setBackgroundImage:image forState:UIControlStateNormal]
    instead of
    btn.imageView.image = .. //ugh

    The same way if title is not showing, use:
    [btn setTitle:itemTitle forState:UIControlStateNormal];
    instead of
    btn.titleLabel.text = ..

Oct 11, 2012

Show GSP directly in Grails 2

Posted Oct 11, 2012
Starting Grails 2.0, you cannot access GSP's directly when you type it in the url without defining it in url mappings. It has been disallowed since it's considered a security flaw of Grails 1.x. The side-effect is for simple static pages, it's a hassle to create mappings everytime.

Fortunately, Grails allows a simple workaround by using the UrlMappings.groovy. You just need to define one controller and make its actions accessible in url mappings configuration.

These are the steps I followed to quickly see all my root pages:
  1. Create a StaticViewController
  2. My UrlMappings.groovy contains:

Creating a controller is my preferred way, it's an additional step but my views are more manageable this way. 

For this example, I defined the following in my StaticViewController:
def index() {

def hello() {

Then added the ff gsps:

I can now access the following in my browser:

To make your urls more search engine friendly, you may also want to map urls that ends in "html" to your controller, just add this line in UrlMappings.groovy :

In this case, I'll be able to access:


Oct 5, 2012

How to force Google to reindex your site or blog - kind of

Posted Oct 5, 2012

Google Webmaster Tools has a page for submitting a url to Google. Google will queue then try to re-index the requested page, but it doesn't guarantee that it will do so. Here's the extracted disclaimer:

Google adds new sites to our index, and updates existing ones, every time we crawl the web. If you have a new URL, tell us about it here. We don't add all submitted URLs to our index, and we can't make predictions or guarantees about when or if submitted URLs will appear in our index.

I guess it means they will try their best! It's better than nothing :)

The full url of the tool is

Oct 1, 2012

Google Apps Free Edition

Posted Oct 1, 2012
I use Google Apps for my domain name purchases because it comes with the Google goodies and easy to integrate with their services like Blogger. Now, I can't find the free edition anywhere on their front page, it seems it has been deliberately removed, maybe to promote the paid version.

Good news is there's still a link to access the free version of Google Apps. As of writing (October, 2012), you can access it here:

Source: Tech Crunch

Jun 21, 2012

Use Anywhere Pad to Conduct Meetings on your iPad, iPhone and Android devices

Posted Jun 21, 2012
Anywhere Pad is an e-meeting app for iPad and iPhone. It's a cool app and it's free, and yes I'm affiliated with Azeus. This is more of a TEST than a promotion.

Anywhere Pad is a lot of things: Document collaboration on your mobile device, meeting application, document management, scheduling, annotations, etc. It also won the Best Ubiquitous Networking Award (Mobile Enterpries Solution) in Hong Kong.

Anyway, I just want to see the Google ranking of this post.

We showed some love for Android, so it's coming to this platform too. It's now available on Android and Window platform.

So what else can I write in this entry to boost ranking..  hmm it's Enterprise grade, secure, you can draw your annotations and highlight words. You can host the meeting using your local network (through WiFi) or through internet using Azeus portal server. Meet with people, use it for board meetings, collaborate with a colleague, etc.

Tested on iPad 1, iPad 2, iPad 3 (New iPad), iPhone 4, iPhone 4s. Okay, don't know what else to say. Just download it and try. I wonder if this page will make it on the first page of Google results.

And to give my biased rating: 4.5

May 30, 2012

MySQL Error : Incorrect information in file

Posted May 30, 2012
I copied an entire WAMP folder from an old computer in an attempt to revive a PHP application. When I started its mysql service and tried to query the tables, I got this:

MySQL Error No. 1033 Incorrect information in file: [filename].frm

I can see the list of tables but I cannot query, it was like the data has been corrupted. When I checked the logs in [wamp folder]\bin\mysql\[mysql folder]\data\*.err, I also found the following:

InnoDB: Error: log file .\ib_logfile0 is of different size 0 10485760 bytes
InnoDB: than specified in the .cnf file 0 5242880 bytes!

  1. Stop the MySQL service,
  2. delete both ib_logfile0 and ib_logfile1 found in  [wamp folder]\bin\mysql\[mysql folder]\data
  3. and start MySQL service again.

May 29, 2012

MS Word to PDF displays boxes when viewed in iOS (iPhone / iPad)

Posted May 29, 2012
If the text in your PDF displays boxes when viewed iPad or iPhone, one of the cause might be the conversion of MS Word to PDF.

Try these simple steps to see if it resolves the issue:
  1. Open MS Word
  2. File -> Save As
  3. Select PDF type
  4. Click Options
  5. ISO 19005-1 compliant (PDF/A) should be ticked.
  6. Try to save the document to PDF and view it in your iPhone / iPad.

I'm using MS Word 2010 and Windows 7.  PDF is properly displayed in desktop and Android devices, but in iOS (UIWebView, Safari, etc), the text is just a series of black boxes; like it's been highlighted with a black marker. The fix above solves the issue.

May 24, 2012

Singleton Pattern in Objective-C (iOS) and release method (oneway) issue

Posted May 24, 2012
Apple gives a good sample on how to create a singleton class; I've modified it a bit for iOS programming:

static MyGizmoClass *sharedInstance = nil;

+ (MyGizmoClass*) sharedInstance
    if (sharedInstance == nil) {
        sharedInstance = [[super allocWithZone:NULL] init];
    return sharedInstance;

+ (id)allocWithZone:(NSZone *)zone
    return [[self sharedInstance] retain];

- (id)copyWithZone:(NSZone *)zone
    return self;

- (id)retain
    return self;

- (NSUInteger)retainCount
    return NSUIntegerMax;  //denotes an object that cannot be released

- (oneway void)release
    //do nothing

- (id)autorelease
    return self;

  1. Used "sharedInstance" method and variable name to make it easier to copy paste.
  2. - (void) release to - (oneway void) release
    The singleton sample produces a warning in the release method because NSObject uses the "oneway" return type modifier. It's basically an indication that the method is used for asynchronous messages. For more details on what oneway does, offers a good explanation.

May 15, 2012

Grails Session Timeout

Posted May 15, 2012
To increase or decrease the default session time-out in grails:

In your project folder, first execute (if you haven't execute this yet):
grails install-templates

After this, you'll be able to see your web.xml in [project folder]/src/templates/war/

Add / modify the code in web.xml


I place the snippet above after my servlet-mapping. The value "60" is in minutes.

Tested on Grails version 2.03. Enjoy!

May 8, 2012

Sublime Text 2 and Command Line Integration

Posted May 8, 2012
A little background: Sublime Text 2 is the ultimate programmer's notepad (Thanks to Lan for introducing me this tool). I've been using it since last year especially when editing Grails applications and so far I'm loving it.

One thing that's lacking out of the box is the shell integration; a way to launch the command line and pass your project's folder path for convenience. Fortunately, there's a package for it. It's called Shell Turtlestein.

  • You can install Shell Turtlestein using Package Control. If you don't have Package Control yet, I highly suggest you install it.
  • When you have the Package Control, access it through Preferences menu > Package Control.
  • Select "Install Package" and search for Shell Turtlestein and select it.
  • After the package is installed, you can use ctrl + alt + shift + C (in Windows) to launch the command line.
  • You can also use ctrl + shift + C to prompt for a shell command.

Search Terms:
  • sublime text 2 command line

Apr 19, 2012

Slow CATiledLayer on New iPad 3 Retina display

Posted Apr 19, 2012
Noticed the poor performance of PDF rendering using CATiledLayer on the iPad 3. You can see the tiles loading one by one; it's terrible.

We tried increasing the tile size, we also tried the workaround found in Stackoverflow of setting the contentScaleFactor to no avail. Hope Apple release an update to address this issue. 

Apr 11, 2012

Desktop Clients for Alfresco: Fred vs FlexSpaces

Posted Apr 11, 2012
Why do we need a desktop client when we already have the browser application? Convenience, speed and added productivity.

So far I've seen two mention-worthy desktop clients for Alfresco:
  1. Fred by XeniT (Commercial)

    I've tried it and was extremely pleased with the interface; it's very clean and highly functional. It just works. Sure you can use IMAP, CIFS and Alfresco Office Extension / Addon to get the same features but I especially like the idea of putting those essential features conveniently into one user-friendly application.

    The only downside of this is it's a paid subscription, but for large organizations I believe this is worth it.
  2. FlexSpaces (Free, Open Source)

    What's great about FlexSpaces is that it's a cross-platform software. It can run on Windows, Mac, Linux and even on mobile devices: iPad, Android devices, and BB Playbook. It's free and the license is LGPL.

    A bit of a letdown is the interface, it's not yet polished. Functionality is excellent, but it can get quite confusing at times.

Apr 10, 2012

Switching from Development to Production mode STS + Grails + CloudFoundry

Posted Apr 10, 2012
STS (as of version 2.8), by default, uses development environment when deploying a Grails application to server. Usually you would want to deploy your application in production mode instead to get the best performance.

To do this in STS, go to your project properties and navigate to Grails > Run On Server. Change the value from "dev" to "prod".

Hope this helps. My website has been deployed in Cloud Foundry for more more than a year and only now I've discovered that it's running in development mode!