Skip to content

Instantly share code, notes, and snippets.

View liangzan's full-sized avatar

Wong Liang Zan liangzan

View GitHub Profile
@liangzan
liangzan / gist:2390523
Created April 15, 2012 06:43
npm install command
npm install notifymode-client socket.io
@liangzan
liangzan / gist:2390665
Created April 15, 2012 07:09
registering an app through command line
notifymode register
require 'securerandom'
class User < ActiveRecord::Base
has_many :inquiries
has_many :host_inquiries, :class_name => 'Inquiry', :foreign_key => 'host_id'
validates_presence_of :password
before_save :create_new_password
after_save :certify_if_needed
INQUIRY_LIMIT = 3
@liangzan
liangzan / violate_each.rb
Created May 13, 2011 03:13
violating the each block
foo.items.each do |i|
i.do_whatever
break; # he really placed a semi colon
end
@liangzan
liangzan / .gitconfig
Created April 27, 2011 04:44
git configuration
[giggle]
compact-mode = false
main-window-geometry = 700x562+8+50
[user]
name = Wong Liang Zan
email = zan@liangzan.net
[color]
ui = auto
[color "branch"]
current = yellow reverse
@liangzan
liangzan / remove_magic_comment.diff
Created April 21, 2011 03:26
removes the magic comment for ruby mode
diff --git a/ruby-mode/ruby-mode.el b/ruby-mode/ruby-mode.el
index 94cb9ab..d810146 100644
--- a/ruby-mode/ruby-mode.el
+++ b/ruby-mode/ruby-mode.el
@@ -350,7 +350,7 @@ Also ignores spaces after parenthesis when 'space."
((forward-char)))))
(insert coding-system)))
((looking-at "\\s *#.*coding\\s *[:=]"))
- (t (insert "# -*- coding: " coding-system " -*-\n"))
+ (t (insert ""))
@liangzan
liangzan / gist:833370
Created February 18, 2011 07:15
sync.js profile
Statistical profiling result from profile-12980120047188966.log, (1058 ticks, 3 unaccounted, 0 excluded).
[Unknown]:
ticks total nonlib name
3 0.3%
[Shared libraries]:
ticks total nonlib name
59 5.6% 0.0% 00ada000-00adb000
# lib/searchlogic/named_scopes/conditions.rb
def create_primary_condition(column, condition)
...
named_scope("#{column}_#{condition}".to_sym, scope_options)
end
# lib/searchlogic/named_scopes/conditions.rb
def method_missing(name, *args, &block)
if details = condition_details(name)
create_condition(details[:column], details[:condition], args)
send(name, *args)
elsif boolean_condition?(name)
column = name.to_s.gsub(/^not_/, "")
named_scope name, :conditions => {column => (name.to_s =~ /^not_/).nil?}
send(name)
else
# lib/searchlogic/named_scopes/conditions.rb
def method_missing(name, *args, &block)
...
send(name, *args)
...
end