Skip to content

Instantly share code, notes, and snippets.

View supaspoida's full-sized avatar

Lar Van Der Jagt supaspoida

View GitHub Profile
@supaspoida
supaspoida / gist:1270387
Created October 7, 2011 14:29
guard cucumber fails on second run
Run Cucumber features features/admin_deletes_an_event.feature features/admin_deletes_an_event.feature:7
ERROR: Guard::Cucumber failed to achieve its <run_on_change>, exception was:
Errno::ENOENT: No such file or directory - features/admin_deletes_an_event.feature:7
/Users/dev/.Guardfile:92:in `read'
/Users/dev/.Guardfile:92:in `block in cucumber_command'
/Users/dev/.Guardfile:91:in `each'
/Users/dev/.Guardfile:91:in `any?'
/Users/dev/.Guardfile:91:in `cucumber_command'
/Users/dev/.rvm/gems/ruby-1.9.2-p136@hr_2011/gems/guard-cucumber-0.7.2/lib/guard/cucumber/runner.rb:24:in `run'
/Users/dev/.rvm/gems/ruby-1.9.2-p136@hr_2011/gems/guard-cucumber-0.7.2/lib/guard/cucumber.rb:85:in `run_on_change'
RSpec::Matchers.define :have_country do |expected|
match do |actual|
# usage:
# field_labeled('Select your address').should have_option("Home Address")
RSpec::Matchers.define :have_option do |expected|
def options_for(select_field)
select_field.all('option').map &:text
end
match do |select_field|
@supaspoida
supaspoida / candidate_spec.rb
Created October 11, 2011 13:41 — forked from knwang/candidate_spec.rb
Proofing_oven: Candidate Spec with search
require 'spec_helper'
describe Candidate do
subject { Fabricate(:candidate, first_name: "Joe", last_name: "Doe") }
describe "#full_name" do
its(:full_name) { should == "Joe Doe" }
end
describe "#search" do
require 'ostruct'
module ApplicationHelper
def pluralize(*args, &blk)
result = super
if block_given?
count, *text = result.split
yield OpenStruct.new(text: text.join(' '), count: count)
nil
else
@supaspoida
supaspoida / vimtips.md
Created December 15, 2011 00:31
Vim Tips

Vim has a special register for the system pasteboard.

Access it via: "*

Paste: "*p

Copy line: "*Y

@supaspoida
supaspoida / donors_choose_spec.rb
Created February 14, 2012 20:46
How I'd express the donors choose spec
describe DonorsChoose do
describe "requesting data" do
let(:test_title) { "A test project" }
def mock_request(args)
request = double(:fetch => %Q/{"proposals": [{"title": "#{test_title}"}]}/)
DonorsChoose::Request.should_receive(:new).with(args).and_return(request)
end
context "via lat & lng" do
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5
bind r source-file ~/.tmux.conf
@supaspoida
supaspoida / view_models.rb
Created October 15, 2012 18:47
Trivial example of a view model using dependency injection to access view context
class Controller
expose(:person) { PersonView.new(Person.first, self) }
end
class Decorator
attr_reader :controller, :object
def initializer(object, controller)
@object, @controller = object, controller
end
mod3 = ->(i) { (i % 3).zero? }
mod5 = ->(i) { (i % 5).zero? }
both = ->(i) { mod3[i] && mod5[i] }
rules = {
'FizzBuzz' => ->(i) { both[i] },
'Fizz' => ->(i) { mod3[i] },
'Buzz' => ->(i) { mod5[i] }
}
@supaspoida
supaspoida / hanoi.rb
Created February 2, 2013 02:58
brute force towers of hanoi
towers = [[nil,4,3,2,1],[nil],[nil]]
valid = [[nil],[nil],[nil,4,3,2,1]]
moves = []
record = ->(disc, from, to) {
names = { 0 => 'left ', 1 => 'center', 2 => 'right ' }
moves << "disc %s: %s -> %s" % [disc, names[from], names[to]]
}