Sometimes the wrong data gets into the database and you have to update the record, that’s no biggie. You run a simple update command and everything is back on track. In other cases the error is not on one record but on many.

Alarm.

I don’t now why exactly, but when I have to do the same thing twice I’m already looking for a way to automate it. So this is what happened.

I added a new domain name to the dns tables dns_soa and dns_rr. This is done through a rails application I’m working on, but the thing I forgot was to check on spaces. So instead of having ‘domainname.com’ in my tables, ‘domainname.com ‘ (an extra space at the end is added) was inserted. The space has to go away and this is how I’ve done it.

First check what you are going to do:

SELECT REPLACE(origin,'domainname ','domainname'),
FROM dns_soa
WHERE origin like 'domainname %';

Nothing is done to the tables just yet, so be sure to check the result. After carefully checking if that was the result I wanted, I ran the actual update.

UPDATE dns_soa
SET origin = REPLACE(origin,'domainname ','domainname')
WHERE origin like 'domainname %';

One of the best things I’ve found recently is a brilliant jquery plugin called Tablesorter. This plugin lets you do all kind of things that we’ve come so accustomed to do with the ubiquitous Microsoft Excel. The things I do with tabular data are:

  • Sort
  • Filter
  • Find

These are the basic things that allow for easy representation of data the way you like it.

The setup of the plugin is quite easy, although you have to get it right. Everyone knows that debugging javascript is a bitch (although firebug helps alot). I’ve integrated this in a rails project and the results are beyond my expectations. It handles tables with 2000 records just fine. Sorting and finding is quasi instant. All-in-all a nice user experience.

Paste the code below in your apache website.com.vhost file.

<Directory /var/www/website.com/web>
Options FollowSymLinks
AllowOverride Indexes AuthConfig Limit FileInfo Options
Order allow,deny
Allow from all
</Directory>

This allows you to use .htaccess files and paste in the following code that wordpress requires for pretty urls which are used as permalinks. Options is not really needed [...]

I need it frequently, but always, and I really mean always, forget the options. Without further ado, how to tar and untar (and gzip as a bonus).
The following code will compress all files and folders in the current directory to the filename you specified and store it in the underlying directory. This is important as [...]

Yesterday I wrote an article about the event-driven streamparser in Ruby. While this solution is very fast and has a very small memory footprint, it comes at the cost of expressibility. You have to write a decent amount of code to get it working. Luckily for us there is an alternative.
For most applications I would [...]

This article shows how to write an event-driven xml parser in Ruby. Event-driven xml parsers are typically used if speed is important or large amounts of data are in play. One of the best known implementations is the SAX2 parser for Java. No Java here though, all Ruby baby.
To build an xml parser, you need [...]