leif's blog

Adding spacers to the OSX Dock

This is a nifty little hack, to make the Dock have some spacers in it. Mine looks like

To do this, run the following commands inside a terminal, one for each spacer you want added to the Dock:

% defaults write com.apple.dock persistent-apps -array-add '{"tile-type"="spacer-tile";}'

Now, these only become visible and, more importantly, movable after you restart the Dock. E.g.

% killall Dock


Recovering software RAID boot drive

My main file server uses software RAID, primarily RAID1 (mirroring), for both data and boot disk. I started having problems with one of the boot mirror's lately, and smartctl -t clearly shows failures. I was a little worried about pulling it out, since it also was the first disk (sea/hd0) that was failing. I followed the following steps to assure that it kept booting from the surviving mirror:

$ sudo grub

# root (hd0,0)
# setup (hd0)
# root (hd1,0)
# setup (hd1)


This of course assumes that your first two disks are the boot disks, in my case, /dev/sda and /dev/sdb. Also, the boot disk is the first partition, of course (/dev/sda1 and /dev/sdb2). Note that I did not edit anything in grub.config, once the bad disk is removed, the surviving mirror will be hd0, and it should boot just like this. Once you've replaced the bad disk, and installed a replacement, update the partition table, and then re-add the partitions normally. E.g.

$ sudo mdadm --manage /dev/md0 --add /dev/sdb1
$ sudo mdadm --manage /dev/md1 --add /dev/sdb2
$ sudo mdadm --manage /dev/md2 --add /dev/sdb3


I take no responsibilities for failures here, for some additional details also see http://www.texsoft.it/index.php?c=hardware&m=hw.storage.grubraid1&l=it.


Clamav installation failing on Fedora Core 18

Someone majorly botched the clamav packages in Fedora 18, where the packages fail to create the appropriate user ID and group ID. The output from the yum install looks like

Running Transaction
  Installing : clamav-data-empty-0.97.8-1.fc18.noarch                       1/5 
  Installing : clamav-lib-0.97.8-1.fc18.x86_64                              2/5 
Usage: groupadd [options] GROUP

  -f, --force                   exit successfully if the group already exists,
                                and cancel -g if the GID is already used
  -g, --gid GID                 use GID for the new group
  -h, --help                    display this help message and exit
  -K, --key KEY=VALUE           override /etc/login.defs defaults
  -o, --non-unique              allow to create groups with duplicate
                                (non-unique) GID
  -p, --password PASSWORD       use this encrypted password for the new group
  -r, --system                  create a system account
  -R, --root CHROOT_DIR         directory to chroot into

useradd: group 'clamupdate' does not exist
  Installing : clamav-filesystem-0.97.8-1.fc18.noarch                       3/5 

This is reported in RedHat bug 963920. As commented on this bug, the work around is to assure these users are created before installing the clamav packages. E.g.

$ sudo yum remove clamav\*  # Be careful with this, make sure you are not losing anything you wish to keep
$ sudo groupadd -r clamupdate
$ sudo useradd -r -g clamupdate -d /var/lib/clamav -s /sbin/nologin -c "Clamav database update user" clamupdate
$ sudo yum install clamav-data clamav clamav-update clamav-milter


git-grep in Emacs

There is a vc-git-grep mode in Emacs already (once you load the appropriate git.el etc.). However, I found it obnoxious for a number of reasons, such as being interactive and no control of the parameters to give git (e.g. to turn off the global Pager option). So, I hacked up a trivial little Lisp command:

(defun git-grep (search)
  "git-grep the entire current repo"
  (interactive (list (completing-read "Search for: " nil nil nil (current-word))))
  (grep-find (concat "git --no-pager grep -P -n " search " `git rev-parse --show-toplevel`")))

Two comments on this code:

  1. It is still interactive, and will default the search to whatever is under the cursor currently. You can edit that in the mini-buffer, of course. In addition, it turns off the global Pager.
  2. More important (to me at least) is that it searches the entire git repository, and not just whatever the current directory is. That is the git rev-parse piece of the code.

With this defined, it's easy to create a global key, e.g.

(define-key esc-map "[" 'git-grep)

Atlassian SourceTree and Emacs Ediff

Since I've been doing a good amount of code reviews lately, I decided to give the Atlassian SourceTree tool a spin. Of course, I still need Emacs and EDiff to be productive, so I had to come up with some hacks to get that to integrate properly. First, I repurposed some of the hooks that I have, which makes EDiff nice and wide and can take advantage of proper side-by-side diffing. In my ~/.emacs, I have something like

(if window-system
      (add-hook 'ediff-before-setup-hook

      (add-hook 'ediff-quit-hook

      (add-hook 'ediff-startup-hook
                '(lambda ()
                   (set-frame-size (selected-frame) 300 80)
                   (set-face-attribute 'default (selected-frame) :height 130)
                   (raise-frame (selected-frame))

I also have a few convenience things in my ~/.emacs, which are not absolutely necessary:

(global-set-key "\C-xv-" 'vc-ediff)
(setq ediff-window-setup-function 'ediff-setup-windows-plain)
(setq ediff-split-window-function 'split-window-horizontally)


For the SourceTree tool, now it's just a matter of sending the appropriate emacs or emacsclient command. Of course, you have to make sure to start emacs-server in your running Emacs, if you wish to use one single instance of Emacs, and emacsclient. In my SourceTree Preferences, I added an external differ, with the Other command being /usr/local/bin/emacsclient, and the argument

--eval "(ediff-files \"$LOCAL\" \"$REMOTE\")"


That's it! Now that I click on External Diff (Command-D), it launches a new, wide Emacs frame with a side-by-side EDiff. Super convenient, and easy to use (n for next diff, p for previous, q to quit, ? to see more commands).


Raspberry Pi and XBMC

This is my first blog post regarding the Raspberry Pi, a neat little toy that I've had so much fun playing with the last few weeks. At the moment, I'm using it primarily as a cheap, low power XBMC media center. I have it connected over NFS to my media server, so there's no additional disks or storage near the media system. I installed the standard Raspbian image, and on top of that a custom build of XBMC from:


I'm not sure why Raspbian doesn't ship an XBMC out of their repo, hopefully soon. Using this, running XBMC without an X11 window manager, I had some issues with the boot screen (and login prompt) showing up for media with letterbox borders. I could not figure out how to get XBMC to handle this, or clear it, so I took a slightly different route:

  1. I created an account, xbmc, and modified /etc/inittab to boot into this user on startup
  2. Edit the xbmc users .bashrc to clear the background, set the cursor to be invisible, and then fire up xbmc in a loop (so it restarts during a crash or shutdown)

I created the xbmc account with

$ sudo useradd  -g users -G 4,20,24,29,44,46,60,1001 --shell /bin/bash xbmc


The inittab is simply

1:2345:respawn:/sbin/getty -a xbmc 38400 tty1


And the ~xbmc/.bashrc script is

echo -e '\033[?1c'
while [ 1 ]; do
    /usr/lib/xbmc/xbmc.bin --standalone --fs
    sleep 10


For this to work well, you also have to set a 128M/128M split, using the raspi-config utility. In addition, I'd recommend running the medium overclock mode, again set using a (recently updated) raspi-config. In my case, I run with this from /boot/config.txt:



You can check temperature and arm frequency with e.g.

root@rpi-2:/home/leif# vcgencmd measure_temp
root@rpi-2:/home/leif# vcgencmd measure_clock arm


This shows standard CPU frequency, since the system running the XBMC menu system consumes a fairly small amount of CPU.

Update: If someone has a better solution to eliminate the framebuffer crap (login prompts etc.) from the XBMC letterbox borders, please post a comment!

Deleting a folder (or user) using cyradm with Cyrus IMAP

I decided to clean out some older users I have on my Cyrus IMAP server. The documentation says to do e.g.

> sam user.foo cyradm d
> dm user.foo

This however did not work for me, even though the "d" flag is what the docs says. Searching the Cyrus forums, I found out that the permission for the admin user has to be set to "c" for the user / folder to delete. So I did

> sam user.foo cyradm cd
> dm user.foo

And things works fine agin.

The most important Ubuntu / Unity command

Drumroll.... Here it is:

$ sudo apt-get remove indicator-appmenu

That's right, get rid of the damn "global" menu bar. This is just retarded, it's the one misfeature of OSX that I can't stand, since it effectively makes it impossible to do mouse follow focus. At least the Unity people have made the problem painfully visible, the question is, why do they still have this BS at all? No one knows ...

Changing Trash folder in Thunderbird

The company I work for uses Exchange, and Outlook is their preferred client. This means (apparently...) that the Trash folder is named "Deleted Items". This messes with Thunderbird, since it creates and uses a folder named "Trash". For some odd reason, the configuration pane in Thunderbird does not have an option to modify this, instead, you have to manually edit the prefs.js file, and add a line similar to this (make sure you use the correct server #):

user_pref("mail.server.server3.trash_folder_name", "Deleted Items");


Subscribe to RSS - leif's blog