This file contains 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
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 | |
This file contains 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
#!/usr/bin/env ruby | |
require 'json' | |
require 'descriptive_statistics' | |
def print_data_summary(key_name, data) | |
puts "-----------------------------------------------------------" | |
puts "-- #{key_name} --" | |
puts "Data Points:\t\t#{data.length}" | |
puts "Mean:\t\t#{data.mean}" | |
puts "Median:\t\t#{data.median}" |
This file contains 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
# pid = pid of running ruby process | |
tracer = RBTracer.new(pid) | |
output = tracer.eval("StackProf.start") | |
puts output #=> "<StackProf ....>" |
This file contains 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
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 |
This file contains 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
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) |
This file contains 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
# 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"); | |
} |
This file contains 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
[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 |
This file contains 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
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]) | |
} |
This file contains 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 TrueClass | |
def to_s | |
"so fucking true" | |
end | |
end |
This file contains 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 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 |
OlderNewer