Skip to content

Instantly share code, notes, and snippets.

include js file: http://connect.facebook.net/en_US/all.js
// load facebook api
$('<div id="fb-root"></div>').appendTo("body");
FB.init({
appId : '168055643260227',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
include js file: http://connect.facebook.net/en_US/all.js
// load facebook api
$('<div id="fb-root"></div>').appendTo("body");
FB.init({
appId : '168055643260227',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
require 'rspec'
# TODO: class vars?
# TODO: better just alias_method_chain method_missing for the duration of running the method
module Tdef
def self.check_args(args, rules)
rules.each_pair do |name, klass|
unless args[name.to_s].kind_of?(klass)
raise "Wrong type: #{name} should be #{klass.to_s}, but is #{args[name].class.to_s}"
end
end
@mrbrdo
mrbrdo / gist:2880210
Created June 6, 2012 06:06
crashes ruby 1.9.3
# run with rspec filename.rb
require 'rspec'
# TODO: class vars?
# TODO: better just alias_method_chain method_missing for the duration of running the method
module Tdef
def self.check_args(args, rules)
rules.each_pair do |name, klass|
unless args[name.to_s].kind_of?(klass)
raise "Wrong type: #{name} should be #{klass.to_s}, but is #{args[name].class.to_s}"
end
@mrbrdo
mrbrdo / gist:3199866
Created July 29, 2012 16:02
mongoid memory leak with threading
require 'rubygems'
require 'mongoid'
class User
include Mongoid::Document
include Mongoid::Timestamps
end
# Connect to MongoDB
Mongoid.identity_map_enabled = false
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 9979 100 9979 0 0 9705 0 0:00:01 0:00:01 --:--:-- 86025
Turning on auto mode.
Downloading RVM from wayneeseguin branch stable
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1047k 100 1047k 0 0 550k 0 0:00:01 0:00:01 --:--:-- 980k
Upgrading the RVM installation in /home/mrbrdo/.rvm/
@mrbrdo
mrbrdo / null_object_chaining.rb
Created September 27, 2012 08:00
chaining methods on nil (null object pattren)
# null object pattern Objective-C style (togglable)
# more elegant: https://gist.github.com/3792804
def null_chain
unless NilClass.instance_variable_defined?(:@null_chain)
NilClass.class_eval do
alias_method :nc_mm_orig, :method_missing
def method_missing(name, *args, &block)
if self.class.null_chain?
@mrbrdo
mrbrdo / null_object.rb
Created September 27, 2012 08:05
chaining methods on nil (null object pattren)
# null object pattern Objective-C style (togglable)
def null_chain
begin
return yield
rescue NoMethodError
end
nil
end
@mrbrdo
mrbrdo / null_object_chaining.rb
Created September 27, 2012 08:36
null object pattern for chaining
class NullChainer < BasicObject
def initialize(obj)
@obj = obj
end
def get
@obj
end
def method_missing(name, *args, &block)