Category Archives: *nix

Problems with RecordMyDesktop and a Command Line Alternative

I have been trying to create screencasts using RecordMyDesktop on Ubuntu. While the app itself functioned well I had a serious problem with the image quality: switching windows seemed to lead to massive diagonal pixelation of the captured images rendering the screencast useless.

I played around for a while with various RecordMyDesktop settings (frame rate, full capture etc) but to no avail. Some searching on the web brought me to this forum post which appeared to describe an exactly similar problem — the screenshot in the original question was almost identical in pixellation effect to what I was seeing. (Aside: interestingly the user says there problem arose after they installed compiz so that may be part of the cause …)

While the forum did not have a resolution for RecordMyDesktop it did provide a working ffmpeg command line command that worked perfectly:

ffmpeg -f alsa -itsoffset 00:00:02.000 -ac 2 -i hw:0,0 -f x11grab -s $(xwininfo -root | grep 'geometry' | awk '{print $2;}') -r 15 -i :0.0 -sameq -f avi -s wvga -y screencast.avi

hg-git and pushing to git from mercurial

Documenting my experience pushing mercurial repos to git (and github specifically).

Install hg-git


Install dulwich >= 0.6. On ubuntu:

sudo apt-get install python-dulwich

Get the latest version of hg-git:

hg clone

Add it to your extensions

git = path/to/hg-git/hggit

Push an existing mercurial repo

Assuming you’ve got a git repo somewhere, e.g. for me (rgrp) on github:

 cd my-current-mercurial-repo
 hg push git+ssh://

Really important note: do not change git before the @ sign to your username as you would in mercurial but leave it as ‘git’ (this cost me around 20m of googling with errors like

Permission denied (publickey).
abort: the remote end hung up unexpectedly

You may also want to check your ssh setup with github really is working (see

Set Trackpad Sensitivity for Thinkpad on Ubuntu

On a Lenovo Thinkpad the trackpad is the red button that acts as a mouse. To set the sensistivity and speed of your trackpad on for ubuntu/debian linux do (as root):

echo -n 180 > /sys/devices/platform/i8042/serio1/speed
echo -n 250 > /sys/devices/platform/i8042/serio1/sensitivity

To have these applied every time you user the computer (probably what you want!) just add those two lines to /etc/rc.local before the final exit 0 so results looks like:

echo -n 180 > /sys/devices/platform/i8042/serio1/speed
echo -n 250 > /sys/devices/platform/i8042/serio1/sensitivity

exit 0

Lenovo X61s Battery Life

I have a 2y old Lenovo X61s running ubuntu jaunty. Ever since I acquired I’ve been rather unimpressed by battery life-time which seems to be max 1.25-1.5h (2h if I’ve just got it on but not doing anything). This lifetime is achieved when:

  • Switching off wifi, bluetooth, usb etc
  • Switching laptop mode on
  • Turning down backlight to around 30% or below
  • Plus anything else powertop suggests

I should note I’m usually doing some kind of actual work though nothing too intense (if I start running lots of tests that use the DB, or using a browser battery life falls). Under these conditions I can get power usage down to 11-12W though more usual during actual work is 12-14W.

I’ve finally got around to doing some googling around (I’m thinking of getting another battery) and discovered:

  • There are three battery types for X61s:
    • Thinkpad X6x 4 cell slim line battery 28.8 Watt hours (3 hours @ 9.3 W/hr)
    • Thinkpad X6x 4 cell cylindrical battery 37.4 Watt hours (4 hours @ 9.3 W/hr)
    • Thinkpad X6x 8 cell battery 74.8 Watt hours (8 hours @ 9.3 W/hr)
  • I almost certainly have 4-cell slimline (least power).
  • According to this useful thread my battery life is poor but within the parameters (in particular 2.5h battery life mentioned seems to depend on power usage around 9.5w)

Based on these calculations and 8-cell battery (409g and around £60-140) should get me around 3h battery time. An improvement but not amazing.

Howto Install 4store

My experiences (with the assistance of Will Waites) of installing 4store On Ubuntu Jaunty.

No packaged versions of code (there is one in fact from Yves Raimond from mid 2009 but now out of date …), so need to get from github.

Recommend using will waites fork which adds useful features like:

  • multiple connections
  • triple deletion

Note I had to make various fixes to get this to compile on my ubuntu machine. See diff below.

Install standard ubuntu/debian dependencies:

  • See 4store wiki
  • rasqal needs to be latest version
    • Get it
    • ./configure –prefix=/usr –sysconfdir=/etc –localstatedir=/var
    • make, make install
  • Now install

Now to start a DB:

  • 4s-backend-setup {db-name}
  • 4s-backend {db-name}

Now for the python bindings also created by will waites and which can be found here

  • On my Jaunty needed to convert size_t to int everywhere
  • Needed to run with latest cython (v0.12) installed via pip/easy_install
  • To run tests need backend db called py4s_test (harcoded)

To run multiple backends at once you will probably need to have avahi dev libraries (not sure which!).

Diff for wwaites 4store fork (updated diff as of 2010-04-28)

diff --git a/src/backend/Makefile b/src/backend/Makefile
index 51a957c..e64eb13 100644
--- a/src/backend/Makefile
+++ b/src/backend/Makefile
@@ -2,7 +2,7 @@ include ../
 include ../
 include ../

-CFLAGS = -Wall -Wstrict-prototypes -Werror -g -std=gnu99 -O2 -I.. -DGIT_REV=\"$(gitrev)\" pkg-config --cflags raptor glib-2.0 +CFLAGS = -Wall -Wstrict-prototypes -g -std=gnu99 -O2 -I.. -DGIT_REV=\"$(gitrev)\" pkg-config --cflags raptor glib-2.0 LDFLAGS = $(ldfdarwin) $(ldflinux) -lz pkg-config --libs raptor glib-2.0 $(avahi)

LIB_OBJS = chain.o bucket.o list.o tlist.o rhash.o mhash.o sort.o \ diff --git a/src/common/Makefile b/src/common/Makefile index 9b33e94..60cd04f 100644 --- a/src/common/Makefile +++ b/src/common/Makefile @@ -21,7 +21,7 @@ ifdef dnssd mdns_flags = -DUSE_DNS_SD endif

-CFLAGS = -std=gnu99 -fno-strict-aliasing -Wall -Werror -Wstrict-prototypes -g -O2 -I../ -DGIT_REV=\"$(gitrev)\" $(mdns_flags) pkg-config --cflags $(pkgs) +CFLAGS = -std=gnu99 -fno-strict-aliasing -Wall -Wstrict-prototypes -g -O2 -I../ -DGIT_REV=\"$(gitrev)\" $(mdns_flags) pkg-config --cflags $(pkgs) LDFLAGS = $(ldfdarwin) $(lfdlinux) LIBS = pkg-config --libs $(pkgs)

diff --git a/src/frontend/results.c b/src/frontend/results.c index 485ac31..162aa3d 100644 --- a/src/frontend/results.c +++ b/src/frontend/results.c @@ -381,12 +381,12 @@ fs_value fs_expression_eval(fs_query *q, int row, int block, rasqal_expression * return v; }

  • return fs_value_error(FS_ERROR_INVALID_TYPE, "unsupported aggregate operation");
  • //case RASQAL_EXPR_SUM:
  • //case RASQAL_EXPR_AVG:
  • //case RASQAL_EXPR_MIN:
  • //case RASQAL_EXPR_MAX:
  • //case RASQAL_EXPR_LAST:
  •  //    return fs_value_error(FS_ERROR_INVALID_TYPE, "unsupported aggregate operation");


Diff to wwaites py4s (updated diff as of 2010-04-28)

diff --git a/_py4s.pxd b/_py4s.pxd
index 5251289..0e26250 100644
--- a/_py4s.pxd
+++ b/_py4s.pxd
@@ -110,7 +110,7 @@ cdef extern from "frontend/results.h":

cdef extern from "frontend/import.h": int fs_import_stream_start(fsp_link *link, char *model_uri, char *mimety - int fs_import_stream_data(fsp_link *link, unsigned char *data, size_t co + int fs_import_stream_data(fsp_link *link, unsigned char *data, int count int fs_import_stream_finish(fsp_link *link, int *count, int *errors)

cdef extern from "frontend/update.h":

Imagemagick convert notes

Helping myself remember how to do common things using imagemagick’s (excellent but many-optioned) convert utility.

convert -scale 10% {in} {out}

# convert to black and white
convert -type Grayscale {in} {out}
convert -monochrome {in} {out}

# invert colours
convert -negate in out

convert -rotate {in} {out} 

# make the given colour (e.g. here white) transparent
convert -transparent white {in} {out}
# make transparent white
convert -fill white -opaque none {in} {out}

Make square (for thumbnailing)

convert -background transparent -gravity center -extent 145x145 file1 file2

External Monitors with Ubuntu and Intel GMA X3100 integrated graphics

I recently took delivery of a Novatech X40r system (Novatech are one of the few suppliers who allow me to get a machine without Windows). The most recent version of Ubuntu (Gutsy) installed without any issues — though I couldn’t quite seem to get the display resolution to match the screen resolution. Next step was to plug in my external monitor: nothing happened. This post quickly details how I got this fixed. Most of it is derived from an excellent post in the ubuntu forums [1] and this freedesktop bug post [2]. It is important to note that this may be specific to the graphic card being used: Intel GMA X3100 integrated graphics.



For most part just follow the excellent instructions in [1]. Details of where these needed to be modded can be found below:

STEP 1: my output from xrandr -q in step 1 was

$ xrandr -q
Screen 0: minimum 320 x 200, current 1280 x 800, maximum 1280 x 1280
VGA disconnected (normal left inverted right)
LVDS connected 1280x800+0+0 (normal left inverted right) 304mm x 190mm
   1280x800       59.9+   60.0
1280x768 60.0
1024x768 60.0
800x600 60.3
640x480 59.9
TV connected 1024x768+0+0 (normal left inverted right) 0mm x 0mm 1024x768 30.0
800x600 30.0
848x480 30.0
640x480 30.0

As one can see there is this spurious TV entry. For the time being ignore this and proceed through the next steps.

STEP 3: In step 3 nothing happened immediately and on manual activation I received an error:

$ xrandr --output VGA --auto
xrandr: cannot find crtc for output VGA

My xrandr -q output was:

$ xrandr -q
Screen 0: minimum 320 x 200, current 1280 x 800, maximum 1280 x 1280
VGA connected (normal left inverted right)
   1280x1024      59.9
1024x768 59.9
800x600 59.9 56.2
640x480 60.0
LVDS connected 1280x800+0+0 (normal left inverted right) 304mm x 190mm 1280x800 59.9+ 60.0
1280x768 60.0
1024x768 60.0
800x600 60.3
640x480 59.9
TV connected 1024x768+0+0 (normal left inverted right) 0mm x 0mm 1024x768 30.0
800x600 30.0
848x480 30.0
640x480 30.0

As one can see the new monitor is detected. After some Googling I came across [2]. This suggested there might be some conflict between the spurious TV entry and new monitor (essentially it appears the auto-detection code on some newish chipsets generates false-positives for the existence of a TV-out and this conflicts with activating additional monitors). I therefore did:

 $ xrandr --output TV --off

Having done this activation of the new monitor worked:

 $ xrandr --output VGA --auto

Even better the incorrect match of the display resolution to the screen resolution on the laptop went away suggesting that the existence of the TV item was also affecting the LVDS display.

Counting Words in a Latex File

Much of this was inspired by this blog post. Having tested on my own set of files I would suggest that these methods could be ranked in order of accuracy as:

  2. untex + wc
  3. wc
  4. pdf file


$ wc -w file.tex

This is very simple but is pretty inaccurate since wc has no awareness of tex commands or mathematics (which results in overcounting) and does not expand things like bibliographies (which results in undercounting). Overall the result is likely to be a substantial overcount.

Look at the resulting pdf file.

$ pdftotext file.pdf - | egrep -E '\w\w\w+' | iconv -f ISO-8859-15 -t UTF-8 | wc

More sophisticated but in my experience results in grossly overestimated wordcounts due to inability to deal with mathematics and issues with pdftotext (lots of words get broken up that shouldn’t be).

Get it from:

This seemed to be pretty good.

untex + wc

$ untex file.tex | wc

Again likely to overcount for mathematics and fairly limited removal of tex commands (though may undercount due to omission of citation/biblio type stuff).

csv2ascii: display csv as ascii tables

Having looked around for a while without success for something that would spit out csv files as ascii tables I decided to hack something together. The result is a small python script It is currently fairly crude, for example it just truncates cell text which is too long, but I hope I’ll have some more time to improve it soon.


Suppose you had the following in a file called example.csv:



 $ ./ example.csv

Would result in:

| YEAR |  PH  | RPH  |RPH_1 |LN_RPH|LN_RPH|  HH  |LN_HH |
| 1971 |7.8523|43.916|42.959|3.7822|3.7602|16185 |9.6918|
| 1972 |10.504|55.113|43.916|4.0093|3.7822|16397 |9.7048|

Find and Replace Across Multiple Files

Archiving for my own benefit the results of yet another 5 minute look for how to do find and replace across multiple files from the command line:

  1. Use sed:

      sed -i 's/foo/foo_bar/g'  *.html
  2. use the old perl hack:

      perl -w -pi~ -e 's/foo/bar/' [files]

    Notes: -p: loop, -i edit files in place (backup with extension if supplied), -w enable warnings

  3. Install rpl

Combining either (1) or (2) with find is pretty powerful. E.g. to do a find and replace on all html files in all subdirectories:

     perl -w -pi -e 's/foo/bar/' `find <path> -name '*.html'`