Skip to content

Instantly share code, notes, and snippets.

Adam Sanderson adamsanderson

Block or report user

Report or block adamsanderson

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
@adamsanderson
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
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 'https://rubygems.org'
gem 'activerecord', '4.0.0.rc1'
@adamsanderson
adamsanderson / estimate.peg
Created Jul 18, 2011
PEG for LiquidPlanner Ranged Estimate
View estimate.peg
// 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 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
adamsanderson / gist:786562
Created Jan 19, 2011
Instrumentation for rails test cases in ruby 1.9
View gist:786562
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 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)
end
def __getobj__
__setobj__(@_thread.value) if @_thread.alive?
@adamsanderson
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
end
end
def []= key, object
@adamsanderson
adamsanderson / job_runner.rb
Created Dec 22, 2010
An example of using TSort
View job_runner.rb
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 Dec 18, 2010
An example of using MiniTest::Mock
View test_mail_purge.rb
require 'minitest/mock'
require 'minitest/unit'
require 'date'
MiniTest::Unit.autorun
class TestMailPurge < MiniTest::Unit::TestCase
class MailPurge
def initialize(imap)
@imap = imap
You can’t perform that action at this time.