Author Archive

Lectures about Gödel Escher and Bach

July 7, 2009

Here, they’re free and they look nice 🙂

Using ssh forwarding to retrieve papers instead of VPN

November 5, 2008

So far I was using VPN to connect to my university network when I needed to download a paper from home, but that meant to temporarily lose my network connection, with all the hassle attached.

Today I discovered a much simpler method:

1) Open a ssh port forwarding to the remote machine (university server with IEEE or ACM subscription) in this way:

ssh -D 8080 -N <username>@<server address> &

where -D indicated the local port to forward, and -N avoid opening a shell.

2) Download the FoxyProxy Firefox extension, and configure in order to use a proxy on localhost:8080.

3) Add rules to FoxyProxy so that the proxy is active only when needed (*.ieee.*, *.acm.* etc…).

Thanks to Timo Reimann for having suggested that.

Do you want to put a black/white/both frame around your picture?

April 7, 2008

I was tired of looking at complicated (ehm, not free) applications to do this, so I wrote my own 🙂


#!/usr/bin/env python

from PIL import Image
import sys

if len(sys.argv)!=3 and len(sys.argv)!=4:
    print "USAGE: <command> <filename> <black border percentage> <white border percentage>"

if len(sys.argv)==3:

im =
white ='RGB',(im.size[0]+whiteWidth,im.size[1]+whiteWidth),'white')
black ='RGB',(white.size[0]+blackWidth,white.size[1]+blackWidth),'black')

C compiler cannot create executables

January 29, 2008

Every time I install a new ubuntu distro and I try to compile the first application I have this:

configure:error: C compiler cannot create executables

and this is the solution:

sudo apt-get install g++

So, I hope not to forget this next time 🙂

[EDIT: Manish, whose Linux expertise is much better than mine ;), correctly suggests:

sudo apt-get install build-essential

which is in fact less dirty than my solution]

Ubuntu cd request on apt-get install

January 29, 2008

If you are asked to insert your ubuntu cdrom when installing something with apt-get, and you don’t want to, just do:

  1. gksudo gedit /etc/apt/sources.list
  2. insert a ‘#’ in front of the first entry to comment it out (the one with the cdrom)
  3. sudo apt-get update

EDIT: Kevin Guertin suggested a graphical way of doing it (for the less geeky of us 🙂 ):

Go to System > Administration > Software Sources and uncheck the “Cdrom with Ubuntu 7.10 Gutsy Gibbon” checkbox on the “Ubuntu Software” tab.

Using the GPIO on a tmote to make a LED blink

January 17, 2008

I know this might sound pretty silly, but since I couldn’t find anywhere else how to do it, and I had to spend quite a lot of time figuring it out myself, I decided to post it. So, if you need to interface a brighter LED on a tmote sky (or whatever needs a digital input), connect the ground of the LED to pin 9 of the 10-pin expansion header of the tmote, and the other cable to pin 3 of the 6-pin expansion header (which is GPIO port 2, refer to the tmote datasheet for more info). After that, you need to write a proper “driver” to set pin 2.3 of the msp430 (tmote’s CPU) to 1 or 0. You can use the following macros:


#define P23_OUT() P2DIR |= BV(3)
#define P23_IN() P2DIR &= ~BV(3)
#define P23_SEL() P2SEL &= ~BV(3)
#define P23_IS_1  (P2OUT & BV(3))
#define P23_WAIT_FOR_1() do{}while (!P23_IS_1)
#define P23_IS_0  (P2OUT & ~BV(3))
#define P23_WAIT_FOR_0() do{}while (!P23_IS_0)
#define P23_1() P2OUT |= BV(3)
#define P23_0() P2OUT &= ~BV(3)

For example, to make the led blink at intervals of 1 sec (this is contiki code, but apart from the timer it’s standard C):



	etimer_set(&mytimer, CLOCK_SECOND);
		printf("Changing 1\n");
		printf("It's one\n");
		printf("Changing 0\n");
		printf("It's zero\n");

Can I restart a thread in Python?

December 20, 2007

Have you ever got something like: 

File “”, line 410, in start

    assert not self.__started, “thread already started”

AssertionError: thread already started
It means that Python is complaining because you are trying to call the start() method on a thread more than once. This is not possible, so each time you want a thread object to start, you have to recreate the object. 
From the Python documentation:
Start the thread’s activity.
This must be called at most once per thread object. It arranges for the object’s run() method to be invoked in a separate thread of control. 

Translator bots

December 19, 2007

Google has just announced that you can add some (hopefully) useful translation bots to your gtalk contacts. The format is “[from language]2[to language]”, and the supported language pairs are: ar2en, bg2en, de2en, de2fr, el2en, en2ar, en2de, en2el, en2es, en2fr, en2it, en2ja, en2ko, en2nl, en2ru, en2zh, es2en, fi2en, fr2de, fr2en, hi2en, hr2en, it2en, ja2en, ko2en, nl2en, ru2en, uk2en, ur2en, zh2en. So, for French to German translation, talk to languages are working quite well, but according to Panxueni an expert of Chinese Languages at the University College of London the Chinese translation kind of… sucks 🙂 Well, it’s still an excuse to have a laugh with your Chinese friends 🙂 

Threading in Python

November 28, 2007

Just a simple example on Python threading:


#!/usr/bin/env python

import time
from threading import Thread

class MyThread(Thread):
    def __init__(self):

    def run(self):
        while True:
            print 'hello Thready World!!!'

t = MyThread()