This file contains hidden or 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
; Given two sets, return a new set containing the unique members from each. | |
(define (union set1 set2) | |
(letrec | |
((union | |
(lambda (set) | |
(cond | |
((null? set) set2) | |
((member? (car set) set2) | |
(union (cdr set))) | |
(else |
This file contains hidden or 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
(define (each-fib fn) | |
(letrec | |
((next (lambda (a b) | |
(fn a) | |
(next b (+ a b))))) | |
(next 0 1))) | |
(define (take-n-fibs n) | |
(call/cc | |
(lambda (return) |
This file contains hidden or 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
Imagine something like: | |
var http = require('http') | |
, cache = require('cache') | |
; | |
var options = { | |
ignoreCookies: true, | |
cacheStatics: 300 // 5 minutes, unless an explicit cache-control header is given | |
}; |
This file contains hidden or 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
/** | |
* Get RSpec-style let() in your Mocha/Jasmine specs. | |
*/ | |
var let = function (callback) { | |
var value, called = false; | |
var memoizer = function() { | |
if (called) { | |
return value; | |
} else { | |
called = true; |
This file contains hidden or 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
source_key: > | |
reallylongbase64encodedstring | |
splitovermultiplelinesforthes | |
akeofmyhealthandforvim== |
This file contains hidden or 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
module DataMapper | |
class Transaction | |
def link_with_master_slave(*things) | |
things = things.collect do |t| | |
case t | |
when DataMapper::Adapters::MasterSlaveAdapter | |
t.master | |
else | |
t | |
end |
This file contains hidden or 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
/* | |
Assuming you have an enum type like this. | |
You want to rename 'pending' to 'lodged' | |
*/ | |
CREATE TYPE dispute_status AS ENUM('pending', 'resolved', 'open', 'cancelled'); | |
BEGIN; | |
ALTER TYPE dispute_status ADD VALUE 'lodged'; | |
UPDATE dispute SET status = 'lodged' WHERE status = 'pending'; |
This file contains hidden or 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
class AnsiColorTest | |
FG = 38 | |
BG = 48 | |
class << self | |
def label(n, type) | |
"\033[01;#{type};5;#{n}m %3s \033[0m" % n | |
end | |
def dump256 |
This file contains hidden or 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
class Sidekiq::Middleware::Server::GC | |
def call(worker, msg, queue) | |
yield | |
ensure | |
GC.start | |
end | |
end |
This file contains hidden or 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
class Time | |
class << self | |
attr_accessor :mock_time | |
def now_with_mock_time | |
@mock_time || now_without_mock_time | |
end | |
alias_method_chain :now, :mock_time |