Skip to content

Instantly share code, notes, and snippets.

View d11wtq's full-sized avatar

Chris Corbyn d11wtq

  • Melbourne, Australia
View GitHub Profile
@d11wtq
d11wtq / union.scm
Created June 18, 2012 14:32
An exercise from The Seasoned Schemer. I really like the shape and feel of this.
; 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
(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)
@d11wtq
d11wtq / caching.txt
Created August 14, 2012 10:16
An awesome caching proxy should...
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
};
@d11wtq
d11wtq / let.js
Created August 18, 2012 05:54
RSpec style let() in Jasmine/Mocha
/**
* 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;
source_key: >
reallylongbase64encodedstring
splitovermultiplelinesforthes
akeofmyhealthandforvim==
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
@d11wtq
d11wtq / enum.sql
Created October 26, 2012 10:07
Renaming an ENUM label in PostgreSQL
/*
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';
@d11wtq
d11wtq / ansi_color_test.rb
Created October 28, 2012 23:03
ANSI Color Test Script
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
class Sidekiq::Middleware::Server::GC
def call(worker, msg, queue)
yield
ensure
GC.start
end
end
@d11wtq
d11wtq / time.rb
Created March 20, 2013 03:18
Like Timecop, but simpler.
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