This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hanoi := method(n, start, end, extra, moveDisk, | |
if(n == 1, moveDisk call(1, start, end), | |
Hanoi(n - 1, start, extra, end) | |
moveDisk call(n, start, end) | |
Hanoi(n - 1, extra, end, start) | |
) | |
) | |
printInstruction := block(n, start, end, | |
writeln("Move disk ##{n} from #{start} to #{end}" interpolate) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# MothrFlickr, a small and light wrapper for talking to Flickr's API | |
require 'json' | |
require 'net/http' | |
module MothrFlickr | |
#put your API Key in config/mothr_flickr.yml | |
module Responsable | |
def base_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foos = Foo.where(:name.in => ['bar', 'baz'] | |
#<Mongoid::Criteria:0x1035c0928 @documents=[], @klass=Foo, @selector={:name=>{"$in"=>["bar", "baz"]}}, @options={}> | |
foos | |
#[foo1, foo2, foo3, foo4] | |
foos.slice!(0,3) | |
#[foo1, foo2, foo3] | |
foos | |
#[foo1, foo2, foo3, foo4] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# usage: | |
# field_labeled('Select your address').should have_option("Home Address") | |
Spec::Matchers.define :have_option do |expected| | |
def options_for(select_field) | |
select_field.options.map(&:inner_text) | |
end | |
match do |select_field| | |
raise "Field is not a SelectField" unless select_field.kind_of?(Webrat::SelectField) | |
options_for(select_field).include?(expected) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def update_vimbundles | |
Dir.glob("#{ENV['HOME']}/.vimbundles/*").each do |d| | |
next unless File.directory?(d) | |
puts "updating #{d}" | |
`cd #{d}; git pull --rebase; cd -` | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Łukasz Piestrzeniewicz wrote this patch | |
require 'rack/test' | |
require 'rack/test/cookie_jar' | |
Rack::Test::CookieJar.class_eval do | |
def merge(raw_cookies, uri = nil) | |
return unless raw_cookies | |
raw_cookies = raw_cookies.split("\n") if raw_cookies.is_a? String | |
raw_cookies.reject! {|raw_cookie| raw_cookie.blank?} | |
raw_cookies.each do |raw_cookie| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'peach' | |
[1,2,3,4].peach{ |n| n + 1 } #Spawns 4 threads | |
[1,2,3,4].pmap{ |x| f(x) } #Spawns 4 threads, returns => [f(1),f(2),f(3),f(4)] | |
[1,2,3,4].pselect{ |x| x > 2 } #Spawns 4 threads, returns => [3,4] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Pull the english out of your specs, for great porting | |
lines = [] | |
File.read(ARGV.pop).each_line do |line| | |
next unless line =~ /^\s*(context|it|describe)/ | |
line.gsub(/#{$1}.*('|")/,'').gsub(/('|")\s+do/,'') | |
lines << line | |
end | |
puts lines.join |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Clojure port of the scheme example from http://matt.might.net/articles/implementing-a-programming-language/ | |
; Doesn't quite work. *shrug* | |
(defn any-eql? [x coll] | |
(filter #(= % x) coll)) | |
(defn perform [func x] | |
(evaluate (nnext (first func)) | |
(cons (list (fnext (first func)) (rest func))))) |
OlderNewer