Skip to content

Instantly share code, notes, and snippets.

View jesscanady's full-sized avatar

Jessica Canady jesscanady

View GitHub Profile
for f in *; do mv $f ${f/erb/haml}; done
def google_font_link_tag(family)
tag('link', {:rel => :stylesheet, :type => Mime::CSS, :href => "http://fonts.googleapis.com/css?family=#{family}"}, false, false)
end
@jesscanady
jesscanady / author_delegate.rb
Created November 4, 2010 14:39
Example of the delegate method
class Authorship < ActiveRecord::Base
belongs_to :author
belongs_to :book
delegate :full_name, :to => :author
end
# > @authorship.full_name now calls @authorship.author.full_name
class Things < ActiveRecord::Base
def massive_calculation
@massive_calc_results ||= self.execute_massive_sql
end
end
[ODBC Data Sources]
dsn_name = tds
[ODBC]
Trace = 1
TraceAutoStop = 0
TraceFile = /Users/whatever/Desktop/odbc.log
TraceLibrary =
[dsn_name]
# encoding: utf-8
#
# column_box.rb: Extends BoundingBox to allow for columns of text
#
# Author Paul Ostazeski.
require "prawn/document/bounding_box"
module Prawn
class Document
@jesscanady
jesscanady / gist:1278850
Created October 11, 2011 17:58
Completely untested legacy bitfield-based role system fixer.
alias_attribute :administrator :IsAdministrator
alias_attribute :consumer :IsConsumer
# etc...
# now you can do checks like:
if @user.administrator?
# and if you need .role:
@jesscanady
jesscanady / test.rake
Created October 11, 2011 21:16
Running "rake" doesn't clobber your testing db anymore!
# Rails.root/lib/tasks/test.rake
Rake.application.remove_task 'db:test:prepare'
namespace :db do
namespace :test do
task :set_env do
end
task :prepare => [:set_env, :environment] do |t|
@jesscanady
jesscanady / exception_test.rb
Created January 18, 2012 19:35
Custom errors that extend "Exception" don't get caught by bare rescue statements.
#
# Custom error classes that extend Exception don't get caught by catch-all/bare rescue statements.
#
class ExtendsStandardError < StandardError; end
class ExtendsException < Exception; end
begin
raise ExtendsStandardError, "Burn."
@jesscanady
jesscanady / gist:2228179
Created March 28, 2012 16:57
Deep in the debugger...
[97, 106] in /Users/jonc/code/innova/renewadvantage/vendor/ruby/1.9.1/gems/actionpack-3.2.1/lib/abstract_controller/rendering.rb
97 end
98
99 # Raw rendering of a template to a Rack-compatible body.
100 # :api: plugin
101 def render_to_body(options = {})
=> 102 _process_options(options)
103 _render_template(options)
104 end
105