Skip to content

Instantly share code, notes, and snippets.

View ramfjord's full-sized avatar

Thomas Ramfjord ramfjord

  • Quantcast
  • San Francisco, CA
View GitHub Profile
@ramfjord
ramfjord / blah_spec.rb
Last active July 14, 2016 01:23
Rspec varargs argument matching
# Actual test
it "prefixes each of it's locks with :prefix:" do
expect(ZookeeperLocker).to receive(:lock_no_retry)
.with(start_with("hello"))
lock_for_time_range "hello", @window do
# nothing
end
end
@ramfjord
ramfjord / queue.rb
Created May 27, 2016 19:52
Simple Ruby Queue
class MyQ
def initialize
@head = @tail = []
end
def enq(obj)
@tail << obj << [] # must use methods that mutate the array here
@tail = @tail[1]
obj
end
pg_dump -a -N schema_1 -N schema_2 \
--dbname=<redacted> | \
pg_restore -Fc -j 8 --verbose \
--dbname=<redacted>
database=> BEGIN;
BEGIN
database=> PREPARE dumb AS SELECT 'dumb';
PREPARE
database=> ROLLBACK;
ROLLBACK
database=> PREPARE dumb AS SELECT 'dumb';
ERROR: prepared statement "dumb" already exists
module Test
module ClassMethods
attr_accessor :var
# Make everything in ClassMethods a class method on whatever includes this
def self.included(klass)
klass.extend ClassMethods
end
end
end
module Test
module ClassMethods
attr_accessor :var
# Make everything in ClassMethods a class method on whatever includes this
def self.included(klass)
klass.extend ClassMethods
end
end
end
@ramfjord
ramfjord / gist:6dc9f0185a1894fe9076
Created June 2, 2015 01:04
TypeError nil is not a symbol or string
my_table = "table_name"
conn = ActiveRecord::Base.connection
begin
conn.execute "CREATE TABLE #{my_table} (key INTEGER, val TEXT);"
klass = Class.new(ActiveRecord::Base) do
self.table_name = my_table
primary_key = "key"
default_scope { order("key DESC NULLS LAST") }