Upgrading Ubuntu to 8.04 (Hardy Heron). Ugh.

Some minor problems:

  • /etc/default/locale has been deleted (wtf?). Needed to be recreated.
  • Both /etc/timezone and /etc/localtime have been deleted. Needed to recreate the links.
  • /etc/updatedb.conf has been deleted. Needed to be copied from another machine.

and one major one:

  • klogd now takes 5 minutes to start, which means I have to wait 5 minutes after each reboot to use the machine. Adding -x switch in the init.d script solved the problem. What was the root cause? No idea. There are only hints.

Apparently there is some reasoning behind not upgrading your linux policy.

On being tired

And deploying code which let anyone using any login and password (and by any I mean really any combination, even asdf/asdf worked) authenticate. And have access to the administration panel. No fun. At least at first, when I shook my head with disbelief over the deployed code. How could I not check it… How could I not write even the simplest unit test… Quick fix and few minutes later the site was fixed. After that I’ve simply burst in laughter over my stupidity.

Thankfully hardly anyone ever tries to login to this particular site (login page has both no-index and no-follow so it does not attract google scripters) so despite the fact that this bug has been live for a little over 12 hours no one broke in.

Rails helpers. Rediscovered

Normally, you’d use partials to manage some common functionality in a single file. For example like this:

Somewhere in your view:

<%= render :partial => 'ads/ad', :locals => {:placement => 'frontpage-banner1'} %>

It’s quite concise, but how about making it even less verbose? Helpers to the rescue:

module AdsHelper
  def ad(placement)
    render :partial => 'ads/ad', :locals => {:placement => placement}
  end
end

And now you can write this in your view:

<%= ad 'frontpage-banner1' %>

Nice! I believe it’s as short as it gets. Sure, if you render this partial only a few times it might not be worth it, but what if you render it 20 or 30 times?

content_tag FTW!

About those one-liners… How about turning this:

<% if logged_in? %>
  <p><%= link_to 'Edit', document_edit_path(@document) %></p>
<% end %>

into this:

<%= content_tag 'p', link_to('Edit', document_edit_path(@document)) if logged_in? %>

I don’t know about you, but to say that I’m impressed would be not enough. Available from Rails 2.0 upwards.

Steve Yegge. Again

Steve Yegge (emphasis added):

So how do you make yourself a superstar? Never stop learning. I’ve heard people say they think this position is a crock, that it’s ludicrous, that you couldn’t possibly spend your whole career learning new things.

But I think differently. I think every program you write should be the hardest you’ve ever written. And that’s what I blog about, mostly. Improving yourself.

It got me thinking today and the more I think about it the more sense it makes. I would go even further with this and say that writing not just hard programs but simply more complicated code is good for you. Not obfuscated nor unreadable but code which is just a bit harder to understand. What I mean is using new constructs, new methodologies, shorter one-liners (but not those super-obfuscated Perl ones), etc.

There are lots of people who will tell you that you should write the simplest code possible (even despite the obvious bloat) because this results in a more maintainable application. This is of course true, but should the maintainability be the ultimate goal? I think that self-improvement should be a higher placed goal. And I think that you self-improve by writing code you need more time to comprehend because the harder code you write now and the more time you spend understanding it in the future the less complicated it becomes. Over time. And that is progress. That is self-improvement. Plus, as a side effect of this, your code is usually more concise.

Now going back to refactoring one of my projects