curl -i 127.0.0.1:3003/hotels?token=SECRET_TOKEN
Thursday, December 22, 2011
Monday, October 24, 2011
Friday, October 21, 2011
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.
That solved it. Apparently that hidden folder caches files for easy undelete within 3 days.
reference: http://forums.dropbox.com/topic.php?id=31679
rm -rf ~/Dropbox/.dropbox.cache/*
That solved it. Apparently that hidden folder caches files for easy undelete within 3 days.
reference: http://forums.dropbox.com/topic.php?id=31679
Friday, September 9, 2011
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
fi
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.
Hmm. What bugs is he trying to fix? How would I know if it's really fixed? What if he wrote instead
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.
Great, now the only thing left to the piece of the puzzle is WHO determined that those were bugs?
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,
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.
# 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.
# Format: [REFERENCE] HOW to DO WHAT
[#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:
activerecord.errors.models.admin.attributes.title.blank
activerecord.errors.models.admin.blank
activerecord.errors.models.user.attributes.title.blank
activerecord.errors.models.user.blank
activerecord.errors.messages.blank
errors.attributes.title.blank
errors.messages.blank
So example for validation for email format
reference: http://guides.rubyonrails.org/i18n.html
activerecord.errors.models.admin.attributes.title.blank
activerecord.errors.models.admin.blank
activerecord.errors.models.user.attributes.title.blank
activerecord.errors.models.user.blank
activerecord.errors.messages.blank
errors.attributes.title.blank
errors.messages.blank
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
en:
activerecord:
errors:
models:
membership_request:
attributes:
email:
invalid: "is not a valid email address"
reference: http://guides.rubyonrails.org/i18n.html
Thursday, May 19, 2011
Bit.ly API
Latest stable - v3.0
Rate limit - 5 concurrent users / IP address
http://code.google.com/p/bitly-api/wiki/ApiBestPractices
http://code.google.com/p/bitly-api/
http://code.google.com/p/bitly-api/wiki/ApiDocumentation
gem - https://github.com/philnash/bitly
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
Rate limit - 5 concurrent users / IP address
http://code.google.com/p/bitly-api/wiki/ApiBestPractices
http://code.google.com/p/bitly-api/
http://code.google.com/p/bitly-api/wiki/ApiDocumentation
gem - https://github.com/philnash/bitly
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
Saturday, May 7, 2011
Running single unit test in Rails 3
ruby -Itest test/unit/xxx_test.rb
reference: http://stackoverflow.com/questions/5227081/given-a-typical-rails-3-environment-why-am-i-unable-to-execute-any-tests
reference: http://stackoverflow.com/questions/5227081/given-a-typical-rails-3-environment-why-am-i-unable-to-execute-any-tests
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.
reference: http://forum.skype.com/index.php?showtopic=112545&view=findpost&p=509592&s=95b90ee2e5c9cbdf86801ff004fcfcc5
Monday, April 4, 2011
Wednesday, March 30, 2011
Sunday, March 6, 2011
Delegate getting name attribute of associations
# Instead of
def guest_name
guest.try(:name)
end
# 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']")
x.click()
Tuesday, February 22, 2011
Wednesday, February 2, 2011
Sunday, January 23, 2011
Wednesday, January 19, 2011
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
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
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"
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/
Thursday, January 6, 2011
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
Subscribe to:
Posts (Atom)
Blog Archive
-
▼
2011
(29)
-
►
January
(11)
- Show diff in git stash
- Hard refresh for browsers on Mac OSX
- Multiple domains with Nginx
- Sort lines in Vim
- Setup Google apps (gmail) for .SG domain registere...
- Difference between includes and joins in rails
- Rails arel/activerelation subquery gotcha
- Overide default scope in Rails
- Setting up node.js and npm on Mac OSX
- URL for Google's OpenID
- Cucumber: Running a single feature / scenario
-
►
January
(11)