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