Skip to content

Instantly share code, notes, and snippets.

View hashrocketeer's full-sized avatar

Hashrocket Employees hashrocketeer

View GitHub Profile
module TabularSupport
def hashes_from_table
actual = find("table")
headers = actual.all("th").map(&:text)
actual.all("tbody tr").map do |row|
Hash[headers.zip row.all("td").map(&:text).compact.map(&:strip)]
end
end
end
@hashrocketeer
hashrocketeer / hdb.rake
Created February 12, 2013 17:48
Clone task for heroku databases
# tasks for working with your heroku database
#
# Examples:
#
# Replace development DB with a fresh capture from Heroku
# (removing the oldest one first)
#
# rake hdb:clone # replace development database with a fresh capture of the
# heroku database
#
@hashrocketeer
hashrocketeer / backtrace.rb
Created March 4, 2013 19:20
App backtraces, even when testing javascript.
ApplicationController.class_eval do
rescue_from StandardError do |exception|
$stderr.puts ExceptionFormatter.summarize exception
raise
end
end
class ExceptionFormatter
extend Cucumber::Term::ANSIColor
def self.summarize(e)
@hashrocketeer
hashrocketeer / workspace.sh
Created April 26, 2013 21:02
setup dotmatrix and some other goodies
#!/usr/bin/env bash
source ~/.rvm/scripts/rvm
rvm install 1.9.3
rvm use --default 1.9.3
cd $HOME
echo 'colorscheme railscasts' >> $HOME/.vimrc.local
@hashrocketeer
hashrocketeer / auto_loaded_constant.rb
Created May 17, 2013 21:18
autoloading from a trap call raises ThreadError on ruby 2.0
module AutoloadBug
AutoLoadedConstant = 5
end
require 'method_source'
module ChristmasTree
class WrappingPaper
class ExpressionParser
attr_reader :block
ExpressionOptions = Struct.new(:expression, :line_number) do
def range
# $ rails new <rails_app_name> -m base_app.rb -S -T -d postgresql
# Install gems
gem "haml-rails"
gem "decent_exposure"
gem_group :development do
gem "better_errors"
end
// Generated by CoffeeScript 1.6.3
var constraint, material, mesh, wheel_geometry;
material = Physijs.createMaterial(new THREE.MeshLambertMaterial({
map: THREE.ImageUtils.loadTexture('images/checker.gif')
}), .8, .5);
wheel_geometry = new THREE.CylinderGeometry(5, 5, 2, 16);
mesh = new Physijs.CylinderMesh(wheel_geometry, material, 16);
# credit @rwz
When /^I follow "([^"]+"(?: then "[^"]+")*)$/ do |links|
links.chomp(?").split('" then "').each do |link_text|
click_link link_text
end
end
# Example usage:
# When I follow "thing1" then "thing2" then "thing3"
class PathFinder
attr_reader :paths
def initialize(paths)
@paths = paths
end
def find(request_path)
find_path(request_path) or fail ActiveRecord::RecordNotFound
end