Skip to content

Instantly share code, notes, and snippets.

$ cat Gemfile
source 'https://rubygems.org/'
$ time ruby -e 'puts "Hello world"'
Hello world
real 0m0.197s
user 0m0.117s
sys 0m0.073s
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
@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
@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
module ScoreHelpers
def self.extended(base)
base.class_eval do
let(:scores) { {} }
end
end
def the_letter(letter, options)
score = options[:is_worth]
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
@tomstuart
tomstuart / figtest.md
Last active January 2, 2016 01:28
Running a basic Ruby app with Fig on OS X

You must already have pip (brew install python), Vagrant (from the OS X installer, not the gem) and VirtualBox installed.

First, install Docker:

$ curl https://raw.github.com/noplay/docker-osx/master/docker > /usr/local/bin/docker
$ chmod +x /usr/local/bin/docker
$ docker version
@tomstuart
tomstuart / gist:6782733
Created October 1, 2013 18:18
Downloading and scraping an HTML table
require 'uri'
require 'net/http'
require 'nokogiri'
uri = URI.parse('http://en.wikipedia.org/wiki/Doctor_Who')
html = Net::HTTP.get(uri)
document = Nokogiri::HTML.parse(html)
tables = document.css('table.wikitable')
table = tables.first
#<struct TMConfiguration state=:delete_next_bit, tape=#<Tape (1)1111>>
#<struct TMConfiguration state=:increment_counter, tape=#<Tape (_)X1111>>
#<struct TMConfiguration state=:delete_next_bit, tape=#<Tape 1(X)1111>>
#<struct TMConfiguration state=:delete_next_bit, tape=#<Tape 1X(1)111>>
#<struct TMConfiguration state=:increment_counter, tape=#<Tape 1(X)X111>>
#<struct TMConfiguration state=:increment_counter, tape=#<Tape (1)XX111>>
#<struct TMConfiguration state=:increment_counter, tape=#<Tape (_)ZXX111>>
#<struct TMConfiguration state=:delete_next_bit, tape=#<Tape 1(Z)XX111>>
#<struct TMConfiguration state=:delete_next_bit, tape=#<Tape 1Z(X)X111>>
#<struct TMConfiguration state=:delete_next_bit, tape=#<Tape 1ZX(X)111>>
#<struct TMConfiguration state=:delete_next_bit, tape=#<Tape (1)1010>>
#<struct TMConfiguration state=:increment_counter, tape=#<Tape (_)X1010>>
#<struct TMConfiguration state=:delete_next_bit, tape=#<Tape 1(X)1010>>
#<struct TMConfiguration state=:delete_next_bit, tape=#<Tape 1X(1)010>>
#<struct TMConfiguration state=:increment_counter, tape=#<Tape 1(X)X010>>
#<struct TMConfiguration state=:increment_counter, tape=#<Tape (1)XX010>>
#<struct TMConfiguration state=:increment_counter, tape=#<Tape (_)ZXX010>>
#<struct TMConfiguration state=:delete_next_bit, tape=#<Tape 1(Z)XX010>>
#<struct TMConfiguration state=:delete_next_bit, tape=#<Tape 1Z(X)X010>>
#<struct TMConfiguration state=:delete_next_bit, tape=#<Tape 1ZX(X)010>>