Skip to content

Instantly share code, notes, and snippets.

View mattyoho's full-sized avatar

Matt Yoho mattyoho

  • Portland, OR, USA
View GitHub Profile
@zaius
zaius / background.sh
Created January 16, 2011 23:29
How to redirect a running process output to a file and log out
ctrl-z
bg
touch /tmp/stdout
touch /tmp/stderr
gdb -p $!
# In GDB
p dup2(open("/tmp/stdout", 1), 1)
p dup2(open("/tmp/stderr", 1), 2)
@rbxbx
rbxbx / lambda_methods.rb
Created December 14, 2010 01:36
define methods on a lambda, who knew. Well, probably a lot of you.
Objector = lambda do |properties|
lambda do |meth|
properties[meth]
end
end
def Objector.new(props); self[props] end
~/projects ➔ gem install cloby
Successfully installed cloby-0.0.1-java
1 gem installed
Installing ri documentation for cloby-0.0.1-java...
Installing RDoc documentation for cloby-0.0.1-java...
~/projects ➔ cat simple.rb
require 'cloby'
class MyClojureObj < Clojure::Object
@igrigorik
igrigorik / webapp.rb
Created November 13, 2010 21:28
Inspired by @JEG2's talk at Rubyconf... Any ruby object, as a webapp! 'Cause we can. :-)
require 'rubygems'
require 'rack'
class Object
def webapp
class << self
define_method :call do |env|
func, *attrs = env['PATH_INFO'].split('/').reject(&:empty?)
[200, {}, send(func, *attrs)]
end
@stevenharman
stevenharman / Iso8601DateTimeBinder.cs
Created November 2, 2010 19:25
an asp.net-mvc Model Binder that respects the ISO 8601 standard. look it up, yo!
using System;
using System.Globalization;
using System.Web.Mvc;
namespace Zomg.Web.ModelBinders
{
public class Iso8601DateTimeBinder : DefaultModelBinder
{
public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
@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) }
~/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"]
Capybara.current_session.driver.current_session.instance_eval { @rack_mock_session }.cookie_jar
# 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
@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!