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
@quirkey
quirkey / json_log_stats.rb
Last active August 29, 2015 14:08
JSON log stats
#!/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}"
@quirkey
quirkey / rbtrace.rb
Created April 17, 2015 03:17
rbtrace
# pid = pid of running ruby process
tracer = RBTracer.new(pid)
output = tracer.eval("StackProf.start")
puts output #=> "<StackProf ....>"
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