Skip to content

Instantly share code, notes, and snippets.

Chris Corbyn d11wtq

  • Melbourne, Australia
Block or report user

Report or block d11wtq

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@d11wtq
d11wtq / functional_ruby.rb
Created Mar 25, 2013
Lists, and the concept of "head" and "tail", coupled with recursion are at the core of functional programming. This demonstrates how you can do it in Ruby, without ever writing a loop.
View functional_ruby.rb
# foldl() is fundamental. With a fold, you can do everything else.
def foldl(list, acc, &fn)
if list == [] # base case, return the accumulator
acc
else
head, *tail = list
foldl(tail, fn.call(acc, head), &fn) #recurse on the remainder
end
end
View kitchen.erl
%% @doc This implements a kitchen fridge that you can put things into
%% and take them out.
%%
%% It is stateful, through the use of recursion.
%% I opted for the sets module only because I wanted to try it.
%% Using the sets module has the side-effect that you can only store
%% one of each food item in the fridge.
-module(kitchen).
-export([new/0, store/2, take/2]).
@d11wtq
d11wtq / calc.erl
Last active Dec 15, 2015
Reverse Polish Notation Calculator in Erlang
View calc.erl
%% @doc Reverse Polish Notation Calculator.
%%
%% Parses expressions like "1 2 3 + -" = -4
%%
%% This is an exercise in Learn You some Erlang for Great Good,
%% however I didn't read the text and just implemented it.
%%
%% I guess understanding stack-based parsing helps here.
-module(calc).
-export([rpn/1]).
@d11wtq
d11wtq / time.rb
Created Mar 20, 2013
Like Timecop, but simpler.
View time.rb
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
View gc.rb
class Sidekiq::Middleware::Server::GC
def call(worker, msg, queue)
yield
ensure
GC.start
end
end
@d11wtq
d11wtq / ansi_color_test.rb
Created Oct 28, 2012
ANSI Color Test Script
View ansi_color_test.rb
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
View dm-transactions-patch.rb
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
View gist:3832709
source_key: >
reallylongbase64encodedstring
splitovermultiplelinesforthes
akeofmyhealthandforvim==
@d11wtq
d11wtq / caching.txt
Created Aug 14, 2012
An awesome caching proxy should...
View caching.txt
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
};
View fibs.scm
(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)
You can’t perform that action at this time.