Equality-at and Relation-at LaTeX Macros

These are two useful LaTeX macros for creating equality-at and, more generally, relation-at signs. These macros depend on the mathtools package. As with all other macros, you should add them to your preamble in order to use them.

The general macro is relat. It takes two arguments: the relation and an expression where the relation takes place (the “at”). The equality-at macro, eqat, is a specific case of relat. I’ve created it because it is commonly used and only requires passing the “at” argument.
Continue reading Equality-at and Relation-at LaTeX Macros

A Greasemonkey Fix to the Top Menu in Sheilta (Open University)

Following comments in Fixing the Home Link in the Telem System (Open U), I’ve decided to fix the top bar links in the Sheilta system too.

The links in the top bar are JavaScript links that open in a new window when clicked. My Greasemonkey script turns them into regular links that you can open in a new tab.

Continue reading A Greasemonkey Fix to the Top Menu in Sheilta (Open University)

Notes About Using amsmath split Environment in Hebrew Documents

Recently I’ve worked on a Hebrew document in LaTeX and wanted to use the split environment to typeset a multiline formula. The document, which compiled just fine until that point, failed to compile with the following error:

Package amsmath Error: begin{split} won't work here.

Continue reading Notes About Using amsmath split Environment in Hebrew Documents

Hidden Spam Links in WordPress

About a week ago, I decided to look at the HTML source of my blog. I was in total shock to find a spam link hidden there. This is how it looked:

<!-- ocadia theme credits, downloaded from wpthemesfree.com -->
<u id="ocadia" style="display: none">Buy some <a href="http://detoxbuddy.com/categories/191.html">marijuana drug testing</a> products</u>

Ocadia is the name of the theme I’m using, so I guessed the hidden link came from there. I was partially right. The code indeed resided in the index.php file of the theme, but as I later found out, the theme had nothing to do with that. I removed the link and the comment immediately, and went to see if it was distributed this way from Beccary (the author of the theme).
Continue reading Hidden Spam Links in WordPress

Vim Syntax Highlighting for Google Gadgets

I started developing Google Gadgets for LabPixies, so one of the first things I looked for was syntax highlighting. Vim recognized the gadgets’ code as an XML file (which is correct), but I also wanted HTML syntax highlighting for the HTML part. So, after searching a bit for an existing solution, I found one, but I didn’t like it, as it required me to wrap the HTML code with a specific comment. As I don’t like this kind of solution, I’ve decided to create my own syntax highlighting file for Vim.
Continue reading Vim Syntax Highlighting for Google Gadgets

Scanning Documents Written in Blue Ink – biscan

After writing the post on converting PNMs to DjVu, I’ve run into some trouble scanning documents written in blue ink. The problem: XSane didn’t allow me to set the threshold for converting the scanned image to line-art (B&W). So, I tried scanning the document in grayscale and in color and converting it afterward to bitonal using ImageMagick. This ended up with two results. When I used the -monochrome command-line switch, the conversion looked good, but it used halftones (dithering). When I tried to convert it to DjVu, it resulted in a document size twice as large as normal B&W would. The other thing that I tried was using the -threshold switch. The DjVu-compressed document size was much better now, but the document was awful-looking; either it was too dark, or some of the text disappeared. After giving it some thought, I knew I could find a better solution.
Continue reading Scanning Documents Written in Blue Ink – biscan

Convert PNMs to DjVu

I’ve decided to scan some notebooks. After researching a bit, I’ve decided to use DjVu instead of PDF, which I normally use. I’ve chosen to use DjVu because it offered great quality with a very good compression rate (~26KB per page) in lineart (black and white).

While XSane can natively save a multipage project into PDF, it can’t do so for DjVu. So the solution is to use the PNMs generated by XSane and convert them using the command line tools offered by DjVuLibre to bundle them together into a DjVu file. As you can guess, doing this manually is pretty hard work. To make this task easier, I’ve written a small bash script to automate the process.
Continue reading Convert PNMs to DjVu

Trailing Whitespace Causes a Session to Be Destroyed in CakePHP

While working on a new project using CakePHP, I’ve come across a weird problem. In one of the controllers, the session always came out as invalid, as

$this->Session->valid()

always returned false. I tried debugging this weird stuff, and it looked like all the session variables were unset. Using

$this->Session->error()

to get the last error returned “Config doesn’t exist”. After further debugging, “Config” turned out to be an internal array that is saved by CakePHP to the session and holds various internal data (some of it is used for validation, like a user-agent hash). I kept printing more and more debugging data, as well as looking at CakePHP’s trac system.

I found an interesting bug (ticket #4217), and it looked very promising, as it almost fully described my problem. Unfortunately, the solution offered didn’t seem to work for me. But it inspired me to try starting the session manually using session_start() instead of using Cake’s startup and activate methods of the Session Component.

I found out that session_id() returned an empty string. Luckily, calling session_start() directly from the controller gave me a lead. The session seemed to work well, but a nasty error about headers already being sent showed up.

A little more investigation led me to realize that I had a trailing newline after my closing PHP tag in that controller file. Deleting this trailing whitespace completely solved the problem. There was no need anymore to manually start the session. It’s pretty annoying that such a small thing as a trailing newline can cause such seemingly unrelated problems in CakePHP’s session handling.

Maybe CakePHP should add a little debug notice when the session doesn’t start because headers were already sent. This can be done by modifying the else statement in the __startSession() method in cake/lib/session.php (line 557 in version 1.2.0.6311). I wonder what the reason was for not informing the developer when such an event happens, as I don’t see why someone would deliberately try to start the session after sending the headers. I think it only happens by mistake, at least most of the time.

Setting Up OmniComplete (Autocompletion) for wxWidgets in Vim

I use Vim as my main IDE for C/C++-related development (as well as for almost all other development). If you use (or are thinking about using) Vim as an IDE, you better get some good autocompletion functionality. This kind of autocompletion is provided by OmniComplete, which has been available since Vim 7.0. Just having OmniComplete is a nice thing, but it’s much more helpful if it’s configured properly to work with the libraries you use, such as wxWidgets. In this post, I will show you how to get OmniComplete working for wxWidgets. However, the procedure I will show can be easily adapted to almost all libraries.
Continue reading Setting Up OmniComplete (Autocompletion) for wxWidgets in Vim