Airlines and rand()

Ilenia and I are looking for tickets to go “home” (Eugene, Oregon) this summer. We’ve had pretty good luck with Lufthansa in the past (as opposed to Air France, which lost a huge bag of my stuff), so we turned to them first to look for flights. I like the page they have for prices/dates, which gives you a nice way to look around for a better price without stabbing randomly at dates:

Big long Lufthansa URL

However, the maddening thing is that the prices change frequently. Not every day, but often after even 5 minutes! They bounce around up to 100 euro at a time. I understand the theory behind price descrimination, but this is the classic case where the customer ends up feeling like they’re being made fun of and goes elsewhere. United, in our case, which offers a cheaper price for the same plane (they’re Lufthansa’s partner and thus share flights).

ShopList updates

I did some work on my mobile phone shopping list ShopList today.

Thanks to a bug report from Sven Mueller, I think I managed to correct an encoding issue. If you use ShopList and enter non-ascii text into the shoplist web application, let me know if things are working for you.

I also did some work on the back end to enable statistics, but only for users who are logged in to their accounts. Not surprisingly, the most common things people buy at the store are:

  • Milk
  • Bread
  • Butter
  • Cheese
  • Eggs

Which probably hasn’t changed in hundreds of years. Sort of reassuring, I guess?

Domain names vs real estate

I was reading some of the debate regarding this guy and his business:

The man who owns the Internet

and got to thinking about the comparison between domain names and real estate. One of the things that irritates me about domain name squatters is that they can essentially sit on a good name forever, at very, very little cost. You can’t do that in real estate, because you have to pay property taxes, which acts as an incentive to actually do something productive with the property, rather than simply let it sit there until someone comes and offers to buy it from you for even more than you paid. So you can’t let the space go completely to waste – you have a big incentive to at the very least rent it out to someone who can make money with it. You can’t really rent out a domain name, though. Since it’s an integral part of your brand and identity, it would be insane to borrow one for a few years, whereas with a physical business renting space, people will still be able to find you if you move.

Perhaps an annual tax based on the purchase price of domain names would encourage people to either do something valuable with them or pass them on to someone who could? I don’t think anyone would be sad to see pure speculators gone, but on the other hand, I have a strong suspicion that all the extra taxes and red tape would make the idea a net negative, and taxes on ‘real’ domains like google or ebay, would simply be passed on to consumers, and so wouldn’t be desireable.

In any case, it’s something interesting to think about.

mailmodel rails plugin

Here is the first cut at a plugin I created, called Mailmodel. It’s pretty simple, you install it, configure the email sender/destination addresses, and then, in your ActiveRecord objects:

after_save :mail_model

For those objects that you want to be notified of when they change. Think of it as ‘scaffolding’ for email notification of changes in your database (new comments, new users, new payments) when you aren’t quite ready to set up notification for each individual thing.

Available from:

http://svn.dedasys.com/public/mailmodel/

Some improvements that could be made:

  • Customize behavior for some objects: if it’s a this, then include that and that in the object dump.

  • Customized templates depending on object type in order to take the scaffoling analogy further.

Pretty Print Active Record

I wanted to be able to pretty print ActiveRecord objects, and do so in a way that’s a little bit more involved than what pp gives you:

module ActiveRecordPrettyPrint

  def pprint(ar, maxdepth=1)
    pp_helper(ar, "", 0, [], maxdepth - 1)
  end

  private
  def pp_helper(ar, buf, level, seen, maxdepth)
    if level > maxdepth || seen.member?(ar)
      buf << (" " * level) + "#{ar}n"
      return buf
    end

    seen << ar

    reflections = ar.class.reflections
    rcolumns = reflections.collect { |k, v| v.primary_key_name }

    buf << "#{ar.class}:n"
    ar.attributes.keys.reject { |k| rcolumns.member? k }.each do |k|
      buf << (" " * level) + "#{k}  =>  " + ar.send(k).to_s + "n"
    end

    reflections.keys.each do |k|

      buf << (" " * level) + k.to_s + " =>  "
      res = ar.send(k)
      if res.nil?
        buf << "[nil]n"
      elsif res.class == Array
        res.each do |o|
          pp_helper(o, buf, level + 1, seen, maxdepth)
        end
      else
        pp_helper(res, buf, level + 1, seen, maxdepth)
        buf << "n"
      end
    end

    return buf
  end

end

I suspect I’ll fix it up more as I go along, but this is the basic idea… Be careful with maxdepth, though, or else you risk hitting the database too much.

Rails ExceptionNotifier plugin

I’m irritated with myself that I hadn’t found this before. If you aren’t using it now on your rails sites, you need to install it right away:

http://agilewebdevelopment.com/plugins/exception_notifier

Indeed, if it were up to me, I would include it as part of the standard distribution. It’s small, quick to set up, and a huge help in tracking down and eliminating problems.

JavaFX

I’m not convinced.

It looks to me like they’re aiming at something a bit more dynamic/higher level than Java, in more or less the space that Javascript, Ruby and Python operate in.

The declarative GUI stuff looks pretty good, but I don’t know if the rest will make that worth it.

The language itself seems neither here nor there. It’s a lot like Javascript – but not quite. It doesn’t have real hash tables, something I don’t care for in JS, and I didn’t see an eval() method in the documentation, which means that their aim is to make something that you compile, and that doesn’t carry around an interpreter with it like most dynamic languages with eval have to.

I wonder what kind of support it will get from Sun and the open source community? Will the internal Java group view this as some sort of competitor? I wonder what sort of discussions went on during the creation of this system at Sun. They can’t have take the decision to make a new, incompatible language very lightly.

A new language has to have a killer app to drive acceptance, and I don’t quite see one for this. The FAQ sheds some light on where they’d like to go:

Why did you create another scripting language?

JavaFX Script is specifically designed to optimize the creative process of building rich and compelling UIs leveraging Java Swing, Java 2D and Java 3D for developers and content authors.

Why isn’t Groovy enough?

Groovy and other languages have two specific traits which don’t precisely meet these needs, namely that they are generic in nature and don’t provide the appropriate abstractions necessary to optimize the UI design process and similarly are designed specifically for programmers other than content authors.

So it does look like they’re aiming for a language that makes it easy to quickly create GUI’s for people who perhaps aren’t expert enough (or patient enough) to deal with Java itself. Pity they didn’t just stick with Tcl and Tk, which have had a more or less declarative syntax for specifying layout for something like 10 years, and in any case have a flexible enough syntax to “run DSL circles” around most languages that are currently popular.

As the author of Hecl, I’m particularly curious about their mobile strategy. If I may be permitted a bit of hubris, it’s nice that they see things my way, that mobile apps need a good scripting language in order to make them more accessible to the masses, but it wasn’t too hard to see that coming, with the ever increasing capabilities of higher end phones, and the “scaling down” that scripting languages bring to programming (making it easier for people to get started even if they aren’t experts).

I wonder what sort of diffusion they’ll get with their phone system, and how fast, and how easy it will actually be to program the phones. For many people it’s probably not as important, but by creating a real interpreter, rather than something that’s compiled and doesn’t have an eval function, Hecl lets you download and execute code, which makes for some very interesting possibilities (as well as some risks, of course). That’s probably not important though, if they can actually make a system that’s widely used, and easier to create applications for than J2ME currently is. I wonder if they’ll allow J2ME on the phone platform, or close that down in favor of JavaFX?

Even for Big Companies, launching a new language is a difficult endeavour[1], and it will be a number of years before we see where this ends up, but I’m not convinced.

[1]
The Economics of Programming Languages

Rails bitten by Ruby’s nil.to_f

I guess I’m still new enough to Ruby that this does not make sense to me:

>> nil.to_f
=> 0.0

Magically, from nothing, you have something. I suppose it might be convenient in places, but today I ran into a minor bug in Rails that causes problems when trying to get the average of a column that doesn’t have any entries.

So what is the reasoning behind nil.to_f being 0.0 (and nil.to_i being 0, to_s being “”), anyway?

Permission denied to get property Object.constructor

I struggled a little bit to figure out what was going on with the Prototype javascript library in terms of this error I was getting in my application, rather cryptically reported as:

[Exception... "'Permission denied to get property 
Object.constructor' when calling method:
[nsIDOMEventListener::handleEvent]" nsresult: "0x8057001e
(NS_ERROR_XPC_JS_THREW_STRING)" location: "<unknown>" data: no]

I was setting up an observer to make some async requests when a checkbox is set or unset. Setting the checkbox to true worked just fine, but unsetting it seems to cause the above exception. It turns out the fix is pretty simple. Instead of this:

<%= observe_field('blah_yes', :url =>
                  {:action => 'set_blah', :id => @someobj.id},
                  :update => 'blahmessages') %>

I made sure to use a :with parameter:

<%= observe_field('blah_yes', :url =>
                  {:action => 'set_blah', :id => @someobj.id},
                  :update => 'blahmessages', :with => 'yes') %>

My guess as to what’s occuring comes from the parameters passed into my controller. Before the modification:

{"action"=>"set_blah", "id"=>"4", "1"=>"", "controller"=>"xyz"}

That “1” is being passed as the variable name, rather than its value… After adding the with, the parameters come in like so when it’s being set:

{"action"=>"set_blah", "id"=>"4", "controller"=>"xyz", "yeah"=>"1"}

And like so when it isn’t… aha!

 {"action"=>"set_blah", "id"=>"4", "controller"=>"xyz", "yeah"=>"null"}

I bet that null is what was causing problems.

I thought I’d publish it so that an answer is available for those searching with google, as I wasn’t able to find one.

Perhaps the Prototype library should be a little bit more careful with its data somewhere in order to fail more gracefully, but I’m not sure where one would go about looking.

Google Apps + Domain Registration

I’m impressed. Via Google Apps, I was able to register a domain (squeezedbooks.com – nothing there yet, though) for $10. But it’s not just a domain, it comes with email, google calendar, and a bunch of the other google apps thrown in for free.

That’s a lot of stuff for ten bucks – especially for the large portions of the world where the currencies are appreciating against the dollar.

The service does have some drawbacks though.

  • It doesn’t do .it domains, something that I would find handy. For that matter, it only seems to offer .com, .net, .org, .info or .biz, which is sort of limited. I guess I don’t blame them for not wanting to take on the Italian domain registry and its stupid, bureaurocratic rules, but having some other TLD’s there would be nice.

  • It relies on another site for DNS fiddling. Google partnered with enom.com for their registration service, and one notices the difference between the nice, clean google interfaces, and the enom app when you get shunted off there to make DNS changes. The app isn’t even that bad, it would just be nicer if it weren’t necessary to log on to something external.

  • The amount of power that google is ammassing is scary in some ways. I have happily used gandi.net for a number of years, and would have continued, but 14 Euro vs 10 Dollars + the apps is simply not a contest.