Skip to content

Instantly share code, notes, and snippets.

Avatar

Manfred Stienstra Manfred

  • Fingertips
  • H4sIAKEt7lwAA0WNsQ7CMAxEd76ilKGwhD1ph9KFGT4AmdRIFlYc7AACxL+jwsBwy+neO8XLlRQbBWJbA3MTIoNZNQySigozatvHQpL+hfcbMAwjnqoYDPnkFC1LMjwcZXx09ZbqgGn8BrqfsG9304f3fc5MESblF55WjhIVAqYnzgM4lWtBc6PC/aUipSrim7iIzTvsIJ6936PeUJ0V0LKEnD2sZh8/BJuuywAAAA==
View GitHub Profile
@Manfred
Manfred / w.rb
Last active Sep 23, 2016
An often used memoization idiom causes problems in Ruby.
View w.rb
# Run this example with $ ruby -W w.rb
class Gallery
attr_reader :disabled
def initialize(disabled:)
@disabled = disabled
end
def images
@Manfred
Manfred / 0_README.md
Last active Aug 29, 2015
Running Rake tasks from your test environment
View 0_README.md

Running Rake tasks from a spec

This will try to find all the rake tasks defined in the lib/tasks directory and run them. Note that some tasks might need arguments and will fail. I want to keep this example short so dealing with that is left as an exercise for the intern.

View random_sales_force_account_id.rb
def random_sales_force_account_id
'%d%d%d%d-%d%d%d%d%d-%d%d%d%d' % ([9]*13).map { |i| rand(i) }
end
@Manfred
Manfred / assert.rb
Created Mar 5, 2012
The tiniestestest test framework
View assert.rb
def assert(expectation, message=nil)
if expectation
$stderr.write('.')
else
message ||= "assertion failed"
puts "FAILURE: #{caller(0)[1]}"
puts " #{message}"
exit -1
end
end
@Manfred
Manfred / gist:942173
Created Apr 26, 2011 — forked from alloy/gist:942157
Square job interview exercise
View gist:942173
class Payment < Struct.new(:amount)
def self.fees
if @fees.nil?
@fees = {}; ObjectSpace.each_object do |object|
if object.class == String and match = /returns.*of\s\$(\d+).*\(\$([\d\.]+)\)/.match(object.to_s)
@fees[match[1].to_i] = match[2].to_f
end
end
end; @fees
end