Configuring Lighttpd for CakePHP

I tried a few days ago to install a CakePHP project of mine on a lighttpd web server. As expected, its clean URLs didn’t work, so I set out to find a solution.

One possible solution is the one outlined in the CakePHP manual. The solution uses the mod_magnet module (which basically runs a Lua script to do the rewriting), and I found it to be overkill. I was looking for a simple solution based only on mod_rewrite, something like the solution for WordPress.
Continue reading Configuring Lighttpd for CakePHP

phpMyAdmin + Lighttpd in Gentoo

Usually, installing software in Gentoo is a piece of cake. Just emerge what you want, and with the right USE flags, everything will be ready for you. However, as I’ve found out today, installing phpMyAdmin with Lighttpd isn’t as trivial as it should be.

In this post I’ll try to walk you through the necessary steps to install phpMyAdmin with Lighttpd in Gentoo.
Continue reading phpMyAdmin + Lighttpd in Gentoo

Fixing Numbering Direction for Hebrew Text in LyX

On Monday, I submitted a patch to the LyX developers mailing list with a fix for the numbering direction in Hebrew text. In Hebrew text, the dot appeared before the numbering symbol instead of after it, as it should.
before-fix
This behaviour has been this way for years (at least as long as I can remember).
Continue reading Fixing Numbering Direction for Hebrew Text in LyX

Batch Renaming Using sed

I was reorganizing my music library and decided to change the naming convention I’d used. This task was just asking to be automated. Since the filename change could be described using a regular expression, I looked for a way to use sed for the renaming process.

The files I had followed the filename pattern ARTIST – SONG – TRACK – ALBUM

James Brown - I Got You (I Feel Good).ogg  - 01 - Classic James Brown

I wanted to rename them to ARTIST – ALBUM – TRACK – NAME

James Brown - Classic James Brown - 01 - I Got You (I Feel Good).ogg

Describing the change as a sed program is easy:

s/(.*) - (.*) - (.*) - (.*).ogg/1 - 4 - 3 - 2.ogg/

Now all that has to be done is to pass each filename to mv and pass it again after it has gone through the sed script. This can be done like this:

for i in *; do
  mv "$i" "`echo $i | sed "s/(.*) - (.*) - (.*) - (.*).ogg/1 - 4 - 3 - 2.ogg/"`";
done

The important part is

`echo $i | sed "s/(.*) - (.*) - (.*) - (.*).ogg/1 - 4 - 3 - 2.ogg/"`

which pipes the filename to sed and returns it as an argument for mv.

To see what renaming will be done, one can alter the above command a bit and get

for i in *; do
  echo "$i" "->" "`echo $i | sed "s/(.*) - (.*) - (.*) - (.*).ogg/1 - 4 - 3 - 2.ogg/"`";
done

which will effectively print a list of lines in the form oldname -> newname.

Of course, this technique isn’t limited to the renaming I’ve done. By changing the pattern given to sed, one can do any kind of renaming that can be described as a regular expression replacement. Also, one can change the globbing (the *) in the for loop to operate only on specific files that match a given pattern in the directory, instead of all of them.

Deleting a Range of Tickets in Trac

Recently, the Open Yahtzee website, which runs Trac, has fallen victim to several spam attacks. The spammers submit a large number of tickets containing links to various sites. This post was written mainly to allow me to copy and paste a command to delete a range of tickets at once, but I thought it might be useful to others as well.
Continue reading Deleting a Range of Tickets in Trac

WordPress Backup to FTP

Update: A newer version of the script is available.

This script allows you to easily back up your WordPress blog to an FTP server. It’s actually a modification of my WordPress Backup to Amazon S3 Script, but instead of saving the backup to Amazon S3, it uploads it to an FTP server. Another update is that now the SQL dump includes the database creation instructions, so you don’t need to create it manually before restoring from the backup.

Although I’ve written it with WordPress in mind (to create backups of my blog), it isn’t WordPress-specific. It can be used to back up any website that consists of a MySQL database and files. I’ve successfully used it to back up a MediaWiki installation.
Continue reading WordPress Backup to FTP

Extract Public Key from X.509 Certificate as Hex

X.509 certificates are a common way to exchange and distribute public key information. For example, most Open Social containers use the OAuth RSA-SHA1 signature method and distribute their public keys in the X.509 format.

While working on an AppEngine application, I needed to verify requests from such containers. However, there is (currently) no pure Python library capable of parsing the certificates. This meant that I needed to extract the public key out of the certificate manually and store it in some parsed way inside the Python code.

Fortunately, parsing public keys from an X.509 certificate and representing them as a hex number turned out to be simple and easy.
Continue reading Extract Public Key from X.509 Certificate as Hex