Skip to content

Instantly share code, notes, and snippets.

Avatar

Rhett Sutphin rsutphin

View GitHub Profile
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 / datagram_test.rb
Created Nov 30, 2015
Parallel processing in ruby with datagrams for bidirectional message passing
View datagram_test.rb
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 Nov 21, 2015
Demonstrating unexpected behavior in cancancan
View Gemfile
source 'https://rubygems.org'
gem 'cancancan'
@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
@rsutphin
rsutphin / time_ext.rb
Created Jun 25, 2012
Demonstrates an issue with selective core_ext and Time.=== on ActiveSupport 3.2.4-3.2.6
View time_ext.rb
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 Apr 19, 2012
Demonstrating an issue with Bundler.with_clean_env and local path installs (#1858)
View .gitignore
.bundle
Gemfile.lock
local-bundle
@rsutphin
rsutphin / .gitignore
Created Feb 7, 2012
Example for a question about jar-packaged gems in JRuby
View .gitignore
aker-gems.jar
gem_home
@rsutphin
rsutphin / foo_spec.rb
Created Nov 10, 2011
RSpec: `let`s leak across examples when invoked from before(:all)
View foo_spec.rb
puts "rspec-core #{RSpec::Core::Version::STRING}"
class InstantiationCounter
def initialize(k)
$count ||= { }
$count[k] ||= 0
$count[k] += 1
@k = k
end
You can’t perform that action at this time.