Skip to content

Instantly share code, notes, and snippets.

puyo / capybara_find_with_info.rb
Created Jan 31, 2014
More useful output from Capybara
View capybara_find_with_info.rb
# More useful output from Capybara.
# Before:
# Unable to find link or button "Year 5"
# After:
# Unable to find link or button "Year 5" in "Sorry, something went wrong We've
# been notified of the error and are looking into it."
View encamel.rb
#!/usr/bin/env ruby
gem 'activesupport'
require 'active_support/core_ext/string/inflections'
snake = ARGV.first
camel = snake.camelize(:lower)
system %{git grep -l #{snake} | xargs ruby -p -i -e '$_.gsub! /#{snake}/, "#{camel}"'}
puyo / alp_facebook_popularity.rb
Last active Aug 29, 2015
Run a Facebook based popularity competition for ALP MPs
View alp_facebook_popularity.rb
gem 'activesupport' # {}.to_query
gem 'nokogiri'
gem 'typhoeus'
require 'active_support/core_ext/object'
require 'json'
require 'nokogiri'
require 'pp'
require 'typhoeus'
View grapple.rb
require 'rubygems' rescue nil
require 'gosu'
require 'chipmunk'
class Array
# e.g. [1,2,3].each_link yields [1,2], [2,3]
def each_link
prev = first
self[1, size].each do |item|
yield prev, item
View hashblock.rb
# What is it with you people and your singletons?
class Hash
def self.from_block(&block)
class BlockBuilder
attr_reader :collected
View array_to_hash.rb
# Is there a preferred way to do it? A lot of people I see use inject, but it makes my eyes bleed.
x = [[1, 2], [3, 4]]
p x.inject({}) { |h, r| h[r[0]] = r[1]; h }
# {1=>2, 3=>4}
p Hash[*x.flatten]
# {1=>2, 3=>4}
View rsync_spec.rb
describe 'rsync' do
it 'should keep the latest version of a file' do
system("mkdir -p d1 d2")
system("echo 'This is the first version' > d1/file.txt")
sleep 1 # ensure timestamps are different
system("echo 'This is the second version' > d2/file.txt")
system("rsync -ru d2/ dest/")
system("rsync -ru d1/ dest/")'dest/file.txt').should include('second version')
puyo / mypresentation.haml
Created Nov 19, 2010
Putting all your slick in one place...?
View mypresentation.haml
%h1 Hi there world
%p Yes this is a slide
%p.step with a step
// stuff for the first slide
puyo / order_spec.rb
Created Aug 26, 2011
Is it possible to rspec this properly without hitting the database?
View order_spec.rb
create_table "line_items", :force => true do |t|
t.integer "cost"
t.boolean "paid"
t.integer "order_id"
create_table "orders", :force => true do |t|
# -----
puyo / Gemfile
Created Sep 6, 2011
Rails 3.1 + Sprockets + Compass
View Gemfile
gem 'haml-rails', '~> 0.3'
gem 'rails', '~> 3.1'
group :assets do
gem 'compass', '~> 0.11'
gem 'sass-rails', '~> 3.1'
gem 'coffee-rails', '~> 3.1'
gem 'uglifier', '~> 1.0'