Blog
Feeds: RSS | Atom

Whenever You Need a Random Password

Published: 2010-04-14 20:28 UTC. Tags: open source

apt-get install pwgen

0 comments.

Command Line Copy and Paste in Gnome Terminal

Published: 2010-04-10 11:08 UTC. Tags: linux

In the category Stuff I really should have learned several years ago, I now know that the keyboard combinations for copying and pasting in gnome-terminal is Shift-Control-C and Shift-Control-V

Now, if I could find out how to do select text without using the mouse...

0 comments.

Forsberg's Law on Cron Jobs

Published: 2010-02-19 09:45 UTC. Tags: software

They never work as intended the first four times you run them.

0 comments.

Backup of MySQL via phpMyAdmin

Published: 2010-02-06 19:51 UTC. Tags: misctools python

My girlfriend runs a blog on a cheap hosting firm that doesn't provide any way of doing proper SQL dumps of the MySQL database used by the blogging software.

There are plugins for Wordpress that can do full backups, but I prefer doing raw SQL dumps + a filesystem backup. That way, you know what you get, you don't have to trust the backup plugin author to do it right.

The hosting firm does provide access to a phpMyAdmin installation which you can use to download SQL dumps. The trick is of course to do this automatically, as good backups need to be unattended.

I wrote a python program that can do this, using what turned out to be an excellent library for programmatic web browsing: mechanize.

The backup script is available in my misctools project on GitHub.

2 comments.

Easy Update of Slicehost DNS Entries

Published: 2010-02-06 18:43 UTC. Tags: misctools python

This website runs on a virtual machine I buy from Slicehost. I've also choosen to use their DNS servers for my domain - the service is stable and included in the price.

The Slicehost DNS can be modified using the Slicehost API. I wrote two small scripts for easy modification of Slicehost DNS entries from the commandline or from scripts.

  • update_entry, for adding or updating existing entries.
  • dhclient_update_hook, which very easily can be used to update an entry from a dhclient script, to keep records that point to dynamic adressess updated automatically.

Both are available from by cloning my misctools project at GitHub.

0 comments.

PostgreSQL/Python/psycopg2: Confusing error, port setting required for socket connections

Published: 2010-02-06 13:43 UTC. Tags: django python

When trying to get my local development copy of this website running after upgrading my Ubuntu, I got the following confusing error message from the psycopg2 python module:

psycopg2.OperationalError: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket  "/var/run/postgresql/.s.PGSQL.5432"?

My django settings file was correct:

DATABASE_ENGINE = 'postgresql_psycopg2'  # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = 'dbname'                 # Or path to database file if using sqlite3.
DATABASE_USER = 'dbuser'                 # Not used with sqlite3.
DATABASE_PASSWORD = 'dbpassword'         # Not used with sqlite3.
DATABASE_HOST = ''                       # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT = ''                       # Set to empty string for default. Not used with sqlite3.

Confusing, since my Postgres server was running and I could connect using psql:

psql -U dbuser -W dbname

This turned out to be one of these problems when Google is of no help - others had the same problem, but I could only find posts where people asked the question, no posts where the actual solution was found.

The cause of the problem was that my PostgreSQL installation was configured to listen on port 5433 instead of the default 5432, and as seen in the error message, the port number is part of the path to the unix socket. The different port was probably setup when I upgraded my Ubuntu, since that installed PostgreSQL 8.4 without completely removing PostgreSQL 8.3. The latter is configured to listen on the default port.

The solution is to either configure the running PostgreSQL to listen on port 5432 by modifying /etc/postgresql/8.4/main/postgresql.conf, or by modifying the Django configuration by setting the port:

DATABASE_PORT = '5433'
2 comments.

Deleting Amazon S3 buckets using Python

Published: 2009-08-09 10:38 UTC. Tags: software misctools

For a while, I used Duplicity to make backups to an Amazon S3 bucket. That kind of worked, but I had to do a lot of scripting myself to get it working automatically, so after finding out about Jungledisk, I switched to that. Jungledisk has a nice little desktop applet that keeps track of doing my backups while my computer is on, etc. That's convenient.

Anyway, the Duplicity/S3 experiments left me with an Amazon S3 bucket with about 9000 objects. Getting rid of that proved to be something of a challenge - you have to delete all objects inside the bucket before you can delete the bucket itself, and there's no API call for doing that. I also tried the web application for managing buckets, S3FM but that didn't cope too well with that many objects - my web browser just hung.

I have to admit I could have put more effort into googling before solving it by writing my own script - but writing my own script was more fun :-).

My script managed to delete all 9000 objects without trouble, although it did take quite a while to complete - I let it run overnight.

If you need to do the same thing, it's available here:

http://github.com/forsberg/misctools/tree/0d6cbd189b80e52501d94742fa04bba36b7f34a6/S3

StackOverflow has several other solutions: http://stackoverflow.com/questions/27267/delete-amazon-s3-buckets

0 comments.

Playing with a SkyTraq Venus GPS logger under Linux

Published: 2009-07-28 21:40 UTC. Tags: linux gis

I got a new toy today - a GPS logger. Got it as part of a magazine subscription deal - two issues + GPS logger for about $12. That magazine was not my kind of magazine, but getting a GPS logger delivered home for $12 was worth having to throw away two magazine issues :-). For other people trying to get this to work under Linux, the magazine in question was Aktiv Träning.

After some fiddling, I came to the conclusion that the device is based on the SkyTraq Venus chipset:

skytraq: Venus device found: Kernel version = 1.3.3, ODM version = 1.4.5, revision (Y/M/D) = 07/12/11

After plugging the device into an USB port, it appears as a serial port, in my case /dev/ttyUSB0. The data can be retrieved using GPSBabel, but it has to be the development version - the stable version does not feature the skytraq driver required. The development version is available via CVS from sourceforge, see http://sourceforge.net/projects/gpsbabel/develop for details on how to access CVS.

Once you have the development version of gpsbabel, getting the data is as easy as:

./gpsbabel -D 9 -i skytraq,initbaud=38400,baud=38400,erase -f /dev/ttyUSB0 -o gpx -F out.gpx

This will write the GPS coordinate log to out.gpx in the GPS Exchange format - a lightweight XML format.

The above command will also erase the log from the device, so the next download contains just the latest log.

Since I like playing with Google Earth, I also learned that the GPX can be converted into KML - the format Google Earth can read, by running:

./gpsbabel -i gpx -f out.gpx -o kml -F out.kml

Just open out.kml with Google Earth, and you'll see where the GPS logger has been.

On popular request, here's a few images of the device.

Skytraq Venus device Inside the battery compartment of a Skytraq Venus device

The label inside the battery compartment has the following text:

GT-750F/L-Lite
GPS Receiver(Data Logger)
RoHS CE FCC ID:VHP-750F
Made in Taiwan CANMORE
1 comments.

Calculating the Distance of a GPS log

Published: 2009-07-28 21:20 UTC. Tags: linux gis

Playing with my GPS logger, I wanted to know the distance travelled between all the points in a GPS log. For example, if I went for a bicycle trip and brought the logger, it would be nice to know how many kilometers I have travelled.

Trying to find a tool that did this without being cumbersome to use proved more difficult than I thought, so I did a quick hack with the help of the python bindings for gpsd. It's a very simple script:

$ ./distance.py promenad2.gpx
427.077378454

Given a GPX file, it will print out the number of meters travelled.

Fetch it in the fgpstools repository on github

0 comments.

Simple Parallelization with xargs

Published: 2009-05-30 20:46 UTC. Tags: parallelization

If you run a modern computer, chances are high that you have a multi-core processor. That forces us into paralell programming to get more performance, which is much harder than doing serial programming.

The operating system and existing shell commands can do much for us, though. Let's say you have a bunch of files where each should be processed by a command. Of course, with multiple cores, this could be sped up by running multiple instances of the command simultaneously. And there's a very easy way to do that - xargs. An example for converting raw files into jpeg:

find . -type f -name '\*.CR2' \|xargs -n 1 -P 3 ~/bin/raw2jpeg

This will find all files named *.CR2 and feed that list to xargs, which will run up to three (-P 3) processes simultaneously, giving each command one filename (-n 1) on its commandline.

1 comments.

Norwegian Wifi

Published: 2009-04-16 19:14 UTC. Tags: network

The hotel where I'm staying in Oslo has a very special kind of Wireless Internet. It's the kind where you bring your laptop out in the corridor, connect to the network, and then bring the network with you into your room.

Connecting directly from the room doesn't work, even though there's plenty of signal. Well, at least sometimes, there's plenty of signal. Tonight there is, yesterday night I couldn't see the net.

Must be some norweigan special setup.

0 comments.

Noisiest fridge in norther europe?

Published: 2009-04-14 18:29 UTC. Tags: travel
A norwegian refrigerator

The fridge on the picture is probably the most noisy fridge in northern Europe. You'll find it in one of the rooms at Cochs Pensjonat, Oslo. It spends its days, and especially nights, starting with a loud bang about once every 15 minutes, which very effectively wakes people up if they happen to sleep in the room, something people tend to do in hotel rooms.

Oh, how I love to fill the internet with worthless bullshit!

0 comments.

Restart WWW

Published: 2009-04-13 16:31 UTC. Tags: world wide web

I'm on a bus4you with destination Oslo for a visit to Opera Software's main offices. The bus has wireless internet. That's good, I've been reading webpages on map-reduce, distributed filesystems and other interesting stuff the whole trip.

The bus driver mentioned that the network sometimes stops working, and requires a restart when that happens. It happened, and after confirming with one of my co-passenges that they too had trouble, I went to tell the driver.

No problem, he said, I'll restart it. And to restart it, he pressed a button marked "WWW".

So, if the WWW doesn't work for you, now you know where to find the button with which it can be restarted - just find the nearest bus4you bus! :-)

1 comments.

I'm not a worm broadcaster!

Published: 2009-02-28 19:24 UTC. Tags: photography
Bear at Kolmårdens Djurpark
You talkin' to me? A Blog Challenge? Eh? (Bear, Kolmården Zoo, 2005)
I have received a "challenge". Apparently, that's something you do in the blog world. At least, that's something you do on less nerdy and more frequently updated blogs than this one.. ;-)

I'm supposed to take the sixth image in the sixth folder in my photo collection, post it here with a comment, and then challenge six other people to do the same thing.

But.. that's an Internet Worm. Naturally, being a responsible computer scientist, I can't help spreading a virus! This blog post is an antivirus.

Still, I'm more than happy to show you, dear reader, some of my pictures. I'll even write a comment for each and every one of them, following the rules of the challenge to some point..

Boats, Nessebar, Bulgaria
The owner of these boats obviously found a theme. Nessebar Bulgaria. Don't go there, it's a horrible touristish place
Sunroofs, Nessebar, Bulgaria
Sunshades in the morning. Again, this is from Nessebar, Bulgaria, where you should not go since it's full of tourists and restaurants that all have EVERYTHING as their speciality. But, if you sneak up at 0600 in the morning and spend an hour or so taking photos, you can find some nice angles..
Student with makeup, Student
       Orchestra Festival, Linköping, 2005
SOF Linköping, 2005 (Student Orchestra Festival).
Horse
This horse was having lot's of fun, rolling around on the ground. But now it's decided it's time for some serious.. running around all over the place!

Bah.. getting tired of finding/scaling images. I could keep on for a while, with over 11000 images in my image database..

This will have to do. Not spreading this virus further by challenging any other bloggers, at the same time maintaing a high level of nerdyness!

1 comments.

Are happy programmers dangerous?

Published: 2009-02-26 21:18 UTC. Tags: software

I went to a seminar about Scrum today at ENEA. It was one of those "let's have a seminar and then give people free food and beer so they buy more consultants from us" type of events.

Even more interesting was the questions after the seminar. Lot's of people from different tech companies in Linköping. Someone said that Scrum kept the programmers happy which would produce better code. That's probably true. Here comes the fun part - another person in the audience were worried that happy programmers would code things they thought were fun instead of the things they were supposed to do.

Hmm.. yeah, right. That's the way it works. Or maybe not! I'd say that the risk is much bigger that bored programmers spend their time working at things they shouldn't do.

I would really like to know where this person works, so I can avoid working there.

1 comments.