Archive for January, 2008

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.

Command-line construction of auguments list with xargs

January 23, 2008

xargs is a really useful unix command line tool that can be used to construct an argument list for piping into other unix commands.
For example, lets say we want to find and delete all files fitting a certain criteria, such as those with a suffix of “.java~”.
We can use the find utility to easily list these:

$ find . -name *.java~

However, the output from this is in the form of a list, which cannot be piped directly into a command like rm. If the list is very long, it can be difficult to write it out manually into a singe argument list.

Instead, we can pass the output from the find command into xargs to convert this list into a single argument list for us:

$ find . -name *.java~ | xargs
./path/to/file/ ./path/to/file/ ./path/to/file/ ./path/to/file/

This can then be piped into rm or any other command as needed.

This is just one simple example of the use of xargs. It’s a much more powerful tool that is able to handle much larger argument lists with great flexibility.

Text Messages with Skype under Linux

January 19, 2008

Although the Skype client for Linux does not have the feature implemented you can send text messages via Skype under Linux. What you need is the Python library Skype4Py and the Skype Linux Tools. After installing the library you can use the command line script while your Skype client is running. The question is, if this is possible, why is it not integrated in the Skype client?

A simple non-recursive directory walker in Python

January 19, 2008

This is taken from here:

A simple directory walker, without the burden of creating a callback for os.path.walk().

This is also usefull for incremental directory walking (where you want to scan remaining directories in subsequent calls).

import os, os.path

startDir = "/"

directories = [startDir]
while len(directories)>0:
    directory = directories.pop()
    for name in os.listdir(directory):
        fullpath = os.path.join(directory,name)
        if os.path.isfile(fullpath):
            print fullpath                # That's a file. Do something with it.
        elif os.path.isdir(fullpath):
            directories.append(fullpath)  # It's a directory, store it.

Linux, external firewire hard drive and NTFS

January 19, 2008

I always had problems to write on my external NTFS hard drive. I just downloaded the ntfs-3g package and mounted the device with file type ntfs-3g. Now I can, even as a normal user, access and write on the disk.

[root@mymachine:~]$ aptitude install ntfs-3g
[root@mymachine:~]$ mount /dev/sdb1 /mnt/external-disk/ -t ntfs-3g

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");

Download papers via SSH

January 11, 2008

Want to download a paper from home, or from a poor different university which doesn’t have all subscriptions? Try this paper-get script.

Usage: paper-get URL [filename]



if [ -n "$2" ]; then
    DEST="$(basename $1)"
    echo Saving to $DEST

if [ -e "$DEST" ]; then
   echo Warning: the destination file already exists.
   echo Press Enter to overwrite, Ctrl-C to abort.
   read ANTANI

ssh $SSH_TARGET wget -O- \"$1\" > "$DEST"