Skip to content

Instantly share code, notes, and snippets.

View dbrady's full-sized avatar

David Brady dbrady

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / gist:1114136
Created July 29, 2011 16:12
RVM choking on rspec, not remembering .rvmrc
10:09:09 dbrady@shinything:~/projects (git:develop:928475c) ruby-1.9.2-p290
∫ cd adsel
rspec: No such file or directory
0.00 real 0.00 user 0.00 sys
Usage:
db database_file {{key}} {{value}} # set
db database_file {{key}} # get
@dbrady
dbrady / gist:1114768
Created July 29, 2011 21:22
RVM choking on rspec even when rspec isn't there, not remembering .rvmrc
# I just created the pants/ folder and put this .rvmrc in it:
#
# rvm use ruby-1.9.2
#
# Note that rake 0.8.7 is the only gem in my global gemset, so
# rspec ISN'T EVEN INSTALLED NOW.
15:19:50 dbrady@shinything:~/devel/pants ruby-1.9.2-p290@coffer
∫ . .rvmrc
Using /Users/dbrady/.rvm/gems/ruby-1.9.2-p290
@dbrady
dbrady / gist:1114747
Created July 29, 2011 21:11
RVM choking on rspec, not remembering .rvmrc
# After updating rvm, it is surprised and alarmed by .rvmrc files.
# It doesn't recognize them as trusted, and then crashes after
# approving them. Which means EVERY time I cd inside a project with
# an .rvmrc file, this happens:
#
# (Note that I am in ruby-1.9.2-p290@adsel. The 'coffer' directory
# has an .rvmrc file which specifies ruby-1.9.2-p180@coffer.)
15:05:52 dbrady@shinything:~/devel ruby-1.9.2-p290@adsel
∫ cd coffer
@dbrady
dbrady / gist:1114810
Created July 29, 2011 21:47
RVM choking on rspec, not remembering .rvmrc
# Does RVM now use some kind of file db system to remember .rvmrc files?
# The beginning of the (rather long) error message makes me wonder...
15:44:00 dbrady@shinything:~
∫ cd devel/coffer
rspec: No such file or directory
0.00 real 0.00 user 0.00 sys