View number_scan.rb
require 'benchmark'
puts RUBY_VERSION
phones = ["(216) 375-9240","(518) 462-8200","(215) 434-2915","(714) 778-4011",
"(512) 474-7773","(805) 395-1301","(301) 659-5500","(504) 346-5900","(617) 275-4600",
"(313) 643-9080", "(203) 579-1525", "(716) 854-9100", "(609) 541-5028", "(704) 372-4900",
"(312) 853-3920", "(213) 637-8883", "(216) 696-5422", "(614) 224-3735", "(214) 742-5114",
"(513) 228-8015", "(213) 956-1391", "(919) 373-8633", "(717) 233-9031", "(203) 525-0155",
"(317) 635-0119", "(213) 645-9011", "(201) 333-0250", "(816) 474-1850", "(702) 387-7000",
View gist:02c0aba02df6216fab38
::ActionView::Helpers::NumberHelper.instance_method(:number_with_precision).bind(Module.new{ extend ActionView::Helpers::NumberHelper }).call("1234.0", :strip_insignificant_zeros => true)
View sums_100.rb
def sum_digits_to(n)
enumerator = Enumerator.new do |yielder|
# recursive proc (backtracking) which iterates over all possible
# combinations of digits and operators.
p = -> prev_lhs = "", digit = 1 do
lhs = "#{ prev_lhs }#{ digit }"
if digit == 9
yielder << lhs if eval(lhs) == n
else
[" + ", " - ", nil].each do |op|
View gist:1499154
class Foo
has_many :bars
def to_json
bars_json = bars.map(&:to_json).join(",")
%Q({"foo": {...{"bars": [#{bars_json}] } } })
end
end
class Bar
View gist:1012107
class Avatar < ActiveRecord::Base
attr_accessor :content_type, :original_filename, :image_data
before_save :decode_base64_image
has_attached_file :image,
PAPERCLIP_CONFIG.merge(
:styles => {
:thumb => '32x32#',
:medium => '64x64#',