Skip to content

Instantly share code, notes, and snippets.

require 'yaml'
ads = YAML.load_file 'config/page_ads.yml'
class PageAds
attr :anchors
attr :positions
class Anchor
# From Rails 3 ActiveSupport I believe
class StringInquirer < String
def method_missing(method_name, *arguments)
if method_name.to_s[-1,1] == "?"
self == method_name.to_s[0..-2]
else
super
end
end
end
require 'yaml'
# From Rails 3 ActiveSupport I believe
class StringInquirer < String
def method_missing(method_name, *arguments)
if method_name.to_s[-1,1] == "?"
self == method_name.to_s[0..-2]
else
super
end
end
class YohDawgDecorator
def initialize(subject)
subject.public_methods(false).each do |meth|
meth_name = "yoh_dog" + meth
(class << self; self; end).class_eval do
define_method meth_name do |*args|
subject.send meth, *args
end
end
end
#!/usr/bin/ruby -w
require 'benchmark'
require 'set'
array = (1..1_000_000).to_a
hash = {}
array.map {|x| hash[x] = nil}
a_set = array.to_set
Benchmark.bm(15) do |x|
@wesmaldonado
wesmaldonado / node_runner.rb
Created June 6, 2010 17:13
Lazy lazy way to restart a node.js application during development.
##
# Be lazy and restart your node.js app when you change things.
# Screenshot: http://img.skitch.com/20100606-mbi52g6knk3n83b6m3eqxr4pa4.png
# INSTALL:
# $ gem install watchr
# $ wget http://gist.github.com/raw/427720/2aae1f3b43a256f5ca07a603025d455aa92560e1/node_run
# $ cd YOUR_NODE_APP
# $ watchr node_runner.rb
#
# NOTES:
asdf
asdf
asdf
asdf
asdf
# Shows the difference in doing crazy stuff like extending an instance on a say... busy loop or lots of requests.
#
# [16:38][wmaldonado@wmaldonado0:]$ ruby test.local.extend.rb
# user system total real
# extend instance 23.150000 0.430000 23.580000 ( 23.777088)
# create a class 2.390000 0.810000 3.200000 ( 3.209350)
#
require 'benchmark'
67 before_filter :ping
68 before_filter :reset_current_request
69 before_filter :initialize_current_page
70 before_filter :rpc_tracking_prefix
71 before_filter :update_content_cache
72 before_filter :update_config
73 before_filter :initialize_site
74 before_filter :initialize_ad_system
75 before_filter :update_content_cache
76 before_filter :initialize_rpc