I have abandoned this blog in favor of my new homepage http://jankubr.com. I’ll keep the content here but only under the http://onruby.wordpress.com URL. If you want to keep up to date with what’s going on with me, follow me on Twitter where all the fun has moved these days. I’m at @jankubr. You can also follow me on Github to see what’s new in my lab.

If you have two Net::SFTP::Exceptions in one process, the error messages get concatenated. This is probably because the message method of RuntimError (or of something above) returns something static which gets reset only in the initialize method:

class MyError < RuntimeError
  def initialize(response)
    @response = response
  end

  def message
    m = super
    m << @response
  end
end

2.times do
  begin
    raise MyError.new('error')
  rescue RuntimeError => e
    puts e.message
  end
end

Which outputs:
MyErrorerror
MyErrorerrorerror

If you call super from the initialize method or change the last line in the message method to “m + @response” the outputs are more as expected:
MyErrorerror
MyErrorerror

errorerror
errorerror

Since Timeout::Error is not a subclass of StandardError, you’ll need to do something like this to catch the exception:

  rescue StandardError, Timeout::Error => e

Not too much fun, but it certainly didn’t make me as angry as the guy I linked to above ;-)

Another Merb breakage after upgrading. Thanks to some Japanese guy I figured how to solve this one. You’ll need the addressable gem in version 1.0.4 and to add this to your dependecies.rb:

dependency "addressable", '1.0.4', :require_as => 'uri'

before the dm-core dependency.

See this pastie; I just ran into this issue. Good I knew about the problem already from worrying but interesting David Majda’s presentation.

I think one of the greatest contributions of the Merb guys is spreading the message that Ruby is not slow. Even Rails is faster than most mainstream PHP frameworks. Wow.

(I looked up the research they refer to to see if they don’t cheat by comparing Rails and Merb to CakePHP. They don’t, it is the fastest PHP framework from the sample group.

[UPDATE: Nope, was wrong; please read the comments.])

Not caring about warnings is bad. Broken windows do matter. Here’s how to avoid this one:

 warning: already initialized constant C

Simply define the constant only if not yet defined:

C = 'value' unless defined?(C)

Duck typing is like sharp knives: You do need protect yourself. If you don’t, you end up with this:

function propagate_artist(element) {
    element = $(element);

instead of this:

function propagate_artist(element_id) {
    element = $(element_id);

Too subtle for you? Can I please not work with you then?

You might have the same problem I had with using daemonize (might be with anything else, too): File.dirname(__FILE__) doesn’t work after right daemonizing.

Although I haven’t been able to catch the exception message or whatever info, I’m almost sure the problem is that daemonize does a Dir.chdir “/”. Try run this script from a file in any directory and it will always print “/”:

Dir.chdir "/"
puts File.expand_path(File.dirname(__FILE__))

Anyway, save the path to the directory before daemonizing and you’ll be fine.

Our PBX/IVR web-based generator Telfa has been moved from Asterisk to Freeswitch. Why?

Asterisk just seems to come from a different world than what I am used to. Inflexible and problematic. Very long configuration files with ancient syntax. Now I’m far from pretending I’ve used Asterisk enough to understand it pros and cons well, but I have a decent software development experience and I can tell when something “smells.” I didn’t want to build our system (that I want to be flexible and scale well) on some old technology that is only living from its past.

And (most importantly) there are many people experienced with both Asterisk and Freeswitch favoring the latter: Anders Brownworth, Jonathan Palley (creator of Telegraph, a Rails plugin that lets you talk to Freeswitch), or of course the creator of Freeswitch (and former Asterisk developer!) Anthony Minessale himself.