Skip to content

Instantly share code, notes, and snippets.

View mattyoho's full-sized avatar

Matt Yoho mattyoho

  • San Francisco, CA, USA
View GitHub Profile
@defunkt
defunkt / url_dsl.rb
Created December 14, 2009 09:59
The Ultimate URL DSL!
require 'open-uri'
# url dsl -- the ultimate url dsl!
#
# You just can't beat this:
#
# $ irb -r url_dsl
# >> include URLDSL
# => Object
# >> http://github.com/defunkt.json
~/projects/jruby ➔ jruby -J-Xrunjdwp:transport=dt_socket,server=y,address=12345,suspend=n object_walker_test.rb
Listening for transport dt_socket at address: 12345
found object: I am Foo #0
found object: I am Foo #1
found object: I am Foo #2
found object: I am Foo #3
found object: I am Foo #4
found object: I am Foo #5
found object: I am Foo #6
found object: I am Foo #7
@defunkt
defunkt / gemspec
Created March 9, 2010 01:41
Quickly create a gemspec.
#!/usr/bin/env ruby
# Usage: gemspec [-s] GEMNAME
#
# Prints a basic gemspec for GEMNAME based on your git-config info.
# If -s is passed, saves it as a GEMNAME.gemspec in the current
# directory. Otherwise prints to standard output.
#
# Once you check this gemspec into your project, releasing a new gem
# is dead simple:
#
group :first do
gem "activerecord", "2.0.5"
end
group :second do
gem "activerecord", "2.3.5"
end
group :third do
gem "activerecord", "3.0.0.rc2"
@jnunemaker
jnunemaker / gist:468109
Created July 8, 2010 14:52 — forked from jseifer/gist:468075
rvm version and git branch/dirtyness in prompt
function __git_dirty {
git diff --quiet HEAD &>/dev/null
[ $? == 1 ] && echo "!"
}
function __git_branch {
__git_ps1 "(%s)"
}
function __my_rvm_ruby_version {
@jyurek
jyurek / tempify.rb
Created July 14, 2010 13:25
Make any File a temporary file
require 'fileutils'
class File
def self.finalizer(path)
lambda do
FileUtils.rm(path)
end
end
def tempify!
# place in features/support
require 'ephemeral_response'
EphemeralResponse.configure do |config|
config.expiration = lambda { one_day * 30 }
config.white_list = ['localhost', '127.0.0.1']
config.register('api.twitter.com') do |request|
if oauth_token_match = request['authorization'].match(/oauth_token=\"\d+-\w+"/)
"#{request.uri.to_s}#{request.method}#{oauth_token_match[0]}"
else
Capybara.current_session.driver.current_session.instance_eval { @rack_mock_session }.cookie_jar
~/Code/rubygems /master > gem list gemcutter
*** LOCAL GEMS ***
gemcutter (0.6.1, 0.5.0)
~/Code/rubygems /master > irb -rubygems
ruby-1.8.7-p299 > Gem.find_files "rubygems_plugin"
=> ["/Users/wycats/.rvm/gems/ruby-1.8.7-p299/gems/gem-open-0.1.2/lib/rubygems_plugin.rb", "/Users/wycats/.rvm/gems/ruby-1.8.7-p299/gems/gemcutter-0.5.0/lib/rubygems_plugin.rb", "/Users/wycats/.rvm/gems/ruby-1.8.7-p299/gems/gemcutter-0.6.1/lib/rubygems_plugin.rb"]
ruby-1.8.7-p299 > Gem.loaded_specs.map {|k,v| v.full_name }
=> ["gem-open-0.1.2", "gemcutter-0.5.0", "json_pure-1.4.6"]
@dchelimsky
dchelimsky / gist:590557
Created September 21, 2010 21:10 — forked from qrush/gist:590466
describe SomeClass do
freeze { 1.day.from_now }
it "does some stuff with time" do
end
end
# this actually does...
describe SomeClass do
around { |example| Timecop.freeze(1.day.from_now, &example) }