Archive for February, 2009

Installing proprietary NVidia drivers on Ubuntu

Friday, February 27th, 2009

The latest Linux NVidia drivers (180.29) finally contain a fix to a long-standing bug that affects 2D rendering performance in Firefox. Until this release, many javascript-powered visual effects (such as the Javascript image transition on this site) have caused horrendous performance in Firefox. A big thank you to NVidia for finally fixing this!

To install the drivers on Ubuntu:

  1. Download the drivers from the NVidia site to your home directory
  2. Log out of your Gnome / KDE session
  3. Start a virtual terminal by pressing Ctrl+Alt+F1, and log in to your account
  4. Remove any old NVidia packages you might have with
    sudo apt-get remove nvidia*
  5. Stop Gnome with
    sudo /etc/init.d/gdm stop
    Could someone please provide the equivalent command for KDE?
  6. Switch to run level 3 with
    sudo init 3
  7. Install the drivers with
    sudo sh ./NVIDIA-Linux-x86-180.29-pkg1.run
    Just follow the prompts (and basically press enter a lot)
  8. Once the installation has completed, restart your machine with:
    sudo shutdown -r now
  9. Once you’ve rebooted, you should be running the latest drivers in all their 2D performance glory!

Exciting Regular Expressions #37

Thursday, February 5th, 2009

Here’s a regular expression to match the extension in a filename:

/\.(?!(.*\.)).*$/

It uses a negative look ahead to ensure that things all go smoothly when you have a filenames such as:

// Many dots in filename
/directory/folder/subdir/file-v1.2.3.zip

or

// Many dots in filename, relative paths and an extension with more than 3 characters in
./../folder/file-v1.2.3.gzip

Using this regular expression, a simple “ChangeFileExtension” routine in PHP might look like:

function ChangeFileExt($filename, $newExtension)
{
  if ($filename != "")
    return preg_replace("/\.(?!(.*\.)).*$/", ".$newExtension", $filename);
  else
    return "";
}

Edit: Just noticed that Nash has another nice regex to do this. See here