Skip to content

Instantly share code, notes, and snippets.

View rubysolo's full-sized avatar

Solomon White rubysolo

View GitHub Profile
# based off of http://eigenclass.org/hiki.rb?rcov+FAQ#l3
require 'rcov/rcovtask'
namespace :test do
namespace :coverage do
desc "Delete aggregate coverage data."
task(:clean) { rm_f "test/coverage/coverage.data" }
%w[units functionals integration].each do |target|
# Schema:
#
# id int
# crypted_number string(255)
# ... anything else ...
class Foo < ActiveRecord::Base
attr_writer :number
before_save :encrypt_number
#===================
# routes:
map.named_filters ':category_slug/*filters'
#===================
# controller
before_filter :load_category, :only => 'show'
before_filter :apply_filters, :only => 'show'
var ZipRanges = {
ranges: {
'AK':'99500-99929',
'AL':'35000-36999',
'AR':'71600-72999,75502-75505'
// ...
},
toState: function(zip_code) {
var z = parseInt(zip_code);
var s = null;
<script type="text/javascript">
var products = [<%=
@products.map do |product|
bids_json = product.bids.map(&:amount).join(',')
"{id: #{product.id}, name:'#{product.name}', bids:[#{bids_json}]}"
end.join(',')
%>];
var bids = {<%=
@products.map do |product|
class Session < ActiveRecord::Base
end
s = Session.find_by_session_id 'INSERT-SESSION-ID-HERE'
Marshal.load(Base64.decode64(s.data))
class BaseReport
# encapsulate common functionality for gathering report parameters
def initialize(attrs={})
date_time_attributes = {}
# this is a naive implementation of recognizing rails' multipart parameters (eg for datetime selects)
# we are assuming either date / datetime, and discarding any datatype component
attrs.each do |k,v|
if k.to_s.include?("(")
class Time
def is_after?(timestamp)
self.to_i - self.at_beginning_of_day.to_i > timestamp
end
def is_after_430_pm?
# 4:30 == 16:30
# 16*3600 (sec/hr)
#+30*60 (sec/min)
#=59400
class Address < ActiveRecord::Base
belongs_to :addressable, :polymorphic => true
named_scope :default, :conditions => { :default => true }
named_scope :without, lambda{|address| { :conditions => ["id <> ?", address.to_param] }}
before_save :set_default
private
def set_default
named_scope :for_day, lambda { |date|
beginning = date.at_beginning_of_day
ending = beginning + 1.day
{ :conditions => ["placed_at BETWEEN ? AND ?", beginning.utc, ending.utc] }
}