Skip to content

Instantly share code, notes, and snippets.

Avatar

Rhett Sutphin rsutphin

View GitHub Profile
@rsutphin
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 < Struct.new(:name, :songs); end
class Song < Struct.new(:title, :track); end
module AlbumPresenter
include Representable::JSON
property :name
@rsutphin
rsutphin / Gemfile
Created Jul 17, 2013
Bizarre Kernel.exec problem caused by "dropbox" gem
View Gemfile
source 'https://rubygems.org'
gem 'dropbox'
@rsutphin
rsutphin / clear_radio.html
Created Mar 14, 2013
Example of resetting an HTML radio button to unchecked using JavaScript.
View clear_radio.html
<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 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
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
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
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="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 Nov 23, 2012
A trivial client for the rubygems.org 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 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 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 = 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 Jul 18, 2012
Attempt to reproduce surveyor #346
View threefoursix.sh
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.