This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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#', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo | |
has_many :bars | |
def to_json | |
bars_json = bars.map(&:to_json).join(",") | |
%Q({"foo": {...{"bars": [#{bars_json}] } } }) | |
end | |
end | |
class Bar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
::ActionView::Helpers::NumberHelper.instance_method(:number_with_precision).bind(Module.new{ extend ActionView::Helpers::NumberHelper }).call("1234.0", :strip_insignificant_zeros => true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
$(ruby -e 'puts File.expand_path("../../share/git-core/contrib/diff-highlight/diff-highlight", File.realpath(`/usr/bin/which git`.strip))') "$@" |