Skip to content

Instantly share code, notes, and snippets.


Rhett Sutphin rsutphin

View GitHub Profile
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 / 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 / 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}"
View nokogiri-816.rb
require 'rubygems'
gem 'nokogiri', ENV['NOKOGIRI_VERSION'] || '1.5.6'
require 'nokogiri'
xml = <<-XML
<xs:schema xmlns="" xmlns:fn="" xmlns:ncs="" xmlns:ncsdoc="" xmlns:xlink="" xmlns:xs="" targetNamespace="" elementFormDefault="unqualified" attributeFormDefault="unqualified">
<xs:element ncsdoc:pii="P"/>
rsutphin / list_gem_deps.rb
Created Nov 23, 2012
A trivial client for the dependencies API. Prints all versions and their deps for a particular gem.
View list_gem_deps.rb
require 'pp'
require 'rubygems'
GEM_NAME = ARGV.pop or fail "Please give a gem name"
api_result = `curl{GEM_NAME}`
pp Marshal.load(api_result).sort_by { |dep|[:number]) }.reverse
rsutphin / mustache_check.rake
Created Oct 22, 2012
Rake task for mustache syntax checking an application's surveyor surveys
View mustache_check.rake
task :mustache_check => :environment do
require 'mustache/parser'
mustache_error =, :reference_identifier, :error_message)
text_error = lambda do |text|
rescue Mustache::Parser::SyntaxError => e
rsutphin /
Created Jul 18, 2012
Attempt to reproduce surveyor #346
rm -rf threefoursix
rails --version
rails new threefoursix --skip-bundle
cd threefoursix
echo "gem 'surveyor'" >> Gemfile
bundle install
script/rails g surveyor:install
You can’t perform that action at this time.