/me@(voip.)?|www./ SamLown.com

Rails: NilClass no longer extended with a < method in Rails 2.1

I discovered a strange change in Rails 2.1 today when I found a bit of faulty code that used to work in Rails 2.0. Rather than try to describe it, here’s a quick example:

planetaki@Planetaki1:~/Planetaki$ ./script/console 
Loading production environment (Rails 2.0.2)
>> @x < 10
=> false

And in Rails 2.1:

sam@dell-desktop:~/workspace/Planetaki$ ./script/console 
Loading development environment (Rails 2.1.0)
>> @x < 10
NoMethodError: You have a nil object when you didn't expect it!
The error occurred while evaluating nil.<
     from (irb):1

After a quick search I’ve not managed to find anything specific that would cause this in the Rails libraries, and on both systems performing the test on the standard irb console will cause an exception as expected. Very strange. Let me know if you have any ideas!

Big Update to Planetaki!

We’ve just made a major release for Planetaki! Its taken a lot of effort to get here and there are quite a few changes, the major two being Badge support and internationalisation support!

Click the following badge to see what happens!

I would go into more detail, but I’m rather tired after spending all afternoon getting it to work, and tomorrow we’re off to startup2.eu in Barcelona to strut Planetaki’s stuff with a few other European Startups… expect more info soon!

Finally, just in case I don’t get chance to comment beforehand, if you’re in Spain, don’t forget to acquire a copy of “El PaĆ­s” on Thursday. It should have a technology supplement in it and mention Planetaki!

All good stuff!

BBC HD Free-to-air Satellite TV Service Starting

News today that the BBC and ITV has started a free-to-air satellite TV service for UK residents. According to the article:

It broadcasts 80 digital TV and radio channels including the main ones, and will rise to 200 by the end of 2008.

Users make a one-off payment for a dish, set-top box and installation, but will not pay a monthly subscription.

A quick google suggests that the service is provided by Freesat although their website still says things like “once freesat launches” so its clearly still pretty new. There is no mention yet as to which Satellite cluster they are using (although I’m guessing it will be the Astra 2D service), with a bit of luck the signal might just be strong enough to reach Spain and Madrid! (Although clearly illegal by ridiculous, outdated distribution rights.)

This is a great step for HD TV and for lessening the strong-arm of Rupert Murdock and Sky. An example for many of the other over-priced European satellite TV providers.

Free Flash = Open Screen Project

A really astounding peice of news came up on my planet this morning; Adobe lifts SWF/FLV restrictions and creates Open Screen Project

Indeed, the main objectives of Adobe’s Open Screen Project appear to include the opening up of the Flash standard, and the removal of all licensing in order to support the use of Flash in set-top boxes and mobiles. The official press release clearly states their intentions.

Wow. If they go ahead with this it will really put the nail in the coffin for Microsoft’s Silverlight. My vision of Adobe finally releasing their suite of products for Linux is just a little bit closer.

When Ruby doesn't clean up after itself: tempfile leftovers

Today, Planetaki went down for a few minutes as the master reaper server ran out of hard drive space. The first thing you do when you run out of space is remain calm and try to find out whats using it all up. In this particular case where the database is the only real space user (and its not that bad) everything was fine and the log files where all within limits. It didn’t take long to figure out that the temporary directory had turned into a 30GB monster and was locking up the system.

We use the ruby open-uri library to download content from the web which stores everything it downloads in temporary files. Normally, these are supposed to be destroyed as soon as the object that is using the temp file is removed. It turns out however that these files are not destroyed correctly if the Garbage collector does not get chance to run before the program terminates.

In the case of our Planetaki backend, we are opening new sites constantly and downloading files and use forking to download from lots of feeds at the same time. The tempfile library it seems has a problem with forking, and will not correctly remove the tempory files when each instance terminates.

The solution, take the garbage out before going to bed:

spawn do
  open('http://website.com') do | f |
    # do stuff with data
  end
  GC.start
end

The GC.start at the end there is vital it seems to ensure your temp files don’t cause you system to run out of hard disk space.

Migrating a MySQL database from one character set to another with the same data.

My previous post on the issue of MySQL character sets addressed the problem when the data in the database has been stored incorrectly by the encoding of the connection. This time, I’d like to cover what to do when the connections are okay, but the table definitions are wrong.

Normally, this isn’t a problem, by the “rubbish in, same rubbish out” principal, whereby even though the database doesn’t understand the data as long as goes in and comes out the same there will not be a problem. This has worked for me in the past, but it turns out it doesn’t work when you start dealing with Cyrillic and symbolic languages such as Russian and Chinese. (I have yet to discover exactly why, but I suspect it has something to do with the range of the bits in UTF-8 encoding.)

Firstly, we’re going to create a new database to hold the properly formated data, so enter the mysql console and create a new database with the following command:

CREATE DATABASE new_database CHARACTER SET utf8;

Unfortunately, MySQL does not allow us to rename a database, so the new name must be permanent and all the permissions that use the database name will need to be modified. The old and new databases for this miniguide are distinguished as old_database and new_database respectively. There are hacks to get around the renaming issue, and solutions to this can be found elsewhere. Phpmyadmin also makes renaming pretty straight forward by copying the database.

Back on the command line, we need to copy and modify the table definitions to use the new character set. At this point, you might want to stop your website to ensure nothing else gets written, and in this instance so that the autonumber fields do not loose track. Dump just the definitions of the original database as follows:

mysqldump --no-data -u root -p old_database > /tmp/tables.sql

The resulting file must be opened, and everything that says “latin1” must be converted to “utf8”. (Vim search and replace might help with this.) Also, you might want to remove any of the COLLATE commands, as they will default to something reasonable if the character set is correct.

With the tables corrected, we need to dump just the data, including the default character set of course.

mysqldump --no-create-info --default-character-set=utf8 -u root -p old_database > /tmp/data.sql

Lets now dump this back into the new database:

cat /tmp/tables.sql | mysql -u root -p new_database
cat /tmp/data.sql | mysql -u root -p new_database

Thats it! The new database should running completely using utf-8 and you shouldn’t have corrupted any of the data that was already in use. Let me know if you find this useful or come up with a problem!

Planetaki.com - ready for thrashing

Its official, Planetaki.com is now officially ready to be broken by more than just javier and myself (amongst others)! Clearly, we are still in early Beta, and most people who glimpse at this blog probably already know about it, but this milestone nonetheless deserves recognition for the amount of effort taken to get here.

The startup wasn’t without its setbacks, indeed, there was a short period this afternoon where the site dropped to modem speed as the Ruby on Rails Mongrel servers began to gobble up all the memory and the swap space (causing thrashing). As soon as I figured out what was going on (with the help of the very helpful slicehost.com people) the server returned to acceptable response levels though I expect we’ll be doing some upgrades soon!

My Planet can be found here and you may also find this one amusing.

If you haven’t looked already, please check it out and let us know how it goes!

Pixmania: Need help in Spain? Call England!

Last June we bought a 42" Toshiba LCD television from the seemingly popular online store PIXmania.com. Last November it stopped working. Initially, we made the mistake of using the guarantee with Toshiba, they picked up the TV, made us wait two months, we complained, then told us they wouldn’t repair it because we bought it from Pixmania in France and they have no legal obligation to complete the warranty. Thanks Toshiba you incompetent losers!

So, after calling Pixmania they told us to send it to their local store in Madrid, and they’ll sort it out. One month later we tried to contact them to find out what the status is. Trying to call their expensive Spanish support line resulted futile, they either just hung-up or a message came on saying they were closed. With my patience wearing thin, I decided “these guys are in France, what difference does it make what country I call from!”, so I grabbed my internet phone and proceeded to call far cheaper UK support line. They answered instantly, explained the problem precisely, and guaranteed within three weeks we’ll have the TV. They even blamed Toshiba for the delay and apologised.

There are several morals to the story here when buying over the internet:

  • Always call the store first, despite what their website says
  • Be prepared to wait
  • If the Spanish support line sucks, call the English one

At least the weathers nice here!

Indignation: The New Website for Mariano Rajoy

There are so many things wrong with Mariano Rajoy’s (Spanish president candidate) new website I just don’t know where to begin. Firstly though, as many readers may already know, I’ve had a lot of involvement with the PP website although not directly through one of my client companies (out of chance rather than political bias) and I can safely say we had nothing to do with this disastrous piece of work. I’d be long gone if that was the case!

As if the site couldn’t be worse, it seems the creators even forgot to protect the administration area, just insane for one of Spain’s largest political parties, and a clear sign of complete incompetence, you can almost smell the nepotism in the air.

Here’s a quick run down of what made me so sad about it:

  • Accessibility – simply not there, not even a style sheet! There is no way a visually disabled person could navigate this site. Frankly, I don’t think this should even be legal for public site of this scale.
  • Doesn’t show correctly in Firefox – layers are all messed up, and the flash uses up 100% of the CPU (due to poor looping.)
  • Dreamweaver code – see also accessibility and a sign of lazy authors.
  • Links as pop-ups – rule 101 of web programming, no pop-ups to access other parts of the same site, ever! Especially not from a Flash animation that causes Firefox to block access!

I hope the Spanish public bring attention to how unacceptable this is, it saddens me greatly.