Skip to content

Instantly share code, notes, and snippets.

View hashrocketeer's full-sized avatar

Hashrocket Employees hashrocketeer

View GitHub Profile
@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 / 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
#
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 / setup.sh
Last active December 11, 2015 10:58
Drop at script/setup to keep everyone up to date, dependency-wise.
#!/bin/bash
DEPS="YES"
check-dependency() {
name=$1
program=${2-"brew list $1"}
if ! eval $program &>/dev/null; then
echo "This app requires $name to run, but it is not installed."
echo " brew install $name"
@hashrocketeer
hashrocketeer / freethousand
Created October 2, 2012 15:23
Free up port 3000
#!/usr/bin/env ruby
pid = `lsof -t -i tcp:3000`.to_i
Process.kill 'INT', pid if pid
(ns hackerfews.core
2 (:require [net.cgrand.enlive-html :as html]))
3
4 (def url (java.net.URI. "http://news.ycombinator.com/"))
5
6 (defn titles
7 [docx] (flatten (map :content (html/select docx [:td.title :a]))))
8
9 (defn numbers-in-nodes
10 [docx selector] (let [x (flatten (map :content (html/select docx selector)))]
@hashrocketeer
hashrocketeer / gist:3209188
Created July 30, 2012 19:01
base64 string to image
# http://stackoverflow.com/questions/1160741/how-to-save-a-base64-string-as-an-image-using-ruby
File.open('shipping_label.gif', 'wb') do|f|
f.write(Base64.decode64(base_64_encoded_data))
end
source 'http://rubygems.org'
gem 'rails', '3.1.1'
platforms :jruby do
gem 'jruby-openssl'
gem 'trinidad'
gem 'activerecord-jdbcpostgresql-adapter'
gem 'activerecord-jdbc-adapter'
gem 'jdbc-postgres', :require => false
NoMethodError: undefined method `read_nonblock' for #<OpenSSL::SSL::SSLSocket:0x44cdf872>
rbuf_fill at /Users/dev/.rvm/rubies/jruby-1.6.5/lib/ruby/1.9/net/protocol.rb:135
readuntil at /Users/dev/.rvm/rubies/jruby-1.6.5/lib/ruby/1.9/net/protocol.rb:116
readline at /Users/dev/.rvm/rubies/jruby-1.6.5/lib/ruby/1.9/net/protocol.rb:126
read_status_line at /Users/dev/.rvm/rubies/jruby-1.6.5/lib/ruby/1.9/net/http.rb:2219
read_new at /Users/dev/.rvm/rubies/jruby-1.6.5/lib/ruby/1.9/net/http.rb:2208
transport_request at /Users/dev/.rvm/rubies/jruby-1.6.5/lib/ruby/1.9/net/http.rb:1191
request at /Users/dev/.rvm/rubies/jruby-1.6.5/lib/ruby/1.9/net/http.rb:1177
request at /Users/dev/.rvm/rubies/jruby-1.6.5/lib/ruby/1.9/net/http.rb:1170
start at /Users/dev/.rvm/rubies/jruby-1.6.5/lib/ruby/1.9/net/http.rb:627
@hashrocketeer
hashrocketeer / candidate_spec.rb
Created October 11, 2011 13:30 — 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