Skip to content

Instantly share code, notes, and snippets.

View d11wtq's full-sized avatar

Chris Corbyn d11wtq

  • Melbourne, Australia
View GitHub Profile
source_key: >
reallylongbase64encodedstring
splitovermultiplelinesforthes
akeofmyhealthandforvim==
@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;
@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
};
(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 / 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
;; This was damn hard.
;;
;; One of the exercises near the end of The Little Schemer requires defining
;; a function that uses a collector to remove odd numbers, recursively from
;; a list, sum the odd numbers and multiple the even numbers.
;;
;; This is it.
;;
;; It requires currying lambdas one inside another to deal with the recursion
;; in the collector function.
@d11wtq
d11wtq / .vimrc
Created June 6, 2012 07:21
My .vimrc
" actually run as vim, not vi
set nocompatible
" 256-color terminal
set t_Co=256
" utf-8 by default
set encoding=utf-8
" vundle requires turning off filetypes momentarily
; Remove a given member from a list
(define rember
(lambda (a lat)
(cond
((null? lat) '())
((eq? (car lat) a) (cdr lat))
(else (cons (car lat)
(rember a (cdr lat)))))))
@d11wtq
d11wtq / boot.rb
Created May 27, 2012 15:49
Rails startup time optimization
# Instructions for use
#
# 1. Execute "time rails runner nil" a few times in your shell, see how long rails takes to boot
# 2. Add this monkey patch to the top of config/boot.rb
# 3. Repeat step 1. What's the difference?
#
# This is just an experiment, but it gains me 30% on Rails' start time, which suggests there is something
# in Rails that is breaking the "run only once" behaviour of #require.
#
# Note: You can't override Kernel#require, since Rails by-passes it most of the time.
@d11wtq
d11wtq / .vimrc
Created May 24, 2012 12:37
.vimrc al Chippie
" actually run as vim, not vi
set nocompatible
" 256-color terminal
set t_Co=256
" utf-8 by default
set encoding=utf-8
" vundle requires turning off filetypes momentarily