I hereby claim:
- I am fledman on github.
- I am fledman (https://keybase.io/fledman) on keybase.
- I have a public key whose fingerprint is A35B DDE8 C870 DB7B D663 242B 3FCB 4801 83BE B6F0
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
=begin | |
Extends Mocha to support dynamic return values. | |
Now you can set the return value of your stub or | |
expectation to a proc; the proc is evaluated each | |
time the method is called. For example, you can | |
now do Foo.stubs(:when).returns(->{Time.now}) and | |
each call to Foo.when will return the current time. | |
Note that this behaviour is only available while inside | |
of a block passed to Mocha.with_callable_returns. |
=begin | |
block-form stubbing for Mocha; stubs get cleaned up after the block | |
each argument to #with_stubs should be an array of the form | |
[object to stub on, method symbol, value to return] | |
the stub object can be an instance, a class, or Klass.any_instance | |
e.g. stub1 = [Foo.any_instance, :bar, bar = mock()] | |
stub2 = [bar, :count, 5] | |
with_stubs(stub1,stub2) { assert_equal Customer.foo.bar.count, 5 } | |
=end |
# Project Euler: Problem 24 | |
# Lexicographic permutations | |
# https://projecteuler.net/problem=24 | |
def fact(x); (1..x).reduce(1,:*); end | |
l=(0..9).to_a | |
out = [] | |
marker = 1_000_000 | |
while !l.empty? do |
class DotMath | |
NUMBERS = { | |
zero: 0, one: 1, two: 2, three: 3, four: 4, five: 5, | |
six: 6, seven: 7, eight: 8, nine: 9, ten: 10 | |
}.freeze | |
OPERATORS = { | |
plus: [:+,1], minus: [:-,1], times: [:*,1], divide: [:/,1], | |
negate: [:-@,0], abs: [:abs,0], pow: [:**, 1], mod: [:%, 1] | |
}.freeze |
require 'forwardable' | |
module ADT | |
class HashCache | |
extend Forwardable | |
include Enumerable | |
attr_reader :max_size, :default_value, :store_default | |
def initialize(max_size, default: nil, store_default: true) |
source /usr/local/share/chruby/chruby.sh | |
source /usr/local/share/gem_home/gem_home.sh | |
unset RUBY_SWITCH_DEFAULT | |
unset RUBY_SWITCH_CURRENT | |
unset RUBY_SWITCH_GEMHOME | |
RUBY_SWITCH_DEFAULT=$(cat ~/.ruby-switch-default) | |
if [[ -z "$RUBY_SWITCH_DEFAULT" ]]; then |