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;
                         server_name domain1.com;
                         location / {
                                      index index.html;

                                      root /var/www/domain1;
                         }           }
           server {
                         listen 80;
                         server_name domain2.com;
                         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 http://register.webvisions.com/ and click "Modify Name Server" link

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

NS1.SLICEHOST.NET
NS2.SLICEHOST.NET

3. Add MX record on Slicehost

ASPMX.L.GOOGLE.COM.

4. Add slice IP address as A record on Slicehost

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

http://www.google.com/support/a/bin/answer.py?hl=en&answer=47283

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])

Incident.where(i[:supportable_type].eq('Site').and(i[:supportable_id].in([subsql]))).to_sql

=> "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')
end

# 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 }

references: http://ryandaigle.com/articles/2008/11/18/what-s-new-in-edge-rails-default-scoping

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"


reference: http://shapeshed.com/journal/setting-up-nodejs-and-npm-on-mac-osx/

Sunday, January 2, 2011

Cucumber: Running a single feature / scenario


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