🏳️🌈
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
| def show | |
| @note = Note.find(:where => 'id = 1') | |
| rescue NotFound | |
| redirect_to 'not_found', :status => 404 | |
| rescue NoDatabase | |
| logger.error('the db died again, shit') | |
| redirect_to 'apology', :status => 500 | |
| end |
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
| def show | |
| @note = Note.find(:where => 'id = 1') | |
| rescue NotFound | |
| redirect_to 'not_found', :status => 404 | |
| rescue NoDatabase | |
| logger.error('the db died again, shit') | |
| redirect_to 'apology', :status => 500 | |
| end |
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 Economy | |
| def slowing? | |
| self.value.today < self.value.yesterday | |
| end | |
| def slow_by(amount) | |
| self.value -= amount | |
| end | |
| end | |
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 Foo(object): | |
| def __init__(self,arg): | |
| """docstring for __init__""" | |
| self.arg = arg | |
| def dec(fn): | |
| def wrapper(*args): | |
| # args[0] is self. Lame | |
| args[0].arg = 'not what you thought, huh?' | |
| return fn(*args) |
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 Thingie | |
| attr_accessor :element | |
| def initialize(element) | |
| self.element = Element.new(element) | |
| # with a block | |
| self.element.respond_to :click do | |
| self.element.hide | |
| ... other stuff ... | |
| end |
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 PhotoBox | |
| attr_accessor :element, :images | |
| def initialize(element) | |
| # associate an element with this object | |
| self.element = Element.new(element) | |
| # give it a class | |
| self.element.add_class('active') | |
| # find subelemts and store them |
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
| Customer < ActiveRecord::Base | |
| before_destroy :log_deletion, :email_admin | |
| private | |
| def log_deletion | |
| logger.info("customer id:#{self.id} was just deleted") | |
| end | |
| def email_admin | |
| ... |
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 Conference | |
| has_many :attendees, :class_name => 'Person', :through => :attendance | |
| def Conference.next_upcoming | |
| self.find!(:first, :conditions => ['starting_at > ? and visibile = ?' Time.now, true]) | |
| rescue RecordNotFound | |
| self.most_recent | |
| end | |
| def most_recent |
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
| def search(v,a) | |
| return if a.empty? | |
| if a.pop == v | |
| return search(v,a) + 1 rescue 1 | |
| else | |
| return search(v,a) + 0 rescue 0 | |
| end | |
| end | |
| search(1,[1,2,3,4,3,4,4,4,1,1,4]) |
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
| require 'redshift' | |
| class PhotoBucket | |
| def initialize(element) | |
| @element = element | |
| @req = Request.new | |
| @req.upon(:request) { self.show_loader } | |
| @req.upon(:success) { self.hide_loader } | |
| @req.upon(:response) { self.load_photos } | |
| self.load_initial_photos |