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 / redirects.rb
Created July 6, 2011 16:27
Sinatra app that emits various kinds of 3xx redirects
require 'sinatra'
get '/' do
<<-HTML
<ul>
<li><a href="/301.html">301</a></li>
<li><a href="/302.html">302</a></li>
<li><a href="/303.html">303</a></li>
</ul>
HTML
@rsutphin
rsutphin / gist:1068941
Created July 7, 2011 05:39
Extract gmail SMTP password from OS X keychain (from Mail.app configuration)
# Will prompt the first time
`security find-internet-password -gs smtp.gmail.com 2>&1 | grep password`.
split(' ').last.gsub('"', '').strip
@rsutphin
rsutphin / duration_updater.rb
Created August 17, 2011 22:24
Demonstrating an issue round-tripping between Syck and Psych. Clone then run syck-psych-syck.sh.
# I'm not sure why but sometimes Syck is used for 'yaml' even under 1.9.2. This forces the issue.
Y =
if RUBY_VERSION =~ /1.9/
require 'psych'
Psych
else
require 'yaml'
YAML
end
@rsutphin
rsutphin / fakefs-encodings-test.rb
Created August 25, 2011 22:07
Demonstrating two encoding-related issues for fakefs
# encoding: UTF-8
def test(env)
fn = 'foo'
File.open(fn, 'w:UTF-8') { |f| f.write '☃' }
begin
puts "Read from #{env} file: #{File.read(fn, :encoding => 'UTF-8')}"
rescue => e
@rsutphin
rsutphin / Gemfile
Created September 1, 2011 23:02
ActiveRecord 3.1 cannot load models with non-default PKs unless there's already a database connection
source :rubygems
gem 'activerecord', ENV['AR_VERSION'] || '3.1.0'
gem 'sqlite3', '~> 1.3.4'
@rsutphin
rsutphin / Gemfile
Created September 2, 2011 19:15
ActiveRecord 3.1 does not restore connection inheritance after removing a connection from a model
source :rubygems
gem 'activerecord', '~> 3.1.0'
gem 'sqlite3'
@rsutphin
rsutphin / Gemfile
Created October 17, 2011 14:28
RSpec 2.7.0: rcov task does not work
source :rubygems
gem 'rake'
gem 'rspec', '~> 2.7.0'
gem 'rcov'
@rsutphin
rsutphin / a_spec.rb
Created October 17, 2011 16:23
RSpec 2.7.0: Problem with full_description
describe 'A' do
describe '#foo' do
it 'is generally okay' do; end
describe 'subconcern' do
it 'has common behavior' do; end
describe 'case 1' do
it 'does the right thing' do; end
end
@rsutphin
rsutphin / Gemfile
Created October 18, 2011 18:38
Minimal Gemfile for bundler #1486
source :rubygems
gem 'i18n', '~> 0.4'
gem 'activesupport', '~> 3.0'
gem 'activerecord', '~> 3.0'
gem 'builder', '~> 2.1.2'
@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