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
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 / datagram_test.rb
Created November 30, 2015 18:30
Parallel processing in ruby with datagrams for bidirectional message passing
require 'socket'
require 'pp'
END_COMMUNICATION = "\0"
def start_child(n)
child_socket, parent_socket = Socket.pair(:UNIX, :DGRAM, 0)
maxlen = 1000
pid = fork do
@rsutphin
rsutphin / Gemfile
Last active November 21, 2015 01:48
Demonstrating unexpected behavior in cancancan
source 'https://rubygems.org'
gem 'cancancan'
@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
@rsutphin
rsutphin / time_ext.rb
Created June 25, 2012 19:50
Demonstrates an issue with selective core_ext and Time.=== on ActiveSupport 3.2.4-3.2.6
ACTIVESUPPORT_SOURCE = ARGV.pop
if ACTIVESUPPORT_SOURCE
if File.directory?(ACTIVESUPPORT_SOURCE)
puts "Using ActiveSupport from #{ACTIVESUPPORT_SOURCE}"
$LOAD_PATH << ACTIVESUPPORT_SOURCE
else ACTIVESUPPORT_SOURCE
puts "Using ActiveSupport gem version #{ACTIVESUPPORT_SOURCE}"
require 'rubygems'
gem 'activesupport', ACTIVESUPPORT_SOURCE
@rsutphin
rsutphin / .gitignore
Created April 19, 2012 04:15
Demonstrating an issue with Bundler.with_clean_env and local path installs (#1858)
.bundle
Gemfile.lock
local-bundle
@rsutphin
rsutphin / .gitignore
Created February 7, 2012 00:17
Example for a question about jar-packaged gems in JRuby
aker-gems.jar
gem_home
@rsutphin
rsutphin / foo_spec.rb
Created November 10, 2011 04:53
RSpec: `let`s leak across examples when invoked from before(:all)
puts "rspec-core #{RSpec::Core::Version::STRING}"
class InstantiationCounter
def initialize(k)
$count ||= { }
$count[k] ||= 0
$count[k] += 1
@k = k
end