Skip to content

Instantly share code, notes, and snippets.

@quirkey
quirkey / gist:1247
Created July 22, 2008 20:02 — forked from mrb/gist:1245
module ApplicationHelper
def e_tag(model)
eval("link_to image_tag(\'pencil.png\'), edit_#{model.class.name.underscore}_path(model)")
end
def d_tag(model)
eval("link_to image_tag(\'delete.png\'), model, :confirm => \'Are you sure?\', :method => :delete")
end
module DeepHash
def deep_value(key_array)
value = self
Array(key_array).each do |key|
value = value.fetch(key, nil)
end
value
rescue NoMethodError
nil
module ActionMailer
class Base
class_inheritable_accessor :view_paths
def self.prepend_view_path(path)
view_paths.unshift(*path)
ActionView::TemplateFinder.process_view_paths(path)
end
def self.append_view_path(path)
# example <a onclick="popup('http://gooogle.com','Google',400,300);">Popup</a>
function popup(link,title,width,height) {
return window.open(link,title,"height="+height+",width="+width+",status=no,toolbar=no,menubar=no,location=no");
}
[10:29 AM:n41(master)] $ ./script/console
Loading development environment (Rails 2.1.1)
>> m1, m2 = Money.new(200), Money.new(200)
=> [#<Money:0x32165f8 @currency="USD", @cents=200>, #<Money:0x32165e4 @currency="USD", @cents=200>]
>> m2.eql?(m1)
=> true
>> m1.eql?(m2)
=> true
>> m1 == m2
=> true
@quirkey
quirkey / gist:16142
Created October 10, 2008 19:47 — forked from mrb/gist:16141
TherapistReport.send(:with_exclusive_scope) {
@last_tr = TherapistReport.find(:all, :conditions => ["report_id = ? AND therapist_id = ? AND report.territory_id = ? ", self.report.previous, self.therapist_id, self.report.territory_id], :include => [:report])
}
class TrueClass
def to_s
"so fucking true"
end
end
def truncate_words(text, length = 30, truncate_string = "..." )
return if text.nil?
words = text.split
words.length > length ? words[0...length].join(" ") + truncate_string : text
end
desc "Download a tarball from Github and extract to a shared dir then symlink to vendor/rails"
task :deploy_edge do
puts "Pulling Rails from github"
shared = ENV['SHARED_PATH'] || File.join('..','..','shared')
shared_path = File.expand_path(shared)
puts "Shared Path: #{shared_path}"
rails_path = File.join(shared_path, 'rails')
rails_version = ENV['VERSION'] || ENV['REVISION'] || 'v2.1.0'
export_path = File.join(rails_path, "rails_#{rails_version}")
export PS1='\[\e[36;1m\][\@:\[\e[32;1m\]\W\[\e[33;1m\]$(__git_ps1 "(%s)")\[\e[32;1m\]] \[\e[0m\]$ '
# Color Code
# Black 0;30
# Blue 0;34
# Green 0;32
# Cyan 0;36
# Red 0;31
# Purple 0;35
# Brown 0;33