Skip to content

Instantly share code, notes, and snippets.

View bkempner's full-sized avatar

Ben Kempner bkempner

  • Auto List
  • Austin, TX
View GitHub Profile
@bkempner
bkempner / gist:2839211
Created May 30, 2012 22:01
cherry-pick behavior
Maurices-MacBook-Pro:Projects ben$ mkdir gitfoo
Maurices-MacBook-Pro:Projects ben$ cd gitfoo/
Maurices-MacBook-Pro:gitfoo ben$ g init
Initialized empty Git repository in /Users/ben/Projects/gitfoo/.git/
Maurices-MacBook-Pro:gitfoo ben$ touch foo
echMaurices-MacBook-Pro:gitfoo ben$ echo 'foo' >> foo
Maurices-MacBook-Pro:gitfoo ben$ g c -am 'initial commit'
# On branch master
#
# Initial commit
de2nq092qkqfxll=> create index ben_test_partial on units (city_name) where is_deleted = true;
CREATE INDEX
de2nq092qkqfxll=> explain select count(*) from units where city_name = 'San Francisco' and is_deleted = true;
QUERY PLAN
----------------------------------------------------------------------------------------
Aggregate (cost=1276.17..1276.17 rows=1 width=0)
-> Bitmap Heap Scan on units (cost=35.38..1276.00 rows=331 width=0)
Recheck Cond: (((city_name)::text = 'San Francisco'::text) AND is_deleted)
-> Bitmap Index Scan on ben_test_partial (cost=0.00..35.37 rows=331 width=0)
Index Cond: ((city_name)::text = 'San Francisco'::text)
class Foo
def initialize
yield(self) if block_given?
end
end
# Shouldn't these be equivalent? Why isn't thing1 created?
f1 = Foo.new { |me| @thing1 = 'this is thing1' }
f1.instance_variable_get("@thing1") #=> nil
Why are indicies being handled differently in these cases? Below are three different but equivalent queries i would think should handle indicies the same:
Indicies:
Locations:
Indexes:
"locations_pkey" PRIMARY KEY, btree (id)
"index_locations_on_simplified_polygon" gist (simplified_polygon)
Check constraints:
"enforce_srid_simplified_polygon" CHECK (st_srid(simplified_polygon) = 4326)
module Foo
module_function
def wtf?
'wtf?'
end
end
Foo.wtf? #=> 'wtf?'
class Foo
def initialize(options)
@bar = options.fetch(:bar, nil)
@baz = options.fetch(:baz, nil)
end
end
def Foo(options)
Foo.new(options)
end
case
when true
puts 'yes'
when false
puts 'no'
else
puts 'i dont understand'
end
case
@bkempner
bkempner / gist:1235916
Created September 22, 2011 20:21
Spatial indicies
#
# Indexes for units table
#
Indexes:
"units_pkey" PRIMARY KEY, btree (id)
"index_units_on_normalization" UNIQUE, btree (normalization)
"index_units_on_city_id" btree (city_id)
"index_units_on_coordinates" gist (coordinates)
"index_units_on_neighborhood_id" btree (neighborhood_id)
@bkempner
bkempner / gist:1229943
Created September 20, 2011 18:47
Strange let behavior with threads
class Foo; end
describe Foo do
# expected behavior
context 'when not testing with let' do
it "uses the same Foo object inside threads" do
foo = Foo.new
obj_id = @foo.object_id
Class.class
=> Class
Class.new.class
=> Class
Class.instance_methods.count
=> 109
Class.new.instance_methods.count