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

Mongrel_cluster not starting after hard reboot

Does the following error sound familiar?

** !!! PID file log/mongrel.pid already exists.  Mongrel could be running already.  Check your log/mongrel.log for errors.
** !!! Exiting with error.  You must stop mongrel and clear the .pid before I'll attempt a start.

It usually happens when the server crashes. After that you need to ssh into it, remove the mongrel pid files and start the cluster manually. No more.

I assume you have mongrel_cluster setup properly, ie: project’s config file is in /etc/mongrel_cluster and the mongrel_cluster script has been copied from:
/usr/lib/ruby/gems/1.8/gems/mongrel_cluster-*/resources/
to the /etc/init.d directory. You need to edit the /etc/init.d/mongrel_cluster file:

Change this two bits:

start)
  # Create pid directory
  mkdir -p $PID_DIR
  chown $USER:$USER $PID_DIR

  mongrel_cluster_ctl start -c $CONF_DIR
  RETVAL=$?
;;

and

restart)
  mongrel_cluster_ctl restart -c $CONF_DIR
  RETVAL=$?
;;

to

start)
  # Create pid directory
  mkdir -p $PID_DIR
  chown $USER:$USER $PID_DIR

  mongrel_cluster_ctl start --clean -c $CONF_DIR
  RETVAL=$?
;;

and

restart)
  mongrel_cluster_ctl restart --clean -c $CONF_DIR
  RETVAL=$?
;;

respectively.

Adding the --clean option makes the mongrel_cluster_ctl script first check whether mongrel_rails processes are running and if not, checks for existing pid files and deletes them before proceeding.

You must be using the mongrel_cluster version 1.0.5+ for it to work as advertised (previous versions were buggy). To upgrade do:

gem install mongrel_cluster
gem cleanup mongrel_cluster

Here’s the related mongrel_cluster changeset.

Steve Yegge live

After yesterday’s best read of the month here comes the best show of the day. Which is Steve Yegge, live, talking about branding during 2007 OSCON. Without any slides. 25 minutes.

He also reveals that in his opinion Javascript2 will be the Next Big Language (NBL). I was kind of suspecting this would be it. Coincidently, lately I’ve discovered (what a big word) jQuery. And let me tell you, I’ve never seen any other piece of code, which is so concise and does so many things with so much style. Prototype, dojoToolkit and all other js libraries simply look pale in comparison. I’m hooked on jQuery and use it for every new project, while trying to implement it in my old ones too.

Technology Wants To Be Free

The best read of the day, week or maybe even month:

In particular I’ve concluded the free is deeply entwined into the very foundation of technology. I was sharing some of those emerging half-baked thoughts with Chris in the lobby of TED. Since that conversation I’ve discovered that the tie between technology and the free goes even further than I thought. My current conclusion can be summarized simply: Technology wants to be free.

Let me state it more precisely: Over time the cost per fixed technological function will decrease. If that function persists long enough its costs begin to approach (but never reach) zero. In the goodness of time any particular technological function will exist as if it were free.

This seems to be true for almost anything we make: basic things like food stuffs and materials (often called commodities), and complicated stuff like appliances, as well as services and intangibles. The costs of all these (per fixed unit) has been dropping over time, particularly since the industrial revolution.

From Technology Wants To Be Free by Kevin Kelly.

As a bonus, a semi-follow-up called Better Than Free is also a great read.

And another bonus, in similar tune, by the same author Where Music: Will Be Coming From.

Top 10 movies of 2007

Just like for 2006 and 2005 here are ten movies I’ve seen in 2007 that completely blew my mind:

  1. Children of Men (2006)
  2. Mr. Brooks (2007)
  3. The Prestige (2006)
  4. The Pursuit of Happyness (2006)
  5. Stella che non c’è, La (2006)
  6. Zwartboek (2006)
  7. Ostrov (2006)
  8. Reign Over Me (2007)
  9. I Am Legend (2007)
  10. The Namesake (2006)

As usual, Hollywood movies occupy most of the list. 6 out of 10 places to be exact. Nothing changes.

Will Smith man of the year? Surely, he’s already a legend.

Top 25 music of 2007

Just like last year and the year before – here are my favourite music tunes of 2007:

  1. Monrose – Strictly Physical
  2. Mika – Relax (Take It Easy)
  3. Monrose – Hot Summer
  4. Strata – Cocaine (We’re All Going To Hell)
  5. Nelly Furtado – Say It Right
  6. Randy Crawford – When I Get Over You
  7. Sharam – Patt (Party All The Time)
  8. The Jet Set – Just Call Me
  9. Therapy – Diane
  10. Good Charlotte – Keep Your Hands Off My Girl
  11. Marc O’Tool – Let It Go
  12. iio – Is It Love?
  13. Tom Helsen – Sun In Her Eyes
  14. Timbaland ft. Keri Hilson & Doe – The Way I Are
  15. The Disco Boys – For You
  16. Christina Aguilera – Get Mine Get Yours
  17. Rihanna ft. Jay-Z – Umbrella
  18. Mustafa Sandal ft. Gentleman – Isyankar
  19. D-Jon by way of KL – It Skips But It’s Awesome
  20. Sandra – All You Zombies
  21. Sunrise Avenue – Forever Yours
  22. Dead Can Dance – The Host of Seraphim
  23. Omarion – Ice Box
  24. Meck ft. Dino – Feels Like Home
  25. Owal ft. Marta Florek – Szukam (The Nuclear Headz Remix)

Dance and house occupy 80% of this list. As usual.