This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Schema: | |
| # | |
| # id int | |
| # crypted_number string(255) | |
| # ... anything else ... | |
| class Foo < ActiveRecord::Base | |
| attr_writer :number | |
| before_save :encrypt_number | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #=================== | |
| # routes: | |
| map.named_filters ':category_slug/*filters' | |
| #=================== | |
| # controller | |
| before_filter :load_category, :only => 'show' | |
| before_filter :apply_filters, :only => 'show' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <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| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Session < ActiveRecord::Base | |
| end | |
| s = Session.find_by_session_id 'INSERT-SESSION-ID-HERE' | |
| Marshal.load(Base64.decode64(s.data)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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?("(") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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] } | |
| } |
OlderNewer