Assorted Good Stuff 12 comments

posted Wednesday, October 4, 2006 by topfunky

Here are a few things I’ve been hoping to blog about, all wrapped up into a single post!

Francis Hwang

The lecture last week went quite well. I learned many things about Ruby metaprogramming and how Rails loads classes when they are used, not before. Here’s the raw audio:

Francis Hwang Lecture, Raw and Uncut

Download slides for the lecture

Benchmark your tests

A project I’m working for has a big test suite that was taking a long time to run. It turns out that there were a lot of tests that fetched RSS feeds instead of using RSS fixtures. I figured this out by writing a little hack to print a report of each test and how long it takes to run.

# Sample Test Benchmark Output
0.072 test_should_not_rehash_password(UserTest)
1.033 test_to_param(EpisodeTest)
2.108 test_permalink(EpisodeTest)
4.289 test_to_rss(ProgramTest)

I’m working on a plugin for this. In the meantime, you can paste this snippet to the bottom of test/test_helper.rb:

# EXPERIMENTAL
# Show a report of the time each test takes to run
class Test::Unit::TestSuite

  @@test_benchmarks = {}

  # Runs the tests and/or suites contained in this
  # TestSuite.
  def run(result, &progress_block)
    yield(STARTED, name)
    @tests.each do |test|
      start_single_test = Time.now
      test.run(result, &progress_block)
      @@test_benchmarks[test.name] = Time.now - start_single_test
    end
    yield(FINISHED, name)

    puts "\nTEST BENCHMARK REPORT" 
    @@test_benchmarks.keys.sort{|a, b| @@test_benchmarks[a] <=> @@test_benchmarks[b]}.each do |key|
      value = @@test_benchmarks[key]
      puts(("%0.3f" % value) + " #{key}") if /^test_/.match(key)
    end
  end

end

Data backup to YAML

Scott Laird wrote a task that backs up your database to YAML. I extracted it so I can drop it into lib/tasks for any Rails app and do rake db:backup. It chokes on large amounts of data or UTF8, but works in some situations.

YAML Backup Rake Task

Rimuhosting VPS

After sharing a server with Cork’d for a few months, I’ve moved Rough Underbelly and PeepCode to the same VPS that runs this blog. I’m getting a crazy good deal from Rimuhosting. While I still use Dreamhost for email, large file hosting, and Subversion, Rimuhosting has been super reliable and has affordable prices.

Lighttpd Notes

While setting up lighttpd to serve all three sites with virtual hosts, I was getting weird errors where the site would be served, but fastcgi was not starting up properly. It would just serve the dispatch.fcgi file as text instead of executing it.

The problem turned out to be:

  1. My $HTTP['host'] sections were incorrect. Because I only have a few sites running on that server, I fixed it by making them super generic: $HTTP['host'] =~ 'peepcode', etc.
  2. All my sites were defined in virtual host sections, so the domains that failed to match fell back to the default setup, which did not have a fastcgi server defined. Hence the delivery of dispatch.fcgi as a plain text file.

I’m using Apache2+Mongrel for other sites, but this setup works very well for me on my VPS and I’ve had months of uptime with no problems.

REST

I’ve been studying the new REST features in the Rails trunk for the last few weeks. I am preparing a PeepCode screencast and a free cheat sheet that will be published later this week. The existing documentation is slim and some of the concepts are a bit confusing.

What problems have you had when trying to understand how RESTful routes work in Rails? Send email to boss@topfunky.com and I’ll try to answer it.

Ruby_on_rails_workshop
12 comments

Leave a response

  • I recently completed a painful migration away from DreamHost. DH’s DNS manager created conflicting records and failed to allow me to correct them; they also failed to authorize a transfer of my domain away from them without providing reasons why. The final straw was when my email server went down for nearly a whole week. DreamHost support didn’t respond until after I had successfully moved my work email account to GMail for my domain.

    www.jvoorhis.com is now hosted on a Rimuhosting VPS and I couldn’t be happier with their service and support. GMail for domains has also been nothing but great – I’m still waiting for the catch.

    Cheers!

  • The test benchmarking stuff you’ve got there is seriously great – the only suggestion I’d make would be to reset the @@test_benchmarks hash during the run so that rather than accumulating results through the test run, it only outputs each test once. That way grepping on ‘(’ and piping through sort gets a full list without the duplicates.

    Not so much an issue on singular test runs, but the rails split between units/functionals makes it more difficult than necessary to get a single, unified list. (though I suppose I could just pipe my results through uniq after sort, but meh)

  • Gravatar icon topfunky

    I should also mention that running the full test suite with autotest gives you a single report on all your unit and functional tests, with the slowest ones at the bottom.

  • I’ve been enjoying the peep code videos, keep up the good work.

    I’m really looking forward to your REST/CRUD cheatsheet and the peepcode video. I finally dove into it last week at the Pragmatic Programmer’s Advanced Rails Studio, good stuff.

    FYI, the best way I’ve found to understand the REST stuff is to dive into Rick Olson & Josh Goebel’s Beast Forum source code. Details here: http://beast.caboo.se/forums/1/topics/381

  • I desperately want to use that backup script… I’m tired of MySQL and want to convert everything to pg.

    Problem is, since it creates models for everything, when importing join tables into pg it tries to update the sequence. Of course join tables don’t have sequences, so it dies.

    The rails-app-installer gem has the same problem, I was hoping that this version would be different… no dice :( I’m trying to figure out a solution, but so far without much luck.

  • Oh, also, thanks for posting Francis’ lecture. I was really sad that I didn’t get to come up for it.

  • Well, I fixed the problem with the sequences… now there’s another problem: it doesn’t work with STI tables.

    I’m increasingly of the mind that the proper solution here is to use raw SQL for the insert side of things. Might not be very robust, but it’d actually work.

  • I’ve added your test duration logging to my new HTML test reporter for Rails

  • A PeepCode on REST? Brilliant, this could not be more timely for me. Thank you so much!

  • Gravatar icon Alex

    I’m so excited about the next PeepCode.

    I’ve been putting off my first Ruby / Rails application – thinking that if I’m going to take the plunge I want to do it properly.

    My deadline’s Monday so I figure I can learn from PeepCode then, since Ruby / Rails is supposed to make me so much more productive, crank out what I need in two days.

    I just hope that PeepCode’s release at the end of this week doesn’t mean Sunday evening – then i’m in trouble :)

  • Gravatar icon topfunky

    I’m putting the finishing touches on it right now. Look for it by the end of today.

  • Gravatar icon Hydro

    Come on guys … regarding Francis Hwang’s slideshow about the api which has been made available here as a PDF, have we NOT learned anything (ahem Geoffrey) from Dr. Edward Tufte abut the overwhelming negatives of the “PowerPoint Pitch” culture? PowerPoint pitches go complete against Tufte’s Grand Principles (especially the Grand Principle regarding spatial adjacency). If Francis Hwang is providing a “serious presentation”, then how about some leadership which steps up to the plate and starts a culture change more in line with Tufte’s Grand Principles which are hard to argue against?

    -Hydro

Your Comment

Nuby on Rails

Geoffrey Grosenbach / Ruby / Code / Graphics / Design / Rails / Merb / Javascript / CSS

Manufactured with

Subscribe

Subscribe (RSS)