Skip to content

Instantly share code, notes, and snippets.

View dbrady's full-sized avatar

David Brady dbrady

View GitHub Profile
@dbrady
dbrady / donkey_patches.rb
Created July 27, 2011 07:25 — forked from blowmage/edgecase.rb
Ruby Koans Hackfest
#!/usr/bin/env ruby
# -*- ruby -*-
# This is a fully-functional set of donkey patches that will break
# Ruby so badly that it makes all of the Ruby Koans pass right out of
# the box. ALl you need to do is patch edgecase.rb with this line:
#
# require File.expand_path(File.dirname(__FILE__) + '/donkey_patches')
#
# so it's the first line of the file. Then save this file as
@dbrady
dbrady / edgecase.rb
Created July 27, 2011 07:24 — forked from blowmage/edgecase.rb
Ruby Koans Hackfest
#!/usr/bin/env ruby
# -*- ruby -*-
require 'test/unit/assertions'
class Object
def method_missing *args
true
end
end
@dbrady
dbrady / gist:1093745
Created July 19, 2011 21:20
json parse error after obj.store
2) Creating a document as the owner of the bucket behaves like a successful create should create the document
Failure/Error: before { @file = api_create @bucket, @key }
JSON::ParserError:
706: unexpected token at '"{\"key\":\"jwstntycxp\"}"'
@dbrady
dbrady / zample.rb
Created July 9, 2011 04:47
Regex Flipflop Zample
DATA.each_line do |line|
puts line if line =~ /metasyntactic/ .. line =~ /regular/
end
__END__
blah
blarg
bleem
here are some metasyntactic variables
foo
@dbrady
dbrady / active_record_object_or_id.rb
Created July 7, 2011 18:25
Get ActiveRecord object from object_or_id argument
class StoreProductCollaborator
def initialize(product_or_id, store_or_id)
# I use this pattern everywhere. I would like to abstract it, but
# can't think of a good name for the abstraction.
@product = Product.find(product_or_id) unless product_or_id.is_a? Product
@store = Store.find(store_or_id) unless store_or_id.is_a? Store
end
# Intended usage examples:
# sp1 = StoreProductCollaborator.new(42, 13)
@dbrady
dbrady / pair_once.js
Created June 26, 2011 04:47
Process every pair in a set only once
// How to do this algorithm in Smalltalk? Call a function on each pair of elements
// in a set once. Do not call func(b,a) if func(a,b) has already been called.
var i,j,ray,func;
ray = [3,2,11,7,5];
func = function(a,b) {
console.log(a + "x" + b + " -> " + a*b);
};
@dbrady
dbrady / gist:1021248
Created June 12, 2011 04:17
FizzBuzz!
Transcript clear.
(1 to: 100) do: [ :i | (i \\ 15 = 0)
ifTrue: [Transcript show: 'FizzBuzz']
ifFalse: [
(i \\ 3 = 0)
ifTrue: [ Transcript show: 'Fizz']
ifFalse: [
(i \\ 5 = 0)
ifTrue: [ Transcript show: 'Buzz' ]
ifFalse: [Transcript show: i].
@dbrady
dbrady / csv_tests.rb
Created May 26, 2011 06:05
Unit Tests for CSV demonstrating that Enumerable is supported only at the whim of the underlying StringIO seek position
#!/usr/bin/env ruby
unless RUBY_VERSION.start_with? "1.9"
puts "This test file is for Ruby 1.9.x"
exit -1
end
require 'csv'
require 'test/unit'
@dbrady
dbrady / vim_eshell.el
Created May 25, 2011 16:59
Run vim natively inside emacs
(defun run-vim ()
(interactive)
(eshell)
(switch-to-buffer "*eshell*")
(insert "vi")
(eshell-send-input))
@dbrady
dbrady / error.log
Created May 21, 2011 22:52
devise install error
# THIS IS FIXED! TL;DR: Sprockets has a bug in betas 3, 4, and 5, roll back to beta 2.
#
# See: http://umwhatnow.com/rails-fix-your-3-1-beta-1-sprockets-problem/
#
# Wots of wuv, Dave and Bwandon
∫ rails g devise_install
/Users/dbrady/.rvm/gems/ruby-1.9.2-p180@ian/gems/actionpack-3.1.0.beta1/lib/sprockets/railtie.rb:37:in `block (2 levels) in <class:Railtie>': undefined method `context' for #<Sprockets::Environment:0x0000010098f840> (NoMethodError)
from /Users/dbrady/.rvm/gems/ruby-1.9.2-p180@ian/gems/activesupport-3.1.0.beta1/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
from /Users/dbrady/.rvm/gems/ruby-1.9.2-p180@ian/gems/activesupport-3.1.0.beta1/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'