Posted: June 20th, 2008 | Author: Daniel Higginbotham | Filed under: Literature | No Comments »
“There’s some way to stop this. It’s not like lightning or earthquakes. We’ve got a bad thing made by men, and by God that’s something we can change.”
From The Grapes of Wrath.
Soon I’ll be writing a post on what The Grapes of Wrath and the short story Everything That Rises Must Converge (by Flannery O’Connor) reveal about racism and identity.
Posted: June 6th, 2008 | Author: Daniel Higginbotham | Filed under: Books | No Comments »
I just began reading Actionable Web Analytics: Using Data To Make Smart Business Decisions and one of the first paragraphs reads: Read the rest of this entry »
Posted: June 2nd, 2008 | Author: Daniel Higginbotham | Filed under: Programming, Rails | No Comments »
This is meant to save me from having to write the same boilerplate profiling code over and over.
By default, it creates an HTML graph and saves it to RAILS_ROOT/ruby-prof/profile.html .
The method url_path is a convenience method for saving your HTML graph to a location based on the URL used.
To use, add the below to lib , then add “around_filter RubyProfHelper” to whatever controllers you want to profile. Then go to the URL you want to profile and add profile=true to the query string. You should probably ensure that this can’t be run by any schmoe in production. Also, you’ll probably want to have your SCM ignore the ruby-prof directory.
If you want to get more fine grained with your filter, use the following:
RubyProfHelper.run("output_file_name.html") do
code_to_profile(here)
end
When you visit the corresponding URL, *leave out* profile=true
from the query string.
This arguably needs to be a plugin, but I find it more
straightforward as a /lib addition.
class RubyProfHelper
class <<self
def filter(controller, &block)
return (yield block) unless controller.params[:profile]
# Instead of "profile.html" you can try url_path(controller),
# which will return a file path based on the url visited
run("profile.html", &block)
end
def run(output_file_name = "profile.html", &block)
require 'ruby-prof'
RubyProf.start
yield block
result = RubyProf.stop
printer = RubyProf::GraphHtmlPrinter.new(result)
# create directory
dir = File.join(RAILS_ROOT, "ruby-prof")
FileUtils.mkdir_p dir
file_path = File.join(dir, output_file_name)
f = File.open(file_path, "w+")
printer.print(f)
end
# will evaluate to home.html or something like
# products.html
# products/2.html
def url_path(controller)
if controller.request.path =~ /\/$|^$/
"home.html"
else
controller.request.path + ".html"
end
end
end
end