Thursday, December 22, 2011

Test rails api using curl

curl -i

Monday, October 24, 2011

Git remove untracked files and directories

git clean -df PATH

Friday, October 21, 2011

Kill detached screen session

screen -XS SESSION NAME quit

Sunday, September 11, 2011

Free up disk space from Dropbox sync

Ran out of disk space on my puny Macbook Air SSD. After tuning down using "Selective Sync", OSX disk utility still reports 7.9GB of space used by ~/Dropbox folder.

rm -rf ~/Dropbox/.dropbox.cache/*

That solved it. Apparently that hidden folder caches files for easy undelete within 3 days.


Friday, September 9, 2011

Check disk usage in OSX

du -sh *

Friday, July 1, 2011

Fix Terminal in OSX not sourcing .bashrc

Bash in OSX looks for ~/.profile rather than ~/.bashrc so just create the former and add the following.

if [ -f ~/.bashrc ]; then
. ~/.bashrc

Wednesday, June 29, 2011

Write testable Git commit messages

Having been a project manager for a couple of projects, I often find myself having to decipher team mate's code commits by digging into code diffs. Take for example.

# Poor commit message with lack of information
fix bugs on email template

Hmm. What bugs is he trying to fix? How would I know if it's really fixed? What if he wrote instead

# Slightly better with description of what the bug is
fix bugs on email template that caused HTML misalignment

Ah, that's better. At least now there's a WHAT context that I can focus on when looking through the diffs. This could possibly be enhanced with a HOW context.

# Even better message
fix bugs on email template that caused HTML misalignment by declaring inline styles on elements

Great, now the only thing left to the piece of the puzzle is WHO determined that those were bugs?

# Almost perfect
[#31] fix bugs on email template that caused HTML misalignment by declaring inline styles on elements

Ok a reference to the bug request on Github would help me find out who requested the issue.

This leads me to the concept of writing good testable commit messages. Example,

# A great testable commit message.
[#55] Added inline styles on HTML elements to fix bug that caused misalignment on email templates

That's a great commit message because it can be tested. I could fire up the email mailer and check that the email is indeed aligned properly. And it saves the project manager and the other team mates valuable time by cutting down time spent deciphering what the code was meant to do. Even more important if the commit messages were to be viewed many months down the road.

Sunday, June 5, 2011

Heroku multiple machines

heroku auth:login # log in with your heroku credentials
heroku keys:add # add a key for the current user

Wednesday, May 25, 2011

Translations / internationalization for active record error messages

Active Record will look for messages in this order:


So example for validation for email format

# app/models/membership_requests.rb
validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i

# config/locales/en.yml
invalid: "is not a valid email address"


Thursday, May 19, 2011 API

Latest stable - v3.0
Rate limit - 5 concurrent users / IP address
gem -

gem install bitly
When you HTTParty, you must party hard!
Successfully installed crack-0.1.8
Successfully installed httparty-0.7.7
Successfully installed addressable-2.2.6
Successfully installed multipart-post-1.1.1
Successfully installed faraday-0.6.1
Successfully installed multi_json-1.0.2
Successfully installed oauth2-0.4.1
Successfully installed bitly-0.6.1
8 gems installed

Sunday, April 10, 2011

Disable Skype start automatically

This has been covered recently in this forum. Go to the Mac's System Preferences. Open the Accounts preference pane. Select your account, then click on Login Items. Scroll down until you see Skype. Highlight it. Next, click on the 'minus' symbol at the bottom of that window to remove it from your startup items. Next time you fire up the computer, Skype will not auto-start.


Monday, April 4, 2011

Check MX record for domain hosted on Slicehost

dig mx

Wednesday, March 30, 2011

Remove files untracked by Git

git clean -fd

Sunday, March 6, 2011

Delegate getting name attribute of associations

# Instead of 

def guest_name

# Use delegate

delegate :name, :to => :guest, :allow_nil => true

Wednesday, February 23, 2011

Clicking on divs using webrat

Modern apps uses javascript to trigger events such as ajax action on clicking divs.

x = find(:xpath, "//div[text() = 'TEXT IN DIV']")

Tuesday, February 22, 2011

Wednesday, February 2, 2011

APN for Hong Kong 3 mobile network

username: blank
password: blank

Sunday, January 23, 2011

Show diff in git stash

git stash show -u

Wednesday, January 19, 2011

Hard refresh for browsers on Mac OSX

Refresh - Command + R
Hard refresh - Command + Shift + R

Monday, January 17, 2011

Multiple domains with Nginx

Easy peasy

http {
           server {
                         listen 80;
                         location / {
                                      index index.html;

                                      root /var/www/domain1;
                         }           }
           server {
                         listen 80;
                         location / {
                                      index index.html;
                                      root /var/www/domain2;

Friday, January 14, 2011

Sort lines in Vim

:{range}sort u
:{range}sort! u

Thursday, January 13, 2011

Setup Google apps (gmail) for .SG domain registered with Webvisions and hosted on Slicehost

1. Go to and click "Modify Name Server" link

2. Removed webvisions name servers and add in your Slicehost name servers


3. Add MX record on Slicehost


4. Add slice IP address as A record on Slicehost

5. Add CNAME record given by Google App on Slicehost to verify domain ownership

Wednesday, January 12, 2011

Difference between includes and joins in rails

Jason please repeat after me ten times.

includes does "LEFT OUTER JOIN" while joins does "INNER JOIN"

Tuesday, January 11, 2011

Rails arel/activerelation subquery gotcha

subsql = s.where(s[:name].matches("%#{site}%")).project(s[:id])


=> "SELECT \"tickets\".* FROM \"tickets\" WHERE (\"tickets\".\"type\" = 'Incident') AND (\"tickets\".\"supportable_type\" = 'Site' AND \"tickets\".\"supportable_id\" IN (SELECT id FROM \"sites\" WHERE (\"sites\".\"name\" ILIKE '%Site A%')))"

Monday, January 10, 2011

Overide default scope in Rails

# Our default scope in question
class Product < ActiveRecord::Base
  default_scope order('created_at desc')

# This won't work
Product.order('created_at asc').all

# Method 1: unscoping
Product.unscoped.order('created_at asc').all

# Method 2: with_exclusive_scope
Product.with_exclusive_scope{ Product.order('created_at asc').all }


Sunday, January 9, 2011

Setting up node.js and npm on Mac OSX

# Install node.js via Homebrew
brew install node

# Install package manager for node.js
brew install npm

# Example: install express framework for node.js
npm install express

# Specify paths in bash
export NODE_PATH="/usr/local/lib/node"
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/local/share/npm/bin:$PATH"


Sunday, January 2, 2011

Cucumber: Running a single feature / scenario

cucumber path/to/file.feature --line 33
rake features FEATURE=path/to/file.feature CUCUMBER_OPTS="--line 33"
or in vim
:! cucumber %:33

Blog Archive