Skip to content

Instantly share code, notes, and snippets.

View rsutphin's full-sized avatar

Rhett Sutphin rsutphin

  • Human Practice, Inc.
  • Chicago, Illinois
View GitHub Profile
@rsutphin
rsutphin / inline_representer.rb
Created August 6, 2013 14:54
Attempting to use an inline representer with Representable 1.6.0
require 'pp'
require 'representable/json'
class Album < Struct.new(:name, :songs); end
class Song < Struct.new(:title, :track); end
module AlbumPresenter
include Representable::JSON
property :name
@rsutphin
rsutphin / Gemfile
Created July 17, 2013 20:16
Bizarre Kernel.exec problem caused by "dropbox" gem
source 'https://rubygems.org'
gem 'dropbox'
@rsutphin
rsutphin / clear_radio.html
Created March 14, 2013 00:18
Example of resetting an HTML radio button to unchecked using JavaScript.
<html>
<head>
<style type="text/css">
label { display: block; }
</style>
<body>
<form>
<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
rsutphin / gist:5102133
Created March 6, 2013 19:14
Surprising each_with_object behavior
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
rsutphin / connection_method_available.rb
Created January 17, 2013 20:46
Demonstrates that version 1.2.5 of the jdbcpostgresql adapter does not load properly.
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
rsutphin / nokogiri-empty.rb
Created December 20, 2012 21:42
Demonstration for behavior difference between Nokogiri-C and Nokogiri-J for empty attributes in 1.5.6.
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
puts " Empty attribute value: #{n.root['empty'].inspect}"
require 'rubygems'
gem 'nokogiri', ENV['NOKOGIRI_VERSION'] || '1.5.6'
require 'nokogiri'
xml = <<-XML
<xs:schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:ncs="http://www.nationalchildrensstudy.gov" xmlns:ncsdoc="http://www.nationalchildrensstudy.gov/doc" xmlns:xlink="http://www.w3.org/TR/WD-xlink" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.nationalchildrensstudy.gov" elementFormDefault="unqualified" attributeFormDefault="unqualified">
<xs:element ncsdoc:pii="P"/>
</xs:schema>
XML
@rsutphin
rsutphin / list_gem_deps.rb
Created November 23, 2012 07:03
A trivial client for the rubygems.org dependencies API. Prints all versions and their deps for a particular gem.
require 'pp'
require 'rubygems'
GEM_NAME = ARGV.pop or fail "Please give a gem name"
api_result = `curl http://rubygems.org/api/v1/dependencies?gems=#{GEM_NAME}`
pp Marshal.load(api_result).sort_by { |dep| Gem::Version.new(dep[:number]) }.reverse
@rsutphin
rsutphin / mustache_check.rake
Created October 22, 2012 15:39
Rake task for mustache syntax checking an application's surveyor surveys
task :mustache_check => :environment do
require 'mustache/parser'
mustache_error = Struct.new(:record_type, :reference_identifier, :error_message)
text_error = lambda do |text|
begin
Mustache::Parser.new.compile(text)
nil
rescue Mustache::Parser::SyntaxError => e
@rsutphin
rsutphin / threefoursix.sh
Created July 18, 2012 20:48
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