Skip to content

Instantly share code, notes, and snippets.

Hi there!

Adam Sanderson adamsanderson

Hi there!
View GitHub Profile
adamsanderson / .tmproperties
Created Jan 13, 2016
Minimal Textmate config for Node
View .tmproperties
# Should parent directory in window title:
windowTitle = "${TM_DIRECTORY/^.*\///}/$TM_DISPLAYNAME"
# Hide node_modules from search and chooser:
excludeInFolderSearch = "node_modules"
excludeInFileChooser = "node_modules"
View README.markdown

For simple duplicate checking, which is faster, a Ruby hash, array, or set?

For arrays, we try two approaches, when inserting data either avoid duplicates, or just add them to the list.

This is most likely flawed, and should probably be taken with a grain of salt.

adamsanderson / Gemfile
Last active Oct 13, 2018
Demonstration of hierarchical queries in Postgres using a materialized path. It will create a new database that you can later play around with.
View Gemfile
source ''
gem 'activerecord', '4.0.0.rc1'
adamsanderson / estimate.peg
Created Jul 18, 2011
PEG for LiquidPlanner Ranged Estimate
View estimate.peg
// Just playing around...
= '[' _ est:estimate _ ']' { return est; }
/ est:estimate { return est; }
= low:duration _ '-' _ high:duration {return [low, high]}
/ fixed:duration { return [fixed, fixed]; }
adamsanderson / perf.js
Created Apr 22, 2011
Webkit Page Load Performance
View perf.js
// One liner to report the perceived performance of a page:
TM = window.performance.timing; console.log(window.location.toString(), TM.domInteractive - TM.unloadEventStart, TM.domComplete - TM.unloadEventStart);
adamsanderson / gist:786562
Created Jan 19, 2011
Instrumentation for rails test cases in ruby 1.9
View gist:786562
@__mem_stats = ObjectSpace.count_objects.dup
ObjectSpace.count_objects.each{|k,v| puts("%12s: %d" % [k, v - @__mem_stats[k] || 0]) }
adamsanderson / future.rb
Created Jan 18, 2011
An example of using Delegator to implement Futures in ruby.
View future.rb
require 'delegate'
class Future < SimpleDelegator
def initialize(&block)
@_thread = Thread.start(&block)
def __getobj__
__setobj__(@_thread.value) if @_thread.alive?
adamsanderson / transient_cache.rb
Created Jan 3, 2011
An example of using WeakRef for caching data
View transient_cache.rb
require 'weakref'
class TransientCache < Hash
class AmbivalentRef < WeakRef
def __getobj__
super rescue nil
def []= key, object
adamsanderson / job_runner.rb
Created Dec 22, 2010
An example of using TSort
View job_runner.rb
require 'tsort'
class JobRunner
include TSort
Job =, :dependencies)
def initialize()
@jobs ={|h,k| h[k] = []}
adamsanderson / test_mail_purge.rb
Created Dec 18, 2010
An example of using MiniTest::Mock
View test_mail_purge.rb
require 'minitest/mock'
require 'minitest/unit'
require 'date'
class TestMailPurge < MiniTest::Unit::TestCase
class MailPurge
def initialize(imap)
@imap = imap