Skip to content

Instantly share code, notes, and snippets.


Rhett Sutphin rsutphin

  • Human Practice, Inc.
  • Chicago, Illinois
View GitHub Profile
rsutphin / exceed_query_limit.rb
Created Jul 7, 2014
RSpec 3 matcher for ActiveRecord query count limits. Based on
View exceed_query_limit.rb
# Derived from Updated for RSpec 3.
RSpec::Matchers.define :exceed_query_limit do |expected|
match do |block|
query_count(&block) > expected
failure_message_when_negated do |actual|
"Expected to run maximum #{expected} queries, got #{@counter.query_count}"
rsutphin / clear_radio.html
Created Mar 14, 2013
Example of resetting an HTML radio button to unchecked using JavaScript.
View clear_radio.html
<style type="text/css">
label { display: block; }
<label><input type="radio" name="q" id="radio-a" value="A"> A</label>
<label><input type="radio" name="q" id="radio-b" value="B"> B</label>
<label><input type="radio" name="q" id="radio-c" value="C"> C</label>
rsutphin / tag_and_push_tag.cap
Last active Apr 18, 2018
A capistrano 3 task to tag the repo after every deploy
View tag_and_push_tag.cap
# Requires Capistrano 3.2 or later
namespace :deploy do
after :finishing, :tag_and_push_tag do
on roles(:app) do
within release_path do
set(:current_revision, capture(:cat, 'REVISION'))
# release path may be resolved already or not
resolved_release_path = capture(:pwd, "-P")
rsutphin / repro
Last active Dec 30, 2015
Problem with spring and rails engine projects
View repro
#!/bin/bash -ex
gem list spring
gem list rails
rm -rf quux
rails plugin new quux --mountable
cd quux
rsutphin /
Created Dec 4, 2013
Use linode's DNS API for dynamic DNS with curl from cron

Use Linode's DNS Manager API for one-line dynamic DNS

This can be useful for cron, for instance.


  • You are using Linode's DNS Manager to manage a zone for your domain
  • You have already created an A record for the name you want to make dynamic
  • You have an API key for Linode's API
  • curl and jsonpp (jsonpp is not necessary but makes the manual steps easier)
rsutphin / inline_representer.rb
Created Aug 6, 2013
Attempting to use an inline representer with Representable 1.6.0
View inline_representer.rb
require 'pp'
require 'representable/json'
class Album <, :songs); end
class Song <, :track); end
module AlbumPresenter
include Representable::JSON
property :name
rsutphin / Gemfile
Created Jul 17, 2013
Bizarre Kernel.exec problem caused by "dropbox" gem
View Gemfile
source ''
gem 'dropbox'
rsutphin / gist:5102133
Created Mar 6, 2013
Surprising each_with_object behavior
View gist:5102133
1.9.3p194 :001 > %w(a b c).each_with_object(['foo']) { nil }
=> ["foo"]
1.9.3p194 :002 > %w(a b c).each_with_object(['foo']) { break }
=> nil
rsutphin / connection_method_available.rb
Created Jan 17, 2013
Demonstrates that version 1.2.5 of the jdbcpostgresql adapter does not load properly.
View connection_method_available.rb
adapter_version = ARGV[0] || '1.2.5'
require 'rubygems'
require 'active_record'
gem 'activerecord-jdbcpostgresql-adapter', adapter_version
require 'active_record/connection_adapters/jdbcpostgresql_adapter'
if ActiveRecord::Base.respond_to?('jdbcpostgresql_connection')
puts "jdbcpostgresql_connection method available in #{adapter_version}"
rsutphin / nokogiri-empty.rb
Created Dec 20, 2012
Demonstration for behavior difference between Nokogiri-C and Nokogiri-J for empty attributes in 1.5.6.
View nokogiri-empty.rb
require 'rubygems'
gem 'nokogiri', ENV['NOKOGIRI_VERSION'] || '1.5.6'
require 'nokogiri'
n = Nokogiri::XML('<foo empty="" whitespace=" "/>')
puts " Ruby: #{RUBY_DESCRIPTION}"
puts "Nokogiri: #{Nokogiri::VERSION}"
puts " Empty attribute value: #{n.root['empty'].inspect}"