Inside the mind of a master procrastinator

“Inside the mind of a master procrastinator”

Inside the mind of a master procrastinator — Tim Urban on TED

Using custom NSError in your Objective-C project

Small tip on using NSError in your Objective-C project.

You can set NSError’s localizedDescription by using key NSLocalizedDescriptionKey, as illustrated in the following example.

NSError *error = [NSError errorWithDomain:@"com.example.myprojectname" code:1
  userInfo:@{NSLocalizedDescriptionKey: @"My custom error message!"}];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error!"
  message:error.localizedDescription delegate:nil cancelButtonTitle:@"Dismiss"
  otherButtonTitles:nil, nil];
[alertView show];

Reduce boilerplate codes for NSCoding

For Objective-C developers who developed models that requires serialization, CoreData and NSKeyedArchiver are the options provided by Apple for object/data serialization.

I will not cover these options but you can read more about NSCoding and Data Serialization from this excellent article by Mattt Thompson.

The one issue I have with implementing NSCoding is how frequently I have to type the boilerplate codes. See the following for an example as given by Mattt.

- (id)initWithCoder:(NSCoder *)decoder {
    self = [super init];
    if (!self) {
        return nil;

    self.title = [decoder decodeObjectForKey:@"title"]; = [decoder decodeObjectForKey:@"author"];
    self.pageCount = [decoder decodeIntegerForKey:@"pageCount"];
    self.categories = [decoder decodeObjectForKey:@"categories"];
    self.available = [decoder decodeBoolForKey:@"available"];

    return self;

- (void)encodeWithCoder:(NSCoder *)encoder {
    [encoder encodeObject:self.title forKey:@"title"];
    [encoder forKey:@"author"];
    [encoder encodeInteger:self.pageCount forKey:@"pageCount"];
    [encoder encodeObject:self.categories forKey:@"categories"];
    [encoder encodeBool:[self isAvailable] forKey:@"available"];

Luckily, after doing some googling, I stumbled upon Speeding up NSCoding with Macros article at

Using macros to reduce the amount of boilerplate codes is a good idea, as illustrated in the following example

- (id)initWithCoder:(NSCoder *)decoder
    self = [super init];
    if (self) {
    return self;

- (void)encodeWithCoder:(NSCoder *)encoder

Here’s my implementation for encoding and decoding datatypes of object, float, double, bool.

#define OBJC_STRINGIFY(x) @#x
#define encodeObject(x) [encoder encodeObject:x forKey:OBJC_STRINGIFY(x)]
#define decodeObject(x) x = [decoder decodeObjectForKey:OBJC_STRINGIFY(x)]
#define encodeInteger(x) [encoder encodeInteger:x forKey:OBJC_STRINGIFY(x)]
#define decodeInteger(x) x = [decoder decodeIntegerForKey:OBJC_STRINGIFY(x)]
#define encodeFloat(x) [encoder encodeFloat:x forKey:OBJC_STRINGIFY(x)]
#define decodeFloat(x) x = [decoder decodeFloatForKey:OBJC_STRINGIFY(x)]
#define encodeDouble(x) [encoder encodeDouble:x forKey:OBJC_STRINGIFY(x)]
#define decodeDouble(x) x = [decoder decodeDoubleForKey:OBJC_STRINGIFY(x)]
#define encodeBool(x) [encoder encodeBool:x forKey:OBJC_STRINGIFY(x)]
#define decodeBool(x) x = [decoder decodeBoolForKey:OBJC_STRINGIFY(x)]

Unsupported locale setting (Ubuntu)

If you get “Unsupported locale setting” in Ubuntu after a fresh installation of Ubuntu, it is due to the default locale is not set yet.

You can fix this error by doing the following

export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
locale-gen en_US.UTF-8
sudo dpkg-reconfigure locales

Solution mentioned in

Retrieving latitude and longitude from Google Map

If you need latitude and longitude of a specific location, like trying to inject location coordinate to your mobile emulator, just locate and center that point in Google Map

Just enter the following


into your web browser and a Javascript prompt will appear and the latitude & longitude of the center point in the Map View in the following format (<latitude>,<longitude>)

Web Server Benchmark Performance

Apache Software Foundation has provided an useful tool to assist developers to test out the performance of their website using their program ab

To install ab in ubuntu:

apt-get install apache2-utils

Once you got ab installed, refer to the following for how to use the ab command:

# replace the following <total requests>, <number of concurrent request>, <url> with their respective values
ab -n <total requests> -c <number of concurrent request> <url>

Display Hidden Files/Folders in Mac OSX

Use the following script to toggle between displaying and hiding hidden files/folder in Mac OSX.

# check if hidden files are visible and store result in a variable
isVisible="$(defaults read AppleShowAllFiles)"
# toggle visibility based on variables value
if [ "$isVisible" = FALSE ]
  defaults write AppleShowAllFiles TRUE
  defaults write AppleShowAllFiles FALSE
# force changes by restarting Finder
killall Finder

Start/Stop script for Java jar executables

Need to start/stop java jar executables via bash scripts?

Refer to the following example script:

export JAVA_HOME=/usr/local/java/

case $1 in
    echo $$ > /var/run/;
    exec 2>&1 java -cp ${CLASSPATH} org.something.with.main 1>/tmp/xyz.out 
    kill `cat /var/run/` ;;
    echo "usage: xyz {start|stop}" ;;
exit 0

Reference: Monit Wiki

SSHFS on Mac

SSHFS is a way to mount remote folder over SSH, you could cut/copy/paste as though as you were accessing a local folder/file. It’s a good way to free web developers from having to run ftp/sftp every time for any changes needs to be uploaded.

SSHFS is based on MacFUSE. MacFUSE allows you to extend Mac OS X’s native file handling capabilities via 3rd-party file systems. You can read up more on SSHFS and MacFUSE at

Start by downloading SSHFS

# Downloading SSHFS
cd ~
svn co sshfs-binaries

After downloading the latest SSHFS, you are ready to start mounting remote folder via SSH.

# Mounting the SSH file system
sshfs user@host:/some/directory /some/mount/point -oauto_cache,reconnect,volname=<volname>

Note: you will need to replace the above snippet with the respective configuration you need.

Android Activity Life Cycle

Android Application Life Cycle is one of the most important things Android programmers needs to understand about, else not knowing it will come back to haunt you on several occasions.

Alt Android Activity Life Cycle Picture

ROR (Ruby On Rails)on Windows 7

I been pretty much jack of all trade, but master of none, for my IT knowledge, especially with Programming Languages.

And this time, it’s time for me to learn about Ruby and learn Rails for web development.

For those who do not know about Ruby (Programming Language), here’s a description from Wikipedia:

Ruby is a dynamic, reflective, general-purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features.

Ruby has been regarded as a Language that allows “Rapid Development and Prototypes”, which is important for developers as the lesser time we spent bashing the keyboard, the more time we have to design and work on those cool features.

By using Rails as it can generate basic base codes for developers looking to create web application, which developers benefit from the “Structured Code and Neat Markup” for developing their web application based on MVC architecture. In addition, “Interchangeable Databases” and “Database Schema Control” will save developers by allowing them to start developing their application using sqlite, which is the default database available right after creating the Rails web application, so developers could work on features that require database without having to setup database.

Benefits of using Ruby on Rails will go into another article, (do check out an article on Ruby on Rails here) for now i will describe the process to install ROR on Windows 7:

Go to RubyForge and download and install the latest version of the Ruby one-click Installer for Windows. RubyGems is like extension/module manager for Ruby, so do ahead to download RubyGems and install using the following command: gem install rubygems-update-1.8.1.gem

Download the pre-compiled version of SQLite3, both the “shell” and “dll” archives from the SQLite web site, unzip them and copy those unzipped files to c:\Ruby192\bin directory. (I had installed Ruby 1.9.2). Now that SQLite3 is installed, just install the gem: gem install sqlite3--include-dependencies

When Ruby and RubyGems have both been set up, run this in a terminal/command prompt window to install Ruby on Rails and all its dependencies: gem install rails --include-dependencies

On to the final few steps, first create a folder to hold your rails Apps. You may proceed to create a test application by issuing this command in a terminal/command prompt: rails new test_app

You should then see a folder called test_app. Go into the testApp folder in a terminal/command prompt and type this: rails server

Finally, open your browser and go to http://localhost:3000/. You should be able to see a default Ruby On Rails page indicating that you have successfully install and run your first ROR project.

Connecting to Wireless@SGx (WPA secured) in Linux using Wicd

Wireless@SG is a free WIFI hotspot service provided by some vendors in Singapore.

Wireless@SGx is the answer to secured(encrypted) connection to the former unsecured WIFI hotspot.

Manual or instructions are provided for all major platform, like Windows, Mac and even all mobile platforms, except Linux.

So this tutorial will show you how to connect to Wireless@SGx using Wicd, a graphical wireless configuration tools for Linux.

  1. Fire up Wicd Network Manager. Alt Wicd Network Manager
  2. Click on “Properties” for the Wireless@SGx network. Alt Wicd Network Manager Properties
  3. Ensure that “Use these settings for all networks sharing this essid” and “Use Encryption” checkboxes are checked.
  4. Enter your Wireless@SG username for “Identity” and your Wireless@SG password for “Password”.
  5. Click “OK” to save the configuration.

You are now all setup for connecting to the secured Wireless@SGx, just click on “Connect” and start surfing away.