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
;; 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
@d11wtq
d11wtq / oedipus-distributed.rb
Created May 14, 2012 14:48
Brainstorming an interface for distributed indexes with oedipus and oedipus-dm
# normally
idx = conn[:posts_rt]
idx.insert( ... )
idx.search( ... )
# distributed
idx = conn[:posts_dist, ->(id){ "posts_rt_#{id % 4}" }]
idx.insert( ... )
idx.search( ... )
module Flippa
module Job
# Allow Resque jobs to be instantiated and performed, instead of singleton classes.
module Instance
extend ActiveSupport::Concern
module ClassMethods
# Default .perform creates an instance and calls perform on that.
def perform(*args)
new(*args).perform(*args)
/home/chris/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0/lib/dm-core/model/relationship.rb:372:in `method_missing'
/home/chris/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0/lib/dm-core/model/property.rb:249:in `method_missing'
/home/chris/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:514:in `load_missing_constant'
/home/chris/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:192:in `block in const_missing'
/home/chris/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:190:in `each'
/home/chris/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:190:in `const_missing'
/home/chris/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0/lib/dm-core/model.rb:728:in `const_missing'
/home/chris/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/dm-core-1.
@d11wtq
d11wtq / gist:2215235
Created March 27, 2012 11:45
Brainstorming Sphinx 2 gem
##
# Using an index defined in code for model abstraction.
##
class PostsIndex
include Oedipus::RTIndex
connection 'sphinx.site.com:3312'
index_name :posts_rt