Theme crash in Ubuntu 10.10

From what I can read it’s a common issue for many people using Ubuntu 10.10, at least among the users of the 64-bits version. There are two bugs reported in launchpad: here and here.

After several months without problem, I just experienced this issue… and the two solutions given in Launchpad (aptitude reinstall gnome-settings-daemon and sleep 2) don’t help at all.

So, how to deal with that? Well, it’s simple: just open a terminal window and in it write:
$ gnome-settings-daemon

Now the theme is restored, but the icons in the file manager still look bad. That’s because of Nautilus the file manager. You have to kill it. Yes, kill it:
$ killall nautilus

So Nautilus will be restarted after that, with the right icons. You can now close your terminal window and go back to a normal life.

I hope the Ubuntu people will fix this issue before the release of the next version, Natty Narwhal, which should be released this month.

How to change the timeout in GRUB2?

Sometimes booting your Linux system can be relatively long. It depends often on how many services your system needs to start while booting.

There’s also a phase which takes time: the boot-loader. It displays a menu in which you can choose which kernel to use or starting another operating system. If you don’t choose anything, there is a timeout and then the boot-loader picks up the default kernel/operating system.

Ubuntu 10.10 sets this timeout to 10 seconds which can be seen as long. It’s possible to change that.

How? Well the boot-loader used by Ubuntu is GRUB2. Since 9.10 (Karmic Koala) and the file for configuring it is /etc/default/grub.

In Ubuntu you need to use sudo for editing this file (replace emacs by your editor of choice):
sudo emacs /etc/default/grub

Then you need to find the setting GRUB_TIMEOUT and change its value to 3 seconds for instance:
GRUB_TIMEOUT=3

Save the file and you have done most of the work!

To achieve it, you need now to run update-grub to update the file /boot/grub/grub.cfg:
~$ sudo update-grub
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-2.6.35-22-generic
Found initrd image: /boot/initrd.img-2.6.35-22-generic
Found linux image: /boot/vmlinuz-2.6.32-25-generic
Found initrd image: /boot/initrd.img-2.6.32-25-generic
Found memtest86+ image: /boot/memtest86+.bin
Found Windows 7 (loader) on /dev/sda1
done
~$

You can now reboot your system if you want to test it 🙂

PHP: isset () vs strlen ()

How to test the length of a string in PHP ?  Well, PHP has a function called strlen () for this purpose.
So obviously, a simple if (strlen ($str) > 10) { ... } should do the trick, isn’t it?

Actually, there’s another way to do that: considering that a string is an array of characters, it’s possible to test if a character is set at the length we want to check with isset (). So the line of code above should be replace by if (isset ($str [10]) { ... }.

Why should we use isset () instead of strlen ()?

Well, it’s way faster: running the test above 100 000 times for each function gives me:
strlen () : 0.034812927246094 seconds
isset () : 0.0079290866851807 seconds

Getting current datetime in ISO format in MySQL

Here is the MySQL function to use to get the current datetime as ISO 8601 format as asked in DarwinCore:

DATE_FORMAT(NOW(),'%Y-%m-%dT%TZ')

DATE_FORMAT() is obviously a function for formatting date and time, and we are using here %Y for four-digit year, %m for two-digits month, %d for two-digits day and %T for 24-hour time (hh:mm:ss). NOW() gives the current datetime.

And then you get a nice figure like this one:

2009-06-10T07:43:12Z

Note that the same result can be achieved with:
CONCAT(CURDATE(),'T',CURTIME(),'Z')

Where CONCAT() is used for concatenating strings, and CURDATE() and CURTIME() give respectively the current date and the current time.

UPDATE: There is now a page for getting the current datetime in different formats. Check the page here: Get the current date in different formats in MySQL.

PHP: isset()

isset() is a function testing if a variable $var is set or not.

boolean isset (mixed $var[, mixed $var[,...]])

It returns TRUE is the variable is set, and FALSE if it isn’t.

Using isset() for testing a variable saves some times compared to try to use an nonexistent one. It also helps to avoid error messages from PHP:

/* The line below generates the warning message:
* Notice: Undefined variable: var in /path/to/script.php on line 1
*/
$toto = $var;

/* Of course it's possible to silence with @ the warnings from PHP but it's costly */
$toto = @$var;

/* Do this instead: */
if (isset ($var)) {
$toto = $var;
}

As seen in the function definition above, isset can take multiple arguments. But it is faster to have an if statement with one isset() call per variable rather than one isset() call with several variables:

if (isset($a) && isset($b)) { } /* Fast */

if (isset($a, $b)) { } /* Slow */