Skip to content

Instantly share code, notes, and snippets.

@ryanb
ryanb / gist:4688
Created August 9, 2008 16:55 — forked from jlindley/gist:4683
# AR Object dup vs marshal benchmarks
#
# re: http://rails.lighthouseapp.com/projects/8994/tickets/785
#
# user system total real
# string saved in hash 0.060000 0.000000 0.060000 ( 0.051861)
# string marshalling 0.630000 0.000000 0.630000 ( 0.643304)
#
# object saved in hash 0.060000 0.000000 0.060000 ( 0.052789)
# object marshalling 7.020000 0.030000 7.050000 ( 7.073463)
@ryanb
ryanb / gist:71618
Created February 27, 2009 18:24 — forked from lukeredpath/gist:71585
class Tag
has_many :taggings
named_scope :important, :include => { :taggings => :important }
end
class Tagging
belongs_to :tag
belongs_to :posts
# uses a string 'flag' column but could be changed to a boolean important
orders = {}
all_orders.group_by(&:ItemCode).each do |item_code, code_orders|
orders[item_code] = {}
code_orders.group_by(&:year).each do |year, year_orders|
orders[item_code][year] = {}
year_orders.group_by(&:month).each do |month, month_orders|
orders[item_code][year][month] = month_orders.first.quantity
end
orders[item_code][year]["total"] = orders[item_code][year].values.map(&:to_f).sum
end
@ryanb
ryanb / morse.rb
Created June 10, 2010 17:56 — forked from swhitt/morse.rb
def morse s;26.times{|i|s.gsub! /#{(97+i).chr}/i,("$be5 J8G#T6P'&9Sl/,!-H0cfk"[i]-31).to_s(3).tr("12",".-")};s;end
@ryanb
ryanb / README.md
Created May 15, 2011 16:24 — forked from copiousfreetime/my-gh-issues.rb
My Github Issues

First install the required gems:

gem install octokit awesomeprint rainbow

Then run it to extract all of your open GitHub issues into files (with comments).

ruby my-gh-issues.rb
@ryanb
ryanb / employees_controller_test.rb
Created September 30, 2011 20:48 — forked from noahhendrix/employees_controller_test.rb
Testing a regular user can not create a user
require 'test_helper'
require 'clearance/testing'
class EmployeesControllerTest < ActionController::TestCase
test "an ASM can not create a user" do
sign_in
assert_raise CanCan::AccessDenied do
post :create, :employee => { :name => 'Feed Store' }
end
@ryanb
ryanb / 0_the_explanation.md
Created December 22, 2011 06:23 — forked from jonsmock/0_the_explanation.txt
Oh the conditionals!

This example is not my real app, but it's modeled pretty closely to it.

My mom schedules a couple hundred employees at a local warehouse. In their system, a worker can earn "points" for being late or missing shifts. Here we have a sort of summary screen for my mom, who may need to follow up with new employees or discipline employees with concerning levels of points.

Questions that arise as I code something like this:

  • Which objects deserve presenters?