Skip to content

Instantly share code, notes, and snippets.

View lcowell's full-sized avatar

Luke Cowell lcowell

View GitHub Profile
@lcowell
lcowell / tag_demo.rb
Created January 21, 2013 16:54
redering tags in rails
require "rubygems"
require 'rails/all'
class MyApp < Rails::Application
config.active_support.deprecation = :log
end
class MyView
include ActionView::Helpers::TagHelper
end
@lcowell
lcowell / Gemfile
Created November 30, 2012 18:27
apartment postgres threading issue
source 'https://rubygems.org'
gem 'apartment'
gem 'sidekiq'
gem 'rails'
gem 'pg'
@lcowell
lcowell / gist:2033824
Created March 14, 2012 03:33
em_inline_benchmark
require 'eventmachine'
require 'em-synchrony'
require "em-synchrony/em-http"
require 'net/http'
require 'benchmark'
def em_http
EM.synchrony do
multi = EventMachine::Synchrony::Multi.new
multi.add :page1, EventMachine::HttpRequest.new("http://localhost:3000/page1").aget
@lcowell
lcowell / gist:1947435
Created March 1, 2012 05:07 — forked from dx7/gist:1333785
Installing ruby-debug with ruby-1.9.3-p0
# Install with:
# bash < <(curl -L https://raw.github.com/gist/1333785)
#
# Reference: http://blog.wyeworks.com/2011/11/1/ruby-1-9-3-and-ruby-debug
echo "Installing ruby-debug with ruby-1.9.3-p125 ..."
curl -OL http://rubyforge.org/frs/download.php/75414/linecache19-0.5.13.gem
curl -OL http://rubyforge.org/frs/download.php/75415/ruby-debug-base19-0.11.26.gem
@lcowell
lcowell / highlight_test.mkd
Created February 4, 2012 22:44
code highlighting in markdown

This is an example of code highlighting

class Ruby
  def blah
  end
end
@lcowell
lcowell / gist:1728345
Created February 3, 2012 05:33
avoiding included {} with ActiveSupport::Concern

We can call a class macro on an instance of a class like this:

class Foo attr_accessor :bar end

Foo.new.bar = 1

We can call a class macro on the class in this way:

class Deal < AR
attr_reader :minimum_order, :board_lot_size, :unit_value, :allocation_value
end
# last level allocation rate
# planned allocations
# deal
class DealAllocation < AR
belongs_to :deal
# Say you have different types of pet classes. It appears that using method_missing is preferable
# over using DelegateClass as we can decide our target at runtime. Is there a way to accomplish
# this type of behaviour using DelegateClass ?
def PetDecorator
def initialize(target)
@target = target
end
def talk
def configure(token)
user = User.find_by_token(token)
user.update_attributes(:confirmed => true) if user
user
end
# we can name each result set eg. top_male_times_this_season
result
| name |
# it's unlikely that we're going to reuse results, so we should scope them by the result they belong to
results
| age | time | gender | result_id |
| 23 | 55:11 | M | 1 |
| 49 | 1:27:51 | F | 2 |