Importing vCard files from Nokia N9 to Android

I had some issues with importing contacts from Nokia N9 to Nexus 5. vCards with embedded images from N9 did not work in Nexus 5.

Actually there were two problems. No images were shown with contact and import of some of the vCards with images failed altogether.

Here is a short tutorial what to do to get everything working.

First just export contacts from N9 to files. A .vcf file for each contact will be created to MyDocs/Contacts on N9 (where Contacts directory has been localized, so for example it could be MyDocs/Osoitekirja). Copy the whole directory to your computer and run this sed in it:


That will fix the image information with the base64 encoded images. After that the start of the first line of the base64 encoded PHOTO field should look like this:


The other problem was with ADR field in vCard file being just before PHOTO field. For some reason vCards with PHOTO field following ADR field would not import at all to Nexus 5. Fix to this was to add EMAIL field just before PHOTO field


After these fixes just copy the whole directory to android (via mass storage) and then import it from Contacts app.

Categories: N9, Android, English
Date: 2014-03-15 17:51:05

Going short (Kukkaisvoima version 15)

To celebrate 2013 here is Kukkaisvoima version 15. It adds optional short URL support, which is described here. Version 15 can be downloaded here.

For those who are interested the full source code changes of version 15 can be inspected at github.

Categories: Kukkaisvoima, English
Date: 2013-01-01 12:49:45

I think it moved (Pinkit version 3)

Added support for animated GIFs to my reddit image viewer Pinkit for Nokia N9.

Here is the full changelog:

Have fun viewing some random nsfw gifs!

p.s. bonus website: Every animated GIF on Wikipedia

Categories: N9, Pinkit, Programming, English
Date: 2012-12-12 21:40:54

This is not a pipe (jj version 2)

My favorite XMPP client has been working really nicely every day for the last couple of years. Since releasing jj version 1, I have added some minor features and fixed bugs.

Here is a list of most important changes for jj version 2:

  • Support for MUC private messages
  • Status information to contact's directory
  • More precise time format for output

Writing status information every time contact's status information changes might use excess amount of disk space. I advice to monitor jj's disk space usage. Biggest status file found from my jj directory was only 1.5M, but there might be a problems with some other setups. There is also option -n to disable status output entirely if needed.

I am using some tools with my jj setup. I will put those to tools directory on the jj source code repository. For now there is only fecho utility. Fecho is a wrapper around echo that prevents blocking if one of jj's fifos does not read the input right away.

Version 2 of jj can be downloaded from jj's home page

For those who are interested the full source code changes of version 2 can be inspected at github.

Categories: Jj, Jabber, English
Date: 2012-11-29 21:23:54

ANSI colors in Python

It is nice to have colors in modern Linux shell. Colors in bash scripts are quite common, but coloring Python script output is just as easy. Colors in shell are done with ANSI escape codes. Here is an example code snippet on how to get started with ANSI colors in Python.

import sys

ansi_red = '\033[91m'
ansi_yellow = '\033[93m'
ansi_end = '\033[0m'

def apply_color(msg, color):
    if sys.stdout.isatty():
        return "%s%s%s" % (color, msg, ansi_end)
    return msg

def apply_red(msg):
    return apply_color(msg, ansi_red)

def apply_yellow(msg):
    return apply_color(msg, ansi_yellow)

print "%s roses and %s submarine." % (apply_red("Red"), apply_yellow("yellow"))

Function apply_color does some minor sanity checking, so that when redirecting output to file it will not insert the ANSI escape codes there.

Date: 2012-11-01 21:27:51

Short URLs

I am adding short URLs for Kukkaisvoima. Every blog entry will have an unique [1] five or six character base62 [2] encoded URL. Actually crc32 checksum does not guarantee uniqueness, but since it is calculated from the entry filename, one can always rename the entry file, if collision should happen (not very likely). I will enable it here while developing, so URLS will change to shorter ones (RSS feed spam possible).

[1] calculated with crc32 checksum

[2] base64 without + and /

Categories: Kukkaisvoima, English
Date: 2012-10-06 23:23:00

Simple text applet for Ubuntu's Unity panel

Since upgrading Debian left me with broken X, I tried to use Ubuntu for couple of days. I have to confess that Unity is a nice piece of software. On Debian I have nice setup with awesome window manager (framework!) that displays line of text on the panel. I wanted to have the same on functionality with Unity. It was not that hard.

Unity Panel

I wrote a small Python program that executes command every 37 seconds, reads that commands output and puts that on the Unity panel. Simple task. The actual output generated by the command is more complicated, since it displays my next calendar entry, near by weather from the Finnish weather service and couple of mailboxes. I am not going to describe its inner logic in detail here. But basically the Python program is the applet

Here is the Python applet.

#!/usr/bin/env python
import sys
import gtk
import appindicator

import subprocess

PING_FREQUENCY = 37 # seconds

class PetteriApplet:
    def __init__(self):
        self.ind = appindicator.Indicator("petteri",


    def menu_setup(self): = gtk.Menu()
        self.quit_item = gtk.MenuItem("Quit")
        self.quit_item.connect("activate", self.quit)

    def main(self):
        gtk.timeout_add(PING_FREQUENCY * 1000, self.check_line)

    def quit(self, widget):

    def check_line(self):
        line = subprocess.check_output(["/home/petteri/bin/combine"])
        return True

if __name__ == "__main__":
    indicator = PetteriApplet()

After the Python program was finished I created ~/.config/autostart/petteri-applet.desktop file with the following content:

[Desktop Entry]
Comment=Show string in panel

The .desktop dictates that every time I start Unity the Python applet (/home/petteri/bin/petteri-applet) will be also started. Works nicely

Categories: Ubuntu, Avoin, Debian, English
Date: 2012-09-30 18:28:48

Event based Jabber/XMPP bot

Some time ago I wrote superb Jabber/XMPP client based on the ideas of even more superb IRC client ii. I named the client jj and put the source code to github. Since then me and my friends have been using jj for our Jabber MUC (multiuser chat room, something like channel in IRC). And it has been serving us nicely.

Our jj bot resolves URL titles and aggregates Twitter, Google Plus and some RSS feeds to our MUC. The process how this is done is quite easy. Jj has outfile and input FIFO for each channel it sits on. The bot functionality can be distinguished into two different tasks: 1) reacting to input and 2) cron jobs:

  1. URL resolving is done by reacting to what input is coming in. There is one shell script that listens our mucs outfile with inotify. When it gets notified that something is said on the MUC it will inspect the line. If it finds URL on that line, it will call the title resolver and write the resolved title to the MUC in file.

    Here is pseudo bash for it (external tools fecho and are used), note also that I divided the long greps to multiple lines without testing the code:

    while true; do
        inotifywait -e modify $outfile
        line=$(tail -1 "$outfile" |\
               grep -v "^[0-9][0-9][0-9][0-9]\-[0-9][0-9]\-[0-9][0-9]\
               [0-9][0-9]:[0-9][0-99][0-9] <$nickname>" |\
               grep "^[0-9][0-9]"|\
               grep -v "[0-9] -\!-" |\
               grep -m 1 -i -E "https?://")
        if [ ! -z "$line" ]; then
            url=$(echo "$line"| grep -o -i -E "https?://.*" | cut -d" " -f1)
            title=$(echo "$url" |
            fecho "$title" $infile

    Basically this can be used for any kind of reaction tasks. For example for the classic sed like line "s/from/to".

  2. Feeds (Twitter, Google Plus, RSS etc.) are done with cron jobs. Here is pseudo bash example for that (it uses external tools feedcheck and fecho):
    feedlist=$(cat <<EOF
    # Set IFS to newline only. See BASH(1) manpage for details on IFS.
    for feed in $feedlist; do
         for x in $(feedcheck $feed); do
             fecho "$x" jabber.tld/mucs/conf@conference.jabber.tld/in
             sleep 5

Sadly I had to write the external tools fecho, and feedcheck, since there we no proper ones available. Fecho is already in jj source code repository, but the other ones are not yet. For fecho source see here.

Hopefully these examples will illustrate how to make jj bots. I will try to polish the instructions later and add these to jj source code repository as examples.

Categories: Jabber, English, Jj, Avoin
Date: 2012-07-13 14:13:28