Skip to content

Instantly share code, notes, and snippets.

View Manfred's full-sized avatar

Manfred Stienstra Manfred

  • Fingertips
  • H4sIAFn6cmUAA0WMMQ7CMBAEe14RTJM0prdDEdFAh8ID0Mm5SCcs25wvIIH4O06QoNhmd3YYbxMxKnBCMVxcDMLRe+QtA3khVNZ5yLna739T2y3wvzCmOx3tgGPlLGMYkOvkgYKp1IFUY0u1BHZfV9f2RZ7LLSVPDmabzejHmdIUSAg8PXFtQXOcBLMeGB4vjlFqiUXrNk41b9uDuxpzRr4j6yzAUkNKBprVB8hGiinYAAAA
View GitHub Profile

Keybase proof

I hereby claim:

  • I am manfred on github.
  • I am manfred (https://keybase.io/manfred) on keybase.
  • I have a public key ASDppOBDpAM6DvUVkd8Cs8kWFV9Ov-K6F8vrhC2QxbvnFAo

To claim this, I am signing this object:

@Manfred
Manfred / 1.png
Last active December 27, 2016 12:01
1.png
@Manfred
Manfred / w.rb
Last active September 23, 2016 19:13
An often used memoization idiom causes problems in Ruby.
# 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 August 29, 2015 14:18
Running Rake tasks from your test environment

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.

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 March 5, 2012 16:10
The tiniestestest test framework
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 April 26, 2011 12:31 — forked from alloy/gist:942157
Square job interview exercise
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