Skip to content

Instantly share code, notes, and snippets.

module ScoreHelpers
def the_letter(letter, options)
score = options[:is_worth]
# TODO Remember the letter's score for the current example group.
end
end
module ScoreMatchers
extend RSpec::Matchers::DSL
module ScoreHelpers
def self.extended(base)
base.class_eval do
let(:scores) { {} }
end
end
def the_letter(letter, options)
score = options[:is_worth]
@tomstuart
tomstuart / gist:4382332089a8402bf475
Created April 30, 2014 12:59
Person#age gives the wrong answer for a person who hasn’t had their birthday yet this year
require 'active_support/time'
require 'active_support/testing/time_helpers'
require 'rspec/expectations'
include ActiveSupport::Testing::TimeHelpers
include RSpec::Matchers
class Person < Struct.new(:birthday)
def age
Date.today.year - birthday.year
end
@tomstuart
tomstuart / gist:8a4ec2a53b12fa122a49
Created June 25, 2014 15:02
Setting up boot2docker for use with fig
$ mkdir ~/.boot2docker
$ curl http://static.dockerfiles.io/boot2docker-v1.0.0-virtualbox-guest-additions-v4.3.12.iso > ~/.boot2docker/boot2docker.iso
$ boot2docker init
$ VBoxManage sharedfolder add boot2docker-vm -name home -hostpath /Users
$ boot2docker up
$ sudo sh -c "echo `boot2docker ip 2>/dev/null` boot2docker >> /etc/hosts"
$ echo export DOCKER_HOST=tcp://$(boot2docker ip 2>/dev/null):2375 >> .bash_profile
require 'rspec/core'
examples = RSpec.describe 'a "Hello world" object' do
before(:each) do
@hello_world = HelloWorld.new
end
it 'says "Hello world"' do
raise unless @hello_world.message == 'Hello world'
end
$ cat Gemfile
source 'https://rubygems.org/'
$ time ruby -e 'puts "Hello world"'
Hello world
real 0m0.197s
user 0m0.117s
sys 0m0.073s
@tomstuart
tomstuart / rules.json
Last active August 29, 2015 14:04
Rules for auto-explaining FreeAgent transactions
[
{
"textToMatch": "HISCOX",
"description": "Liability & indemnity insurance",
"vat": "0",
"category": "Insurance",
"shouldHaveAttachment": false,
"ecStatus": "Non-EC"
},
{
@tomstuart
tomstuart / bwt.rb
Created August 9, 2014 10:09
An implementation of the Burrows–Wheeler transform that satisfies https://github.com/zetter/burrows-wheeler-transform
class BWT
def encode(string)
chars = string.chars + ['$']
chars.each_index.map(&chars.method(:rotate)).sort.map(&:last).join
end
def decode(string)
chars = string.chars
chars.inject([]) { |table| chars.zip(table).sort }.
map(&:join).detect { |s| s.end_with?('$') }.chop
before function call: at start of function call:
ARG: args for caller args for caller
saved state for caller saved state for caller
LCL: locals for caller locals for caller
stack for caller stack for caller
args for callee --> ARG: args for callee
SP: saved state for callee
LCL: locals for callee
SP:
#http://www.nhs.uk/NHSEngland/Healthcosts/Pages/Prescriptioncosts.aspx
Given a user who is 60 or older
When they collect a prescription
Then it should be free
Given a user who is younger than 16
When they collect a prescription
Then it should be free