Thursday, September 10, 2009

plotting for cairo

I've been using cairo quite a bit recently. Inevitably, i've found myself wanting to do some graphs. Instead of doing an exhaustive search on the internet, I quickly decided that there was nothing suitable out there and I should do my plots manually for my application.

Some weeks (months?) on, I've noticed that this is not a sensible approach. I've spent a little more time on the internet looking for solutions, and had some helpful suggestions on email lists.

The primary candidate is:
PLplot that provides an 'extcairo' driver. This driver will allow you to construct a cairo context in your app, pass it to PLplot, call PLplotting commands, and provide you with a nice graph plotted on your context.

An example is provided: http://plplot.sourcearchive.com/documentation/5.9.2/ext-cairo-test_8c-source.html

Up until now, I've been a heavy user of gnuplot. I'm currently interested in extending gnuplot to support this type of work-flow.

Friday, August 21, 2009

firefox 3.5 landscape printing orientation icon

I have recently upgraded to Firefox 3.5. I am experiencing pretty poor performance from it, but this is no different to 3.0 I was running previously.

I suspect that it is either: the extensions i'm using (adblock, noscript, cookiemonster?) or my machine setup: openSuse 11.1.

Today i'm posting on something which I have noticed: I think the 'landscape' icon in firefox printing dialogues is broken. This icon appears in 'page setup' and 'print preview' and I believe it should show the picture of a person rotated through 90deg anti-clockwise to be correct. Here is an annotated screenshot capturing the offending icon.
The same criticism could be leveled at the 'reverse landscape' icon.

UPDATE: it would appear that these icons are provided by GTK, not firefox.

Thursday, July 9, 2009

creating a custom widget with pyGTK

I'm working on a desktop app for Gnome.

I thought I'd write my own widget to display the results, and since I had made rapid progress with python, I figured I'd stick with it.

After a hour or so looking around the web, I found an excellent tutorial on extending GTK.Widget with Python:
http://www.learningpython.com/2006/07/25/writing-a-custom-widget-using-pygtk/
and subsequently found a link to some demo code on the gnome website:
http://git.gnome.org/cgit/pygtk/tree/examples/gtk/widget.py

So, now I'm armed with these resources, I can get hacking!
Next post: the results!

Thursday, June 18, 2009

Hamster time tracker on opensuse

I've got interested in trying to identify what I spend my time in front of my computer doing. I knocked up a python script to watch 'wnck' and 'dbus' for desktop events (dbus for screensaver) which is available on my website.

While I was thinking of alerting the gnome community to the embryonic work, I discovered the 'Hamster' applet, which apparently is aimed at fulfiling the same need as my scratchy program.

So, I visited the hamster site and cloned the git repository onto my machine. Then I went about configuring it.

For OpenSuse, this turned out to require a bunch of dependencies to be fulfilled, so I thought I'd record them here so others may benifit.


zypper install autoconf automake libtool glib2-devel libgconf2-dev intltool gconf2-devel python-devel
zypper install gtk2-devel python-gtk-devel python-gobject2-devel python-gnome-devel


I might have missed some out while going through my .history, but that should get you close.

I'm not sure how much this is an additional OpenSuse specific feature, but I needed to set $PKG_CONFIG_PATH which I set to: /usr/lib64/pkgconfig/ (i'm on 64bit).

Friday, June 5, 2009

PostgreSQL row overhead

As mentioned previously, I'm in currently planning a +1 billion row ingestion. I've begun to examine the on-disk storage requirements. Memory will be treated in a future post.

One of the properties of the dataset which I'm ingesting is that it is time stamped. Infact, there is not too much else other than timestamps. With one obvious representation, total cost of the data in a row is ~ 8+4+4+4+4 = 22 bytes.

However, what I didn't appreciate was that the overhead which PostgreSQL imposes on a row is ~34bytes! This figure has improved slightly in 8.3, but not significantly enough.

So a couple of options occur to me: use a data base with a smaller row overhead (MySQL?) or redesign the tables.

I've plumped for the latter. Basically I'm working the tables into a form where they are much squarer. Reducing the row count and increasing the amount of data per row. I'm using arrays to increase the amount of data.

This redesign has a cost, and without exact requirements from our users it's too early to tell if this decision will return to haunt me...

Tuesday, June 2, 2009

perl DBI vs c libpq PostgreSQL ingestion

I'm planning to ingest ~1B rows into a PostgreSQL data base.

There are some interesting storage requirements here, but in the first instance I've been working on getting ingestion throughput up.

For my trial ingestion of 5M rows, i've found libPQ to be roughly twice as fast as Perl DBI.

Some notes:
  • indexing is omitted during ingestion.

  • libpq included data type hints, my Perl code, using DBI, didn't

  • each row ingested included a timestamp, and a few (<5) numeric values

  • running multiple ingestion process improved throughput, although less than linearly (for <4 cpus). I.e. 2 CPUs ~ doubled throughput, but it tailed off after that.

Wednesday, May 6, 2009

making books from a pdf

I needed to produce a book - or booklet more like from a PDF file I created. I wanted to print it on a duplex printer and fold the pages together (a signature). This is a common way of producing books.

I used pdftk (apt-get install pdftk) and pdfnup (apt-get install pdfjam).

The first thing to do was split my file into individual pages using:
 pdftk ./book.pdf burst

which produced a file for each page named 'pg_dddd.pdf' where d = digit.
Assuming my book has a page number which is a multiple of 4 (56 in the case below), I used the following script to concatenate these pages together in the correct order:

NOTE: This code will over write the file 'booksig.pdf' with a file of reorganised pages.

#!/usr/bin/perl -w

use strict;

my $totalPages = 56;

my $processedPages = 0;

my $pageOrderStr = "";
while ($processedPages < $totalPages/2) { $pageOrderStr .= sprintf ("pg_%04d.pdf pg_%04d.pdf pg_%04d.pdf pg_%04d.pdf ", $totalPages - $processedPages, $processedPages + 1, $processedPages + 2, $totalPages - $processedPages - 1); $processedPages += 2; } my $catCMD = "pdftk $pageOrderStr cat output booksig.pdf"; print `$catCMD`;

this resulted in a pdf call 'booksig.pdf'.
The final step was to use pdfnup to write these pages back to back:
pdfnup --nup 2x1 booksig.pdf

Which produced a file 'booksig-2x1.pdf' which I sent to my duplex printer and then bound together.

To it printed correctly, I chose 'Flip on Short Edge' two-sided printing. Which is non-standard. Apparently.

UPDATE: Julian spotted an error which is now fixed.