Archive for March, 2005


No subqueries on DreamHost either

Tuesday, March 29th, 2005

So MySQL can’t cope with subqueries. Something simple like:

select * from competitions 
  where id in (select competition_id from scores where user_id = 1)

From what I’ve read the 4.1.x series should be able to do this. The version on my account claims to be 4.1.8 but the version the server is running is 4.0.23. But it must be pretty new because even the stable version in Gentoo is only 4.0.28. How on Earth did this database get to be so popular?!?! Simple basic things that PostgreSQL has been doing for ages are only getting into MySQL, it’s really beginning to piss me off.

Spread the word: Technorati related  |  del.icio.us bookmark it!  |  submit No subqueries on DreamHost either digg.com digg it!  |  reddit reddit!

Cancelling your TypePad account is scary

Saturday, March 26th, 2005

TypePad is pretty aggressive if you cancel your account. They immediately delete everything and give you no refund for the remaining period. Thankfully I was only on the monthly subscription. I also did an export, grabbed the atom feed and stylesheet before cancelling. There’s no going back now!

Spread the word: Technorati related  |  del.icio.us bookmark it!  |  submit Cancelling your TypePad account is scary digg.com digg it!  |  reddit reddit!

Fixed the permalinks

Saturday, March 26th, 2005

I fixed the old TypePad permalinks. Rather than trying to get the permalink structure in WordPress to match TypePad, I put together some htaccess Rewrite and Redirect rules. Since I only have nine posts on TypePad I just hardcoded them, e.g.:

Redirect 301 /programming/index.html http://blog.milesbarr.com/category/programming/
Redirect 301 /programming/ http://blog.milesbarr.com/category/programming/

RewriteRule ^2005/02/ruby_on_rails.html /2005/02/ruby-on-rails/ [redirect=permanent,last]

I tried just doing redirects for the posts but it kept appending the filename to the new URL, which WordPress’ RewriteRules would translate into URL parameters, which do a search and you just get a ‘No matching posts found page’. The rewrites work fine and send back a 301 so hopefully URLs will get updated automatically. The archive by date pages have the same URL so I didn’t have to do anything for them.

Next stage, try to replicate the old theme in WordPress.

Spread the word: Technorati related  |  del.icio.us bookmark it!  |  submit Fixed the permalinks digg.com digg it!  |  reddit reddit!

Changed to WordPress

Saturday, March 26th, 2005

DreamHost offers a one-click install of WordPress, so I figured I might as well try it out. The setup was straightforward and it imported all my old posts from TypePad. This does mean all my permalinks are broken, hopefully this doesn’t affect too many sites. The other annoyance is that most WordPress themes are ugly! I finally decided on Steam, but I think I’ll keep looking. It’s perhaps too simple for my eye.

Spread the word: Technorati related  |  del.icio.us bookmark it!  |  submit Changed to WordPress digg.com digg it!  |  reddit reddit!

At least Ruby makes things easy

Wednesday, March 23rd, 2005
def before_destroy 
    scores.each { |x| x.destroy }
end

A lot easier than deleting related objects in Java!

Spread the word: Technorati related  |  del.icio.us bookmark it!  |  submit At least Ruby makes things easy digg.com digg it!  |  reddit reddit!

I want PostgreSQL back!

Wednesday, March 23rd, 2005

DreamHost doesn’t support PostgreSQL. That’s fine, a lot of people use MySQL, so it can’t be that bad. But by default MySQL doesn’t support foreign keys, you need to enable InnoDB for that. And surprise, surprise DreamHost doesn’t current support InnoDB. So instead of a few carefully placed ‘ON DELETE CASCADE’s, I have to manually delete all related objects in my Ruby code. What a PITA, bring back PostgreSQL!

Spread the word: Technorati related  |  del.icio.us bookmark it!  |  submit I want PostgreSQL back! digg.com digg it!  |  reddit reddit!

Installing Ruby on Rails on DreamHost

Tuesday, March 22nd, 2005

After initially deciding to try TextDrive I eventually opted for DreamHost because it looks like they are going to offer better long term stability. But DreamHost doesn’t support Rails natively, and aren’t planning to until it gets into Debian’s stable release, so sometime in 2010. But it’s a pretty flexible host so you can run your own software. I came across this guide for installing Rails on DreamHost:

http://www.numberporn.com/archives/000118.php

Unfortunately, it already appears to be out of date, and the last Apache configuration doesn’t work with the current version of Rails. But that’s just a minor blip because each request reloaded the entire Rails framework, so I doubt it would have been usable.

I decided to give up trying to get it to run inside Apache and just use the WEBrick server that comes bundled with Rails. First startup the server (from the root of your Rails application):

nohup script/server -e production &> log/WEBrick.log &

At this point you should exit your ssh session then relogin because if the ssh session times out it’ll take WEBrick with it, but exiting means nohup will keep it alive.

The next step is to get Apache to forward to WEBrick. In the ‘.htaccess’ file in your web directory, enter:

RewriteEngine On
RewriteCond   %{SERVER_PORT}  ^80$
RewriteRule ^(.*)$ http://www.yourhomename.com:WEBRICK_PORT/$1 [L]

Replacing yourhomename and WEBRICK_PORT with the actual values. This makes Apache redirect all requests to WEBrick. The only annoying thing is it displays the port number in the rewritten URL. This is fine for toy applications, but not good enough for production applications. In theory replacing [L] with [P] is supposed to mask this by making Apache act as a proxy, but it returns a 404 instead. Everything I learnt about Apache configuration I learnt in the past hour, so there’s a good chance I’m doing something wrong.

But anyway that gets your Rails app running on your DreamHost account, which is a definite step forward.

Spread the word: Technorati related  |  del.icio.us bookmark it!  |  submit Installing Ruby on Rails on DreamHost digg.com digg it!  |  reddit reddit!

Static typing isn’t so bad

Thursday, March 17th, 2005

So I’ve spent the past week or so putting together a simple Rails application. For the most part I’m impressed, but it’s clear it only 0.10 for a reason. I developed the app using PostgreSQL, which has a native boolean type (non standard of course), which ActiveRecord translates nicely. My web host does not have PostgreSQL installed, but the more popular MySQL.

So I installed MySQL locally and ported things over. It’s things like setting up users and permissions that bugged me the most because Google couldn’t turn up anything useful. The actual port was trivial, things like changing serial to MySQL’s auto increment thing. That is until I found MySQL doesn’t have a native boolean type, it’s just an alias for TINYINT(1). And no matter what this ticket says, they aren’t recognized properly as booleans by ActiveRecord and are treated like ints. So where before the framework did things like translating a checkbox’s default value of ‘on’ to true, I now had a bunch of silent failures.

This is where static typing is nice. It would tell me that ‘on’ is a string and not the boolean value TRUE. Things like ‘if @user.enabled then’ would fail because enabled is an int not a bool. But instead it just runs with incorrect behaviour. Thankfully there weren’t that many things I had to track down.

So this round goes to static typing. Eventually I’ll start seeing an upside to dynamic typing, but at the moment the years of Java programming still make me want to declare every little thing.

Spread the word: Technorati related  |  del.icio.us bookmark it!  |  submit Static typing isn’t so bad digg.com digg it!  |  reddit reddit!