This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pg_dump -a -N schema_1 -N schema_2 \ | |
--dbname=<redacted> | \ | |
pg_restore -Fc -j 8 --verbose \ | |
--dbname=<redacted> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# There are 7 cards strictly numbered from 1 to 7. There are 3 individuals: A, | |
# B, and C. A and B each have 3 of these cards, and C has just the final 1 | |
# card. The problem is this... A wants to convey to B what his 3 cards are | |
# (with 100% certainty) in such a way that C is *never* 100% certain of them. | |
# There is no private pre-strategizing talk between A and B (in other words, C | |
# can know full well the algorithm/process and still not be able to figure out | |
# A's holdings). | |
# | |
# How can A accomplish this information transmission as described above? | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I can stub a method like this with rspec-mocks | |
allow(Math).to receive(:double) { |x| x * 2 } | |
expect(Math.double(3)).to eq(6) | |
# Is there an equivalent for Mocha? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// is there a more idiomatic way to check if the client is asking for JSON? | |
func isJson(r *http.Request) bool { | |
contentType, hasContentType := r.Header["Content-Type"] | |
return strings.HasSuffix(r.URL.Path, ".json") || | |
(hasContentType && (contentType[0] == "application/json")) | |
} |
OlderNewer