Skip to content

Instantly share code, notes, and snippets.

View adamsanderson's full-sized avatar
👋
Hi there!

Adam Sanderson adamsanderson

👋
Hi there!
View GitHub Profile
@adamsanderson
adamsanderson / .tmproperties
Created January 13, 2016 21:03
Minimal Textmate config for Node
# Should parent directory in window title:
windowTitle = "${TM_DIRECTORY/^.*\///}/$TM_DISPLAYNAME"
# Hide node_modules from search and chooser:
excludeInFolderSearch = "node_modules"
excludeInFileChooser = "node_modules"
@adamsanderson
adamsanderson / README.markdown
Created March 29, 2015 23:42
Hash vs Array vs Set

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
adamsanderson / Gemfile
Last active January 23, 2024 14:08
Demonstration of hierarchical queries in Postgres using a materialized path. It will create a new database that you can later play around with.
source 'https://rubygems.org'
gem 'activerecord', '4.0.0.rc1'
@adamsanderson
adamsanderson / estimate.peg
Created July 18, 2011 23:21
PEG for LiquidPlanner Ranged Estimate
// Just playing around...
// http://pegjs.majda.cz/online
start
= '[' _ est:estimate _ ']' { return est; }
/ est:estimate { return est; }
estimate
= low:duration _ '-' _ high:duration {return [low, high]}
/ fixed:duration { return [fixed, fixed]; }
@adamsanderson
adamsanderson / perf.js
Created April 22, 2011 15:07
Webkit Page Load Performance
// 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
adamsanderson / gist:786562
Created January 19, 2011 18:02
Instrumentation for rails test cases in ruby 1.9
setup{
GC.start
@__mem_stats = ObjectSpace.count_objects.dup
}
teardown{
GC.start
ObjectSpace.count_objects.each{|k,v| puts("%12s: %d" % [k, v - @__mem_stats[k] || 0]) }
}
@adamsanderson
adamsanderson / future.rb
Created January 18, 2011 15:44
An example of using Delegator to implement Futures in ruby.
require 'delegate'
class Future < SimpleDelegator
def initialize(&block)
@_thread = Thread.start(&block)
end
def __getobj__
__setobj__(@_thread.value) if @_thread.alive?
@adamsanderson
adamsanderson / transient_cache.rb
Created January 3, 2011 01:20
An example of using WeakRef for caching data
require 'weakref'
class TransientCache < Hash
class AmbivalentRef < WeakRef
def __getobj__
super rescue nil
end
end
def []= key, object
@adamsanderson
adamsanderson / job_runner.rb
Created December 22, 2010 19:45
An example of using TSort
require 'tsort'
class JobRunner
include TSort
Job = Struct.new(:name, :dependencies)
def initialize()
@jobs = Hash.new{|h,k| h[k] = []}
end
@adamsanderson
adamsanderson / test_mail_purge.rb
Created December 18, 2010 04:35
An example of using MiniTest::Mock
require 'minitest/mock'
require 'minitest/unit'
require 'date'
MiniTest::Unit.autorun
class TestMailPurge < MiniTest::Unit::TestCase
class MailPurge
def initialize(imap)
@imap = imap