Skip to content

Instantly share code, notes, and snippets.

View kwstannard's full-sized avatar

Wolf kwstannard

  • Andros
  • New York City
View GitHub Profile
if [ -f "$rvm_path/scripts/rvm" ]; then
source "$rvm_path/scripts/rvm"
if [ -f ".rvmrc" ]; then
source ".rvmrc"
else
if [ -f ".ruby-version" ]; then
if [ -f ".ruby-gemset" ]; then
rvm use `cat .ruby-version`@`cat .ruby-gemset`
else
rvm use `cat .ruby-version`
#! /usr/bin/ruby
branch_match = `git branch`.match(/FY-#{ARGV[0]}\w+/)
branch = branch_match ? branch_match[0].to_s : ARGV[0]
`git checkout #{branch}`
package funsets
import common._
/**
* 2. Purely Functional Sets.
*/
object FunSets {
/**
* We represent a set by its characteristic function, i.e.
class OnCodeCaller
def self.call(code, needer)
if needer.respond_to?("on_#{code}")
needer.send("on_#{code}")
elsif needer.respond_to?("on_#{code / 100}XX")
needer.send("on_#{code / 100}XX")
else
needer.on_failure
end
end
describe 'ordering' do
let(:herp) { raise 'hi' }
subject { raise 'bye' }
it { should eq(herp) } #=> error 'hi'
it { is_expected.to eq(herp) } #=> error 'bye'
end
class RubyVersion
def self.current
factory.current
end
def self.factory
if version_file_exists?
Files.new
elsif rvm_present?
RVM.new
@kwstannard
kwstannard / .pryrc
Created August 13, 2014 20:33
automatically add lib dir to ruby load path
file=Pathname.new(Dir.pwd+'/lib')
if(file.exist?)
$:.unshift(file.to_s)
end
@kwstannard
kwstannard / foo.rb
Created August 18, 2014 22:02
squiggly all your versions
gemfile=File.read("Gemfile")
unversioned = gemfile.scan(/(?<!#)\s+(gem|custom_require) ['"]([\w-]+)['"](?!,.*(\d+\.\d+\.\d+))/)
lockfile = File.read("Gemfile.lock")
puts unversioned.inspect
unversioned.each do |lead, name|
version = lockfile.scan(/#{name} \(((\d+\.?)+)\)/).first.first
gemfile.gsub! /#{lead} ['"]#{name}['"]/, "\\0, '~> #{version}'"
@kwstannard
kwstannard / module_spec.rb
Created September 15, 2014 17:31
Module Testing without coupling
RSpec.describe YourModule do
let(:includer) { Class.new.include(described_class).new }
describe "#hello_world" do
it "returns Hello World" do
expect(includer.hello_world).
to eq("Hello World")
end
end
end
@kwstannard
kwstannard / factories.rb
Created September 15, 2014 17:33
Drying Factories
require 'spec_helper'
RSpec.describe YourRecord do
subject(:record) { create :your_record, *traits }
let(:traits) { [] }
its(:name) { is_expected.to be_nil }
its(:size) { is_expected.to eq(0) }
context "when name is bob" do