Expectation Symbol in LaTeX

After looking for a builtin expectation symbol in LaTeX, and coming up with none, I’ve defined one. Just add:

% Expectation symbol
\DeclareMathOperator*{\E}{\mathbb{E}}

to your LaTeX preamble and you’re done. You’ll also need to add \usepackage{amsmath} or in LyX to tick “Use AMS math package” under Document->Settings->Math Options.

Using the starred version of \DeclareMathOperator makes sure subscripts goes beneath the symbol in display mode.

Author: (no author) not defined in authors file

I came across the following error message

Author: (no author) not defined in authors file

when I tried to import an SVN repository (Open Yahtzee‘s) to Git using git svn and I specified an authors file (using -A). Indeed, the first commit to the svn (which was done using cvs2svn) had no username for the commiter. Apperantly the workaround is to add the following line to your author file.

(no author) = no_author <no_author@no_author>

I tried also doing the same without an email address, but it just didn’t work. It seems Git requires that all authors have an email address.

Reinstall grub in Ubuntu

My brother asked me to repair his boot loader, after he accidentally erased his MBR. This can be done easily via LiveCD and the command line.

Boot the system using a LiveCD (I’ve used Ubuntu from USB stick) and do the following:

$ sudo mount /dev/sda /mnt
$ sudo mount --bind /usr/sbin /mnt/usr/sbin
$ sudo mount --bind /usr/lib /mnt/usr/lib
$ sudo mount --bind /dev/ /mnt/dev
$ sudo chroot /mnt

# grub-install /dev/sda

I hope it will be useful for others as well, as the Ubuntu community documentations offers a solution based on Boot-Repair, which seems an overkill for me.

Automated Encrypted Backups to S3 Using Duplicity

This tutorial will hopefully guide you in making automated encrypted backups to Amazon’s S3 using duplicity. It was written as a followup for Using Duplicity and Amazon S3 – Notes and Examples, in order to organize all the necessary information into a simple tutorial.

Will start by creating a simple wrapper to duplicity:

#! /usr/bin/python
import sys
import os

duplicity_bin = '/usr/bin/duplicity'

env = {
    'AWS_ACCESS_KEY_ID':     'PUT YOUR KEY ID HERE',
    'AWS_SECRET_ACCESS_KEY': 'PUT YOUR SECRET ACCESS KEY HERE',
    'PASSPHRASE':            'PUT ENCRYPTION PASSPHRASE',
}
env.update(os.environ)

os.execve(duplicity_bin, sys.argv, env)

save this under dupicity-wrapper.py and chmod 0500 it so only you will be able to read and execute it.

Note: You’ll want to write down the passphrase and store it in a safe location (preferably in two separate locations). So in case you’ll need to restore the backups, you won’t have useless encrypted files.

Now edit your crontab and add a line like the following:

10 1 * * 0 /path/to/duplicity-wrapper.py /path/to/folder/ s3+http://bucket-name/somefolder &>> ~/log/backups.log

This will create a weekly backup for /path/to/folder. The backup will be encrypted with what ever passphrase you’ve given in the duplicity-wrapper.py. The output of the backup process will be saved into ~/log/backups.log.

You should also run

/path/to/duplicity-wrapper.py full /path/to/folder/ s3+http://bucket-name/somefolder

in order to create full backups. You might want to periodically verify your backups:

/path/to/duplicity-wrapper.py collection-status s3+http://bucket-name/somefolder
/path/to/duplicity-wrapper.py verify s3+http://bucket-name/somefolder /path/to/folder/

To check the status of the backups and to verify them.

And last but not least, in case you ever need the backups, you can restore them using:

/path/to/duplicity-wrapper.py restore s3+http://bucket-name/somefolder /path/to/folder/

Security Considerations

As I know, some people will comment on the saving of the encryption passphrase plainly in a file, I will explain my reasoning. I use the above encryption in order to secure my files in case of data leakage from Amazon S3. In order to read my backups, or silently temper with them, some on will have to get the passphrase from my machine. While, this isn’t impossible, I will say it’s unlikely. Furthermore, if someone has access allowing him to read files from my computer, he doesn’t need the backups, he can access the files directly.

I’ve given some thought about making the backups more secure, but it seems you always have to compromise on either automation or incremental backups. But, as I wrote, the current solution seems to me strong enough given the circumstances. Nonetheless, if you’ve got a better solution it would be nice to hear.

Check if a server is about to run fsck

Couple of weeks ago I installed some updates to my server. And when I restarted it, it didn’t came up. To make things worse, the IPMI console decided to go on strike so I couldn’t see what’s really going on. I presumed that the system isn’t responding because of some kernel panic. After a while, I gave up for that night in hope the in the morning the IPMI would be sorted out. To my surprise, the IPMI was still out of work, but the server was up again. Apparently, the system wasn’t stuck on kernel panic, but on fsck‘ing the harddisks. So in order to avoid such problems in the future I looked for a way to tell when the system is going to run fsck after the next reboot (I also had the IPMI fixed).

 $ sudo tune2fs -l /dev/sda6

In the output you will find the following lines:

Mount count:              2
Maximum mount count:      36
Last checked:             Tue Jul 26 04:49:18 2011
Check interval:           15552000 (6 months)

“Maximum mount count” is the number of mounts after which the filesystem will be checked by fsck. “Check interval” is the maximal time between two filesystem checks. The command also lets you see the actual mount count since the last check and when it took place.

Missing *.la files

Sometimes when you compile a package it fails and complains it can’t find an *.la file for some library that is installed. Recently I had it when compiling dev-libs/gobject-introspection which complained about missing libpng14.la. The solution for this is to run:

sudo lafilefixer --justfixit

It won’t create the .la file, but it will fix the libtool references so nothing points to it so packages will compile fine.

Deleting Comments from Tickets in Trac 0.12

About a year ago I wrote about a way to delete comments from tickets in Trac prior to version 0.12 (as it didn’t exist back then). Basically the method was to directly delete the comment from the database. Lately, spammers have been harassing one of my Trac installations, bypassing the spam filtering, and changing ticket properties. The old method wouldn’t revert those changes. After searching for a solution, I found a little documented option in Trac 0.12 that allows to delete comments and revert changes to tickets.

To enable it, go to the admin panel->Plugins->Trac 0.12 and enable TicketDeleter under tracopt.ticket.deleter.*. This will add a “Delete” button right next to the “Reply” and “Edit” buttons of every comment. It will also revert any changes to the ticket properties.

See #3641 and [9270] for the relevant ticket and changset in Trac’s own Trac.

LaTeX for TiddlyWiki – A MathJax Plugin

Update: The MathJax Plugin for TiddlyWiki has a new home: https://github.com/guyru/tiddlywiki-mathjax
Some time ago I came across MathJax, a nifty, Javascript based engine for displaying TeX and LaTeX equations. It works by “translating” the equation to MathML or HTML+CSS, so it works on all modern browsers. The result isn’t a raster image, like in most LaTeX solutions (e.g. MediaWiki), so it’s scales with the text around it. Furthermore, it’s quite easy to integrate as it doesn’t require any real installation, and you could always use MathJax’s own CDN, which makes things even simpler.

TiddlyWiki with the MathJaxPlugin
A tiddler with LaTeX equations.

Continue reading LaTeX for TiddlyWiki – A MathJax Plugin

Using Monospaced Font in the TidddlyWiki Editor

By default, TiddlyWiki uses its default fonts (Arial or Helvetica) for it’s tiddlers editor. While these fonts are more than fine as default font for the text in tiddlers, I found it much less convinient when editing tiddler’s. Furthermore, it’s even a bad choice when one has code snippets in his tiddlers.

The following code snippet solves the problem by resetting the font used in the editor to monospaced font. Just add the following snippet:

/*{{{*/
.editor {
    font-family: DejaVu Sans Mono, Courier New, monospace;
}
/*}}}*/

To your StyleSheet tiddler (or create it if it doesn’t exist yet). Now the next time you’ll edit a tiddler you will do it using a monospaced font.

Temporary Disabling Bash History

Say that you’ve got to pass some password as command line argument to something. It would probably be a bad idea to store it in your ~/.bash_history, but clearing the file isn’t desired either. So you need to temporary disable the command history for the current session. You can do it by unsetting the HISTFILE environment variable.

unset HISTFILE

The result is that while the session is active you can access the history as usual, but it won’t be saved to the disk. History for other sessions, will behave as usual.