ReadyBoost and iTunes: bitter enemies

Posted on July 24, 2007

Wondering why iTunes video on Windows Vista is a stuttering, unwatchable nightmare? Try this experiment:

  1. Unplug your ReadyBoost flash card.
  2. Start iTunes.
  3. Start a video.
  4. Plug in your ReadyBoost card.
  5. Wave goodbye to iTunes as it comes to a sudden and complete stop. OK, not complete; I get a framerate that’s around 30secs/frame. Yep, that’s 30 seconds per frame, not frames per second.

    That’s a pretty nasty failure mode for ReadyBoost. OTOH, I’m in general not a big fan of iTunes (terrible performance and a horrid UI), and it could easily be Apple’s fault.

installing mysql gem on ec2

Posted on July 23, 2007
You probably want:
    gem install mysql -- --with-mysql-dir=/usr/lib/mysql --with-mysql-config=/usr/bin/mysql_config
Without the options, you'll probably see:
gem install mysql
Select which gem to install for your platform (i386-linux)
 1. mysql 2.7.3 (mswin32)
 2. mysql 2.7.1 (mswin32)
 3. mysql 2.7 (ruby)
 4. mysql 2.6 (ruby)
 5. Skip this gem
 6. Cancel installation
> 3
Building native extensions.  This could take a while...
ERROR:  While executing gem ... (Gem::Installer::ExtensionBuildError)
    ERROR: Failed to build gem native extension.

ruby extconf.rb install mysql
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... yes
checking for mysql_query() in -lmysqlclient... no


Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/mysql-2.7 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/mysql-2.7/gem_make.out

Filter your stack trace to only see your code

Posted on July 21, 2007

Most of the time, I don't want to see the whole stack trace including the environment - I just want to see my code. So, I tossed this in my test:

module Test
  module Unit
    module Util
      module BacktraceFilter
        def filter_backtrace_with_only_my_code(backtrace, prefix=nil)
          result = filter_backtrace_without_only_my_code backtrace, prefix
          result.reject! {|x| x =~ /ruby.lib.ruby/}
          result.reject! {|x| x =~ /vendor.plugins.mocha/}
          result
        end
        alias_method_chain :filter_backtrace, :only_my_code
      end
    end
  end
end

You'll probably want to play around with what gets filtered in and out.

I think of this sort of thing as more of a debugger macro than actual code; it gets changed constantly depending on what I'm doing.

Ruby idioms

Posted on July 06, 2007

Exceptions, begin/rescue/else/ensure/
Did you know that your begin/rescue/else/ensure code can have an else?

Rails to_xml

Given:

puts ContactPhoneNumber.find(:all).to_xml

Rails is going to create xml that looks like:

<?xml version="1.0" encoding="UTF-8"?>
<contact-phone-numbers type="array">
  <contact-phone-number>
    <created-at type="datetime">2007-11-09T15:46:30-08:00</created-at>
    <customer-id type="integer" nil="true"></customer-id>
    <id type="integer">1</id>
    <phone-number>12065558888</phone-number>
    <updated-at type="datetime">2007-11-09T15:46:30-08:00</updated-at>
    <verified type="boolean">false</verified>
  </contact-phone-number>
</contact-phone-numbers>

Ruby on Rails IDEs: NetBeans and Aptana

Posted on July 05, 2007

Both NetBeans and Aptana (Aptana has taken over RadRails) are useful, and both have their drawbacks. I usually have both open at the same time, editing the same files.

Aptana/RadRails

  • Subversion support is much better than NetBeans.
  • The test runner system is very useful, and NetBeans doesn't have anything like it.

NetBeans:

  • subversion support on windows is poor (they depend on using external tools, and they don't work with cygwin svn)
  • better code completion
  • much better debugging
  • the NetBeans team responds to bug reports very quickly

I use NetBeans for the debugger, and Aptana when I just want debug printfs.

I don't really have much hope for anyone's code completion in Ruby for a while. Too many things are dynamic; the chances of doing full code completion without a running application are close to zero. Seems like you're going to need very tight integration between the IDE and a running process to make this work.

You want to be running the nightly (hourly, sometimes) builds for NetBeans. Today, you'd want netbeans-rubyide-hudson-2749.zip from http://deadlock.netbeans.org/hudson/job/ruby/

http://wiki.netbeans.org/wiki/view/Ruby

Standard Rails things that I always forget

Posted on July 01, 2007

Testing redirect_to :back

You need to set request.env["HTTP_REFERER"] :

back_url = 'http://test.host/last/page/visited' 
request.env["HTTP_REFERER"] = back_url
assert_redirected_to back_url

helper_method

In a controller, do this to turn a controller method into a method that you can call from a view:

def foo
  bar
end

helper_method :foo

Plurals for scaffolds and controllers

By hand:

script/generate model Foo
script/generate controller Foos

But

script/generate scaffold Foo

Builds

script/generate model Foo
script/generate controller Foos