How to handle sfError404Exception

The problem:

Let’s say you need to migrate old website to you new Symfony app. You want to keep all old links working. When they do not match the new link scheme, you want to redirect with 301 (or 302) to correct page in the new URL scheme. All these can be managed via backend module.

My first thought was I need a filter to catch sfError404Exception and handle redirections from there. Well, in Symfony 1.4 you can’t do it without changing the Symfony core files, so it’s not an option. This is because the filters are not even get called, as routing finds out first, that the module and/or action does not exists and throws this exception.

The solution:
Read more…

How to set default value or option in the Symfony embeded form inside the Action

Let’s say you have Symfony 1.4 form User with embedded form Entry

class UserForm extends Something
{
  public function configure()
  {
    $this->embedForm('entry', new EntryForm());
  }
}

Read more…

bash: /usr/bin/kvm: No such file or directory on Gentoo

After updating my Gentoo host machine yesterday with emerge -avDNu world, which included update of kvm from app-emulation/qemu-kvm-0.13.0-r2 to app-emulation/qemu-kvm-0.14.1, I wasn’t able to boot my guests systems any more. So first thing I did was emerge qemu-kvm. It turns out that it doesn’t help – kvm file is still missing.

gentoo1 ~# ls -l /usr/bin/ | grep kvm
-rwxr-xr-x 1 root root      66872 May 28 16:03 kvm.kss

Luckily for me I do have more Gentoo machines with KVM virtualization.

I’ve logged in on my other KVM Gentoo machine and found out following:

gentoo2 ~# ls -l /usr/bin/ | grep kvm
lrwxrwxrwx 1 root root         17 Nov 11  2010 kvm -> /usr/bin/qemu-kvm
-rwxr-xr-x 1 root root         61 Nov 11  2010 qemu-kvm

OK – so what’s the content of the qemu-kvm file?

gentoo2 ~# cat /usr/bin/qemu-kvm
#!/bin/sh
exec /usr/bin/qemu-system-x86_64 --enable-kvm "$@"

From the above you can easily fix the problem by creating qemu-kvm file with content above, plus adding the kvm symlink. Hope it’ll help.

MySQL FROM_UNIXTIME and UNIX_TIMESTAMP functions in PostgreSQL

Personally I prefer PostgreSQL over MySQL DBMS. However there are some things I miss in PostgreSQL. Here is an advice on how to use MySQL FROM_UNIXTIME and UNIX_TIMESTAMP function in PostgreSQL DBMS.
Read more…

What’s the average length of an email address?

This question always comes up, when you have to design new table in database to store email addresses. Is VARCHAR(30) long enough? Or maybe you should use VARCHAR(255) or maybe TEXT as I’ve seen in some projects?

My live database, which I’ve used for this test contains 92298 valid email addresses, verified with the Pear Validate class with domain checking.
Read more…