Skip to content

Instantly share code, notes, and snippets.

View trek's full-sized avatar
🏳️‍🌈

Trek Glowacki trek

🏳️‍🌈
View GitHub Profile
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
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
class Economy
def slowing?
self.value.today < self.value.yesterday
end
def slow_by(amount)
self.value -= amount
end
end
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)
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
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
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
...
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
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])
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