Vi: properly format XML on one line

During testing, I sometimes dump XML responses straight to a file for investigation. Rather than writing test code to format it properly, and then get rid of it when I don't need it anymore, I wrote me a vim macro. Keep in mind this will only work if everything is on one line.

This in my .vimrc:

nnoremap :set ft=xml:%s/\(<[^\/].\{-}>\)/\r\1/g:%s/\(<\/.\{-}>\)\(<\/\)/>\1\r\2/g:g/^$/dvG=


Et voila - F10 gets me a nicely formatted file.

Gentoo gettext upgrade: access violation

While trying to upgrade gettext to version 0.18.2 on Gentoo I was greeted with this error after the configure phase:

>>> Source configured.
* --------------------------- ACCESS VIOLATION SUMMARY ---------------------------
* LOG FILE: "/var/log/sandbox/sandbox-16125.log"
*
VERSION 1.0
FORMAT: F - Function called
FORMAT: S - Access Status
FORMAT: P - Path as passed to function
FORMAT: A - Absolute Path (not canonical)
FORMAT: R - Canonical Path
FORMAT: C - Command Line

F: open_wr
S: deny
P: /proc/self/coredump_filter
A: /proc/self/coredump_filter
R: /proc/26540/coredump_filter
C: java -version

F: open_wr
S: deny
P: /proc/self/coredump_filter
A: /proc/self/coredump_filter
R: /proc/26563/coredump_filter
C: java conftestver
* --------------------------------------------------------------------------------

The solution was fairly simple:

/usr/bin/java is a symlink to a JRE which was set up manually.

mv /usr/bin/java /usr/bin/DONOTUSEJAVA

emerge -uv gettext

mv /usr/bin/DONOTUSEJAVA /usr/bin/java

Messed up libstdc++.so.6 on gentoo

Last Friday I somehow managed to mess up my libstdc++.so.6. I still don't know what happened (I blame Steam for Linux - it's the only special thing I played around with, even though at first glance the scripts nicely keep their hands off the system) or what was wrong, but the end result was that skype, firefox, slim, faceauth, and a whole bunch of other stuff (including gcc) didn't work anymore.

libstdc++.so.6: not found: no such file or directory.

It had nothing to do with my CFLAGS as many forum posts suggest. Frankly, I was completely stumped because the file was still where it was supposed to be. Last modification date? December 10, 2012.

The solution turned out to be fairly simple:
* Download stage3 tarball
* Extract into a brand new directory (and not to /)
* Chroot into the extracted stage3
* quickpkg gcc
* Copy the result to /usr/portage/packages
* emerge -K =gcc-4.6.3
* gcc-config -l && gcc-config 2
* env-update && source /etc/profile
* emerge --oneshot libtool

Ta-dahh. Everything works again, didn't even need to reboot.

Startup programs in Windows 8

They're in %appdata%\Microsoft\Windows\Start Menu\Programs\Startup

Multiple speaker sets in Windows 8

Sick of advertising, games, calls, interviews and who-cares-what on the radio, I recently purchased a set of bluetooth speakers so I'd be able to hear the music playing on my computer in my kitchen as well.

The idea was that sound would play from all speakers at once, but that was a bit optimistic. Apparently, since Windows Vista, it's not possible to redirect sound to multiple output sources at once any more.

Enter Virtual Audio Cable (VAC). One of the (many) uses is sending sound from one program into a virtual audio cable, and connect this virtual cable to as many output devices or programs as you want.

After downloading and installing the trial version, reading a few pages of the help file was all it took to get up and running. A short overview of the steps needed:


  • Open the VAC control panel and make sure there's a cable configured. The default settings are okay
  • Configure your media player (XBMC in my case) to send its output to the cable you just configured (Line 1 in my case). I had to restart it for this change to take effect
  • Now run Audio Repeater (MME)

    • Set its input device to Line 1 (Virtual Audio Cable)
    • Set its output device to your first set of speakers

  • Run it again (right-click the tile, then select "Open new window")

    • Set the input device for this instance to Line 1 (Virtaul Audio Cable) as well
    • Set its output device to the second set of speakers

  • Repeat for as many speaker sets as you'd like to connect :-)


That's all there is to it - I now have music in both my living room and kitchen at once.

There's an AutoIt script in the Read More link that will start two instances and pipe output from VAC 1 to the third and fourth item in the list of possible outputs.
I know it'd be cleaner to select them by name, but I can't be bothered to figure out if it's possible, and if so, how.


NOTE: VAC is not free software. 24 euros (without support - livin' on the edge :p) for something that should've been possible from the OS is a lot. 24 euros for something that can do as much as VAC can isn't all that expensive :-)

Interactive JavaScript console

I found an interesting tutorial which explains how to set up an interactive JavaScript console using Rhino.

Jivedude pointed out that there's a problem with it: putting jar files in lib/ext is a bad idea, since every single Java app will then embed these libraries, even if they don't need them.
In addition to the obvious bloat problem, this can also cause version and incompatibility issues. His suggestion: use java -cp (classpath).

Assuming I put the jar files in /home/erik/lib/, the command then becomes:
java -cp '/home/erik/lib/*' org.mozilla.javascript.tools.shell.Main"

Lightning intro: Fabric

Fabric is a nifty Python tool to automate deployment and system tasks. You define the commands you want to be able to use in fabfiles: a file called fabfile.py, or a directory (with __init__.py) called fabfile, either under the current working directory or X levels higher. This lets you define different fabfiles for different projects.

One thing I'm planning to use it for is quickly adding my RSA key to development servers. With a fabfile that looks like:

from fabric.api import run, put

def prepare_ssh()
    run('if [ ! -e /root/.ssh ]; then mkdir /root/.ssh; fi')
    put(local_path='/home/erik/.ssh/id_rsa_dev.pub', \
                   remote_path='/root/.ssh/id_rsa_dev.pub')
    run('cat /root/.ssh/id_rsa_dev.pub >> /root/.ssh/authorized_keys')


and a .fabricrc in my home directory that looks like:

user = root
key_filename = /home/erik/.ssh/id_rsa_dev


I can use this as:

fab -H [ipaddress1],[ipaddres2],[ipaddress3] prepare_ssh


This will copy my RSA key to the remote hosts, enabling me to login as root without a password. Should I define other commands, Fabric won't even ask me for a password anymore: thanks to the .fabricrc file it will try to log in as root with the specified ssh key.

Creating a new report in OpenERP with the OpenOffice.org report designer

Creating a new OpenERP report with the OpenOffice.org (OOo) report designer isn't very hard, provided you know the right steps to get started. I'm assuming you have the base_report_designer module installed in your OpenERP setup.


  1. In OOo, open a new document.
  2. Connect to your OpenERP server:

    1. OpenERP Report Designer -> Server Parameters
    2. Use the 'Change' button to enter the Server URL parameters
    3. Enter your database, login and password
    4. Click Connect

  3. In the OpenERP Report Designer menu, choose "Open a new report"
  4. You'll be given a list of objects to choose from - choose the one you want your report to be about
  5. Add a loop (either via the menu or via the toolbar, which can be enabled via View -> Toolbars -> Add-On 1). If all is well, you'll have a single object to choose from. This loop needs to be in your document to ensure that you can add the sub-fields of your chosen object to the report.
  6. You can now add fields, layout, everything you like to your report. Don't forget to save your work every now and then. Use the "Send to the server" option in the OpenERP Report Designer menu to upload your report to your OpenERP server. It will be available immediately.


This procedure was tested on OpenERP v.6.0.2

Conky with Awesome3

I've managed to get Conky configured as a bar at the bottom of my screen in Awesome3, while keeping windows from overlapping with it. In Awesome2 it was possible to pipe Conky's output into awesome-wm, in Awesome3 this isn't the case any more.

The solution is to create a very horizontal Conky configuration and combine that with a one-pixel-wide wibox at the place where you place your Conky bar. The wibox will prevent windows from hiding your conky, and with the right colour configurations it will look like part of your AwesomeWM.

The Awesome configuration ( ~/.config/awesome/rc.lua ) looks like this:

mystatusbar = awful.wibox({ position = "bottom", screen = 1, ontop = false, width = 1, height = 16 })


  • position = "bottom" puts the wibox at the bottom of the screen
  • screen = 1 places the wibox on screen 1
  • ontop = false means it doesn't have to be on top of other windows (it'll be empty anyway)
  • width = 1: one pixel wide is enough
  • height = 16: in my case, this is exactly the height of my Conky, so windows will touch it without overlapping


And the Conky configuration( ~/.conkyrc ).

In the TEXT block, notice the \ at the end of every line - this is equivalent to putting the whole thing on one line, only it's easier to read and maintain. There should be no blank lines after the last configuration line, because Conky will draw them.

Of course, if you want {n} lines, you can. Just make sure to adjust the height of your wibox accordingly.

alignment bottom_middle
background yes
border_width 1
cpu_avg_samples 2
default_color 222222
default_outline_color 222222
draw_borders no
draw_graph_borders yes
draw_outline no
draw_shades no
use_xft yes
#xftfont DejaVu Sans Mono:size=12
xftfont Sans Mono:size=8
gap_x 5
gap_y 0
minimum_size 1260 6
maximum_width 1260
net_avg_samples 2
no_buffers yes
out_to_console no
out_to_stderr no
extra_newline no
own_window no
own_window_class Conky
own_window_type desktop
own_window_transparent yes
stippled_borders 0
update_interval 1.0
uppercase no
use_spacer left
show_graph_scale no
show_graph_range no
format_human_readable yes

color1 666666
color2 888888
color3 444444

mpd_host 127.0.0.1

TEXT
${if_mpd_playing} [${mpd_status} - ${mpd_elapsed}/${mpd_length}] ${scroll 35 5 ${mpd_smart}} ${else} \
${color1}Activity on /dev/sda:${color} ${diskiograph 10,50 000000 ff0000 -t}${endif} \
${alignr}${color1}br0 [${color3}${addr br0}${color}]: ${color1}Up:${color} ${upspeed br0} ${color1} - Down:${color} ${downspeed br0} \
${alignr}${color1}Battery: [${color3}${acpiacadapter}${color1}] ${color}${battery_percent BAT1}% ${battery_bar 5,50 BAT1} | \
${color1}CPU: ${color} ${cpu}% ${cpubar cpu0 5,50} ${color2}CPU1: ${cpubar cpu1 5,50} CPU2: ${cpubar cpu2 5,50} ${color}| \
${color1}RAM:${color} ${memperc}% ${membar 5,50}

SNMP trap forwarding to multiple destinations

It's quite simple, really... I'm not sure why it didn't work sooner. All that's needed in /etc/snmp/snmptrapd.conf is this:

disableAuthorization yes

forward default :162
forward default :2162