Skip to content

Instantly share code, notes, and snippets.

View lovehandle's full-sized avatar

Ryan Closner lovehandle

  • Mailchimp
  • Brooklyn, NY
View GitHub Profile

Keybase proof

I hereby claim:

  • I am lovehandle on github.
  • I am lovehandle (https://keybase.io/lovehandle) on keybase.
  • I have a public key ASByKmKGk_jDO3RfdYlvcXPvUF9r4XD_OZ7hZV6CrHdOCQo

To claim this, I am signing this object:

def foo1
print bar
end
def foo2
print bar
bar = "baz"
end
def foo3
@lovehandle
lovehandle / benchmark.rb
Created March 24, 2016 21:12
Benchmarks class methods vs. nested class methods
require "benchmark"
class KlassMethod
def self.call
f
end
private_class_method def self.f
Random.rand
end
class Geo::Shape
def to_geojson
RGeo::GeoJSON.encode(geom)
end
end
@lovehandle
lovehandle / gist:9104033
Last active August 29, 2015 13:56
A DSL for Rule creation

An Example DSL for building rules:

RuleBuilder.build do |rule|
  rule.clearance = Clearance.first
  rule.define do
    all do
      condition { land_use_code == 'NAB' }
      any do
        condition { zone_code.in ['C-2','C-3'] }
@lovehandle
lovehandle / gist:9040129
Last active August 29, 2015 13:56
Example Data Model for Parcel Check

zone_use.rb

  class ZoneUse < ActiveRecord::Base
  end

Table "public.zone_use"

|Column |Type |Modifiers |

@lovehandle
lovehandle / gist:9026123
Last active August 29, 2015 13:56
Creates an ActiveRecord-like object that allows attributes in an Postgres HStore column to be dynamically defined
class Parcel < ActiveRecord::Base
after_initialize :initialize_delegate
before_save :set_data_from_delegate
def data
delegate.to_hash
end
def data=(data)
class Foo
end
f = Foo.new
mod = Module.new
mod.module_eval do
define_method('bar') { puts 'bar' }
private :bar
class Foo < Module
def initialize(bar)
@bar = bar
define_bar_method!
end
private
def define_bar_method!
define_method("#{@bar}") { puts 'bar!' }
# VIEW
div
= record_link(record)
# HELPER
module RecordHelper
def record_link(record)
link_to(record.something_link)
end