Saturday, February 22, 2014

Express.JS quick-start guide on Windows


Express.JS is a fairly new but increasingly popular Node framework for building web application. Being a Node based application means you spin up a web application in just few steps. In this guide, I’m going to show a quick-start on just how to do this on Windows.

  1. Install node.js. See this tutorial if you don’t already have node.js on your Windows.
    • I’m using node v0.10.25, and express 3.4.8 on this guide.
  2. Create a directory for your new Express.JS app, run Command Prompt and cd into the directory. e.g. c:\users\<user name>\projects\fooApp
  3. Install express.js via npm ‘Node Package Manager’ that comes together with node.
    • In the Command Prompt, execute:

      npm install –g express

    • Watch and wait for npm to complete fetching the required dependencies for express.js. It’s going to take a while.
  4. Once installation completed, you will be presented with a summary of what packages has been downloaded and it’s respective version.
  5. Verify the Express.JS is installed and check it’s version with the command:

    express –-version

    Express will response with it’s version number.
  6. Before continue with creating an Express app, have a look at what options is available for creating an Express app.

    express –-help

    • If you do not specify any options, express will use it’s defaults that you see from this help screen
  7. Go ahead and create an express app. Execute:

    express fooApp

    For the sake of simplicity, I’m not going to specify any options.
    • Express will shows a summary of what has been created, and notice that there are 2 short instructions and the end of the summary. So we going to follow exactly that.
  8. Before proceed with the instructions, lets have a look at the content of fooApp/package.json

    cd fooApp
    more package.json

    • Like any other node.js application, the package.json defines the basic information for fooApp and it’s dependencies.
  9. Next we will install the related dependencies:
    npm install
    • Once completed, npm will again shows a summary of what have been downloaded.
  10. Before proceed to run fooApp, take a quick look at these 3 files:
    • fooApp\app.js
    • fooApp\routes\index.js
    • fooApp\views\index.jade
    • app.js – This file define the runtime configuration for fooApp

      routes\index.js & views\index.jade – This is the default route that will be executed when browse to fooApp.
      This give us an idea of what to expect to see when browse to the fooApp, and more importantly the basic idea of the MVC pattern in an Express.JS application.
      The *.jade file is template using node template engine jade.
  11. Proceed to run fooApp, in the Command Prompt, execute:

    node app.js

  12. Browse to http://localhost:3000
    • It works, just like magic.

Thursday, February 13, 2014

Installing and upgrading node.js on Windows

Steps for installation:

  1. Go to and download the latest version of node.  I'll proceed with the Windows Installer (.msi) version.
    1. You can also go to to download installer for other platform.
  2. Run the node-XXXXXXXXXX.msi installer, and proceed to installation like a normal Windows application (basically just Next... , Agree, Next … Finish). I'd strongly suggest that you accepts all the default configurations and selections during the setup.

  3. Once installation completed, start a command prompt and type "node --version" and verify that it shows the version of node.

Steps for upgrade:

  1. I personally don't use any special tools to switch between version of nodes,  I prefer install if using the same Windows Installer. (If you uses all the default settings during setup, upgrading is simple repeating the installation steps to overwrite  the current version of node)
  2. If you want to use NVM (Node Version Manager) kind of tools that available to Linux users, you can use take a look at Nodist ( You can get Nodist via Chocolatey (

Friday, January 3, 2014

Generating INSERT statement from SELECT using SQuirreL SQL

There are often time during development where you would want to test your application with various type of sample data, and you would want those data to be share with other team member as well.

The scenario that I ran into recently is we have some sample data that was enter to a system through a web interface, and for reports developments purposes we need those data to be shared among the team members, so we start to look into exporting those data out using SQL SELECT statements (with the correct WHERE clause) then converting them to equivalent INSERT statement; there are of cause several ways to do this, but I prefer the easy way, using SQuirreL SQL. The insert script can them be shared among the team members.

Following is the steps for completing this

  1. Install SQuirreL SQL
    • Make sure you have JRE7 installed on your machine
  2. Create connection to you database
    • Depending on your database type you need to use different drivers
    • Create the Alias to your database and enter the right connection strings (this can be tricky sometime)
  3. Start the connection session to you database
    • Select your alias and hit the Connect icon 
  4. Write you select statement and run it (CTRL+ENTER)
  5. Bring up the Tools dialog box (CTRL+T)
  6. Look for sql2ins and hit Enter
  7. Done. You will see INSERT statement will be generated right after your SELECT statements.
You can customize what columns you want on the generated INSERT statement by only specifying them in the SELECT statements, and don't forget you can also limit the records by specifying the where clause in your SELECT statements.

There you go, another magic trick.

Saturday, September 14, 2013

Default icons in Windows Phone SDK (use with ApplicationBarIconButton)

Windows Phone SDKs comes with icons that one can also use when developing an app, especially when creating an app bar (aka ApplicationBarIconButton),
These icons are located at

C:\Program Files (x86)\Microsoft SDKs\Windows Phone\vX.X\Icons\

There are different sets of icons, namely the dark icons set for use with a dark windows phone theme, and light icons set for use with light theme, and there is also vector based icons set.

Note: You should only use the icons under the dark folder, during runtime, Windows Phone will automatically put colors on the icons according to the theme selection

Always looks at the icons set and see if you can reuse any of the icons before creating yours, chances are high, icons you needs are already there.

Below is a snapshot of icons available in SDK v7.1 (32 icons)

icons for SDK v7.1

Add there are slightly more icons for SDK v8.0 (37 icons)

icons for SDK v8.0

Also, check out how to create an app bar using XAML on MSDN.

Thursday, August 15, 2013

Disable Gmail Inbox Tabs

If you're a Gmail user, your going to notice that recent changes to the user interface, that's right, there are several tabs now. If you've not seen it, you will soon. Google has decided to roll out the Inbox tabs to all Gmail users.

Gmail's welcome message for Inbox tabs
I've been a Gmail user since it's early days, and this tabs thingy really makes me uncomfortable, I believe there are others out there that has the same feeling as I am. Fortunately, as of today, there is still a way to disable the tabs. And I'll shows you how to do it.

Right after you log in to Gmail, you will be introduce to to the new Inbox interface, where you will see 3 default tabs: Primary, Social & Promotions.

The new Inbox tabs

You emails will be parked under different tabs, this solely depend on what Google think they should be. (and there's an ads pretending to be an email)

Promotions tabs

Moving email between tabs
You can manually move messages between tabs and make them stays on that tabs for future incoming emails. Or you could just 'star' an email to make it appear on the Primary tabs.

All that is good if you want to use tabs to organize your inbox; For me, the existing 'labels' feature are more than enough organize my emails, so I'm going to disable Inbox tabs.

To do this, navigate to the Settings icon on the top right corner and select Configure inbox.

Configure inbox tabs menu

You will be prompted with a dialogue box where you can then select which tabs you wants to enable or disable by checking or un-checking.
Selection of tabs to enable / disable
So go ahead and un-check like crazy. Apparently you can't un-check the Primary tab, because that's where all emails are going to stay when all tabs are gone.
Un-check Social and Promotions to disable those 2 tabs
Hit Save button and you'll be notify that Inbox tabs have been switched off.

Cool, now I get back the old Inbox interface.

Inbox without tabs

Saturday, June 15, 2013

Customizing Windows Command Prompt

Having spend much time switching between Windows, Linux and OS X. I figure my Windows Command Prompt could use a little tweak at least on the PROMPT.

Basically from this single line prompt

To this (basically making the path section on a separate line than the prompt input)

Just like on other platform, the command prompt load it's configuration from the environment variable, and the variable that changes the prompt is "PROMPT".. duh...

Head over to configure Environment Variable on Windows and add a new variable to overwrite PROMPT

Setting it to $P$G$_$$ should do the trick.

You can also modify the prompt using the SETX command to modify the global environment variable. So just type this on a prompt


Following is a list of variable that you can use to customize the prompt

 $A   & (Ampersand)
 $B   | (pipe)
 $C   ( (Left parenthesis)
 $D   Current date
 $E   Escape code (ASCII code 27)
 $F   ) (Right parenthesis)
 $G   > (greater-than sign)
 $H   Backspace (erases previous character)
 $L   < (less-than sign)
 $N   Current drive
 $P   Current drive and path
 $Q   = (equal sign)
 $S     (space)
 $T   Current Time
 $V   Windows version number
 $_   Carriage return and linefeed
 $$   $ (dollar sign)

Minor tweak and the prompt just looks cleaner.

Saturday, April 20, 2013

ObjC Optimization Tips

Over the past few weeks, I've been focus on doing performance tuning on a iPad app. 

A little background of the app

It is an business app, doing financial investment. It has lots of moving parts on the GUI, user can drag, slide and flipping, a graph, and lots of numbers and dates. User can play around with different combination of input and see their investment prediction over few years. There were around 50 parameters (or more) that affects actual calculation result. The app has at least 8000 lines of codes just for doing calculation. 

The story
The Product Owner has been complaining to the team that the app has a serious performance issue. It's sluggish and the financial result does not reflect user's interaction immediately (PO generally don't care how complicate you back-end is). The financial graphs took ~5 seconds to redraw on screen, when user is moving the slider, and they are moving it continuously back and forth.

Tools I uses for this task.
I mainly use Xcode's Instrument tools to analyst and tune the performance. It has been proven to be an extremely useful tool set.

My Verdicts
The following are the result of my findings. Some of this are pretty basic, but I find some of our experience iOS developer still does it. So I think it's important to spell it out to remind everyone.

  1. NSDate, NSCalendar and NSDateComponents.
    1. NSDate is often used in-conjunction with NSCalendar and NSDateComponents, converting a date to string for display on view is unavoidable; though they provide more functionality they tends to have high tax on performance. Only use this when your need more then what the standard C type time_t can't provide what you need.
    2. If you do use the C type it, please test it properly because there are cases where the C type can't handle.
          Tips: Use C type time_t for heavy date related calculation. E.g. On a graph.
  1. NSNumberFormatter and NSLocale
    1. I use NSNumberFormatter and NSLocale to format numbers into da_DK locale (Danish locale)
          Tips: Create the object once and reuse especially on moving part of the GUI, e.g Graph
  1. NSDateFormatter
    1. This is same as #2. Create once and store it in memory for reuse.
  2. NSDecimalNumber and NSNumber
    1. Boxing and unboxing NS data type are expensive. Don't do them in a loop. A way to do this is to make all the interrelated method use the same data type signature.
  3. NSString
    1. You can never avoid to perform operations on NSString in any type of programming language. Concatenating, splitting, substring or converting it to different data type is an expensive operation.
  4. NSMutableArray or NSArray 's KVO and NSPredicate or NSSortDescriptor
    1. KVO is convenient for doing summation, finding max or min in a collection; but it’s 10 times slower then a normal for loop.  KVO itself is doing loop internally.
    2. NSSortDescriptor is another things you should be caution when using in a loop. They can be really slow as they are doing loops internally.
Last but not least
These are not all that causes the app be sluggish, but they are the main causes. If you look really closely you will notice deep down under those methods mentioned above, they are mostly "string" manipulation or comparison related functions.

Happy coding.