Installing lighttpd-1.4.22 on Ubuntu 8.04

I had some problems with the lighttpd-1.4.19 that comes with Ubuntu 8.04, mainly with its handling of the HTTP header Expect: 100-continue (older versions of lighttpd return error 417). The problem was fixed in lighttpd-1.4.21, but 1.4.22 is the newest version, so I’ve decided to install it.

As I mentioned before, Ubuntu doesn’t have lighttpd-1.4.22 for 8.04, and it’s also not available in the updates or backports repositories. Fortunately, I found that the package is available from Debian Sid (unstable). Here are some instructions on how to install it.
Continue reading Installing lighttpd-1.4.22 on Ubuntu 8.04

Re-distilling PDFs to Reduce Size

I decided to finally learn Qt and started to read “C++ GUI Programming with Qt 4” (first edition), which is available online. The book comes in a zip file that unzips to a huge, 51MB, PDF file. Even considering that the book is quite long (556 pages), the file size is very large compared to what one would usually expect. The huge file size made reading the PDF less convenient, as one notices a considerable delay when opening it (especially if the PDF resides on some portable storage), so I decided to play around a little and see what I could do about it.
Continue reading Re-distilling PDFs to Reduce Size

Book Review: Lighttpd by Andre Bogus

As an avid user of Lighttpd, I was glad to receive a copy of the “Lighttpd” book by Andre Bogus (Packt Publishing) for review. I’ve been using Lighttpd extensively in production for over a year now, and I’m very satisfied. However, I remember that as a new user I had my share of frustration. In his book, Andre Bogus tries to ease the process for those who decide to move to Lighttpd.
Continue reading Book Review: Lighttpd by Andre Bogus

Displaying Non-Builtin Math Macros in LyX

I believe LyX is a great tool for writing LaTeX documents. It makes writing formulas very easy, and it allows you to see the formula as you are writing, as opposed to seeing only LaTeX code. However, LyX doesn’t support every LaTeX package and the macros it defines. Sure, it doesn’t stop you from using these macros in your formulas, but they don’t display nicely; you see the name of the macro instead of a schematic preview.

While LyX doesn’t support many of the great packages out there, like mathtools (which I really hope it will someday), you can add some support to your documents. At the beginning of the document, insert a comment via Insert->Note->Comment. Inside the newly created comment, insert a math macro via Insert->Math->Macro. In the name part, put the name of the command you want to add support for. In the second box (captioned LyX), use existing LyX commands to mimic how the macro will look. For example, this is what it looks like for the coloneqq macro (from the great mathtools package):
math-macro

After adding the math macro in the comment, when you use the macro inside formulas, it will display nicely:
math-macro2

A little explanation of how things work: when you define a math macro in LyX, LyX does two things:

  1. Inserts LaTeX code to create the macro.
  2. Displays the macro nicely when editing the document.

While the latter is desirable, the former is problematic. If LyX inserts LaTeX code to define the existing macro, it will cause errors. So when you put the LyX macro in the comment environment, the code LyX generates gets ignored, and only the second, desirable, outcome is achieved.

Convert int to string (As Well As Almost Anything)

This is a little code snippet from Open Yahtzee‘s code base that converts all the built-in types and many custom classes (ones that override the << operator) to string.

template <class T> inline std::string stringify(T x)
{
    std::ostringstream o;
    o << x;
    return o.str();
}

I first wrote it to convert ints to strings, but later I templatized it so it would work with other types as well. It’s a clean, elegant snippet that I thought others might find useful too.

RTL Tiddlers in TiddlyWiki

Update – For TiddlyWiki 5, see RTL Tiddlers in TiddlyWiki 5.

I’ve been using TiddlyWiki for a while now, and it has become a very useful tool for me. Today, I decided to organize my various recipes (somehow cooking, and especially making desserts, has turned into a hobby of mine), and as you can expect, I’ve decided to use TiddlyWiki for the task.

There was a slight problem, as some of the recipes are in Hebrew, and it seems TiddlyWiki doesn’t have built-in support for RTL (right-to-left) tiddlers. However, such support can be added via custom stylesheets and the tiddlers’ tags. The idea for this method was taken from this TiddlyWiki.

Create a new tiddler called “StyleSheet” (without the quotes). This is a special tiddler (a shadow tiddler) that lets you add additional CSS code for your wiki. Insert the following code into the newly created tiddler:

/*{{{*/
div[tags~="RTL"].tiddler {
    direction: rtl;
}
div[tags~="RTL"].tiddler .subtitle {
    direction: ltr;
}
div[tags~="RTL"].tiddler .tagged {
    direction: ltr;
    float: left;
}
/*}}}*/

Now, for every tiddler you want to be in RTL direction, just add RTL to its list of tags. After you do that, the tiddler will appear correctly. Here is an example of what RTL looks like after the fix:

A screenshot of an RTL tiddler
A screenshot of an RTL tiddler

Iptables Cheatsheet

From time to time, I find myself having to go through man pages and google for some simple iptables rules. This post is meant as a cheatsheet for me, so I can concentrate various rules and remarks here.

I hope others will benefit from this cheatsheet as well. I intend to expand it over time as I gather more rules and tips, so bookmarking the post might be a good idea. Last but not least, if you have some useful iptables rules I’ve missed, please send them using the comments.
Continue reading Iptables Cheatsheet

Starting tracd without Root Privileges at Startup

I use Trac for the Open Yahtzee website. I’ve decided to use tracd for serving the requests (due to a configuration issue I didn’t want to mess with), which requires starting it each time the server restarts. I’ve already written one solution for this, in the form of an init.d script for tracd. However, it bothered me that tracd runs with root privileges, which it doesn’t really require.

After searching a bit, I’ve found out that cron can run tasks on startup using the special @reboot keyword instead of the normal time fields. So, edit your crontab and add the following line:

@reboot /usr/bin/tracd --daemonize --pidfile=~/run/tracd.pid --port=PORT --hostname=HOSTNAME -s TRAC_ENV

Just replace PORT, HOSTNAME, and TRAC_ENV with the appropriate values for your environment, and make sure you have a run/ subdirectory in your home folder (or change the pidfile value).

To stop the server, just do:

kill `cat ~/run/tracd.pid`

While there is no straightforward way to restart the server (like /etc/init.d/tracd restart), it’s a good compromise for dropping root privileges.

Amarok Sleep – Stop Playback After a Specified Amount of Time

Amarok is my favourite music player. I like to listen to music when I go to sleep, but I don’t want the music to keep playing all night long. This is why I’ve added a sleep feature to radio.py. Unfortunately, Amarok doesn’t have built-in sleep functionality, but the Amarok developers left an open door for us to implement it with ease by means of interfaces that allow us to control Amarok from the command line.
Continue reading Amarok Sleep – Stop Playback After a Specified Amount of Time

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