Skip to content

Instantly share code, notes, and snippets.

View tjh's full-sized avatar

Tim Harvey tjh

View GitHub Profile

Motivation

We recently were working on a project where the version of Firefox on the development machines was causing acceptance tests running on Capybara and Selenium to fail and/or hang erroneously. The solution was to point Selenium at a custom version of Firefox. We also added the Firefox binaries to the application git repo so that all devs could run against a known good version of Firefox.

Solution

  1. Download the desired version of Firefox from ftp://ftp.mozilla.org/pub/firefox/releases/

  2. Put Firefox.app in your rails app somewhere like ./bin/spec/macosx/

<% @customers.all.each_with_index do |i, customer| %>
<h1><%= "Customer #{i}: #{customer.name}" %></h1>
<% end %>
customers.collect { |c| c.address.city }.uniq
<% form_for @customer %>
<%= f.label :name %>
<%= f.input :name %>
<% end %>
@tjh
tjh / gist:2794272
Created May 26, 2012 15:11
Add Jekyll redirections to existing posts
#!/usr/bin/ruby
# Loop through the posts and add the redirections YML front-matter
# used by the plugin described here:
#
# http://www.marran.com/tech/creating-redirects-with-jekyll/
#
# This is a total hack job, just enough to get the job done. I'm
# sure there's a better way to do this.
@tjh
tjh / gist:2580411
Created May 2, 2012 20:55
HUMOR: Have some fun with the Rails devs in your life, wreck Float#* and watch tests explode.
echo 'class Float; def *(other); self.to_i * other.to_i; end; end;' >> config/application.rb
@tjh
tjh / README.md
Created February 8, 2012 02:32
Test MicroGem

TestClass

Description and usage:

require 'test_class'
TestClass.new

Running the tests

Install the rspec gem

@tjh
tjh / gist:1725383
Created February 2, 2012 19:52 — forked from netshade/gist:1725305
Track Nginx Proc Count
while :; do (ps -o command -U YOUR_APP_USER | awk "/Rack:/ {print $1 $2}" | wc -l | { read procs; echo "hello version 1.0\nauthenticate YOUR_API_KEY\ngauge nginx.proc.num $procs `date +%s`\n" } ) | nc instrumentalapp.com 8000; sleep 60; done
@tjh
tjh / character_set_and_collation.rb
Created January 31, 2012 16:07
Convert all Rails table column collation and character set
#!/usr/bin/env ruby
# Put this file in the root of your Rails project,
# then run it to output the SQL needed to change all
# your tables and columns to the same character set
# and collation.
#
# > ruby character_set_and_collation.rb
DATABASE = ''
@tjh
tjh / _README.md
Created October 21, 2011 01:30
acts_as_boolean

Acts As Boolean

A quick way to create an attribute on your ActiveRecord models that always responds with a boolean value, similar to the Boolean attributes from a table that have the ? method for syntactic sugar.

class SomeObject < ActiveRecord::Base
  acts_as_boolean :is_active
end

o = SomeObject.new

o.is_active? # => false

@tjh
tjh / gist:1051092
Created June 28, 2011 13:07
Watchr script for Cucumber, Rspec, and Evergreen
require 'growl'
ENV["WATCHR"] = "1"
$spec_cmd = "rspec --colour --format nested -d"
$evergreen_cmd = "evergreen run"
def growl(message)
if message == 'true' || message.match(/\s0\s(errors|failures)/)
title = 'Watchr: All tests passed'
priority = 4
ENV["WATCHR"] = "1"
$spec_cmd = "spec --colour --format nested"
def growl(message)
if message.match(/\s0\s(errors|failures)/)
title = 'Watchr: All tests passed'
image = File.join(File.expand_path(File.dirname(__FILE__)), '.watchr_images', 'pass.png')
else
title = 'Watchr: Tests are failing'
image = File.join(File.expand_path(File.dirname(__FILE__)), '.watchr_images', 'pass.png')