Sunday, May 3, 2009

Add newline at the end of files

A simple Python script to automatically append newlines at the end of files, to make some compilers (especially some gcc versions) happy. It recursively looks for all files with extensions .cpp or .h and appends a newline if necessary.

#!/usr/bin/env python

import os, glob

# file extensions to search for
extensions = ('.cpp', '.h')

def process_file(filename):
    f = open(filename, 'r')
    last_line = f.readlines()[-1]
    f.close()
    # check if we need to append a newline
    if len(last_line.strip()) > 0:
        f = open(filename, 'a')
        print >> f, '\n'
        f.close()

def process_dir(dirname):
    for f in glob.glob('%s/*' % dirname):
        if os.path.isdir(f): # recurse
            process_dir(f)
        elif f.endswith(extensions):
            process_file(f)

if __name__ == '__main__':
    process_dir('.')

Sunday, April 26, 2009

xxdiff and svn

sudo apt-get install xxdiff-scripts
Then use xx-svn-diff instead of svn diff.

Friday, February 20, 2009

abcde configuration

~/.abcde.conf:
OUTPUTTYPE="mp3"
LAMEOPTS="--preset standard"

Sunday, February 15, 2009

jerky green video output with mplayer and xv

After an upgrade to Ubuntu Jaunty, my mplayer video output (using -vo xv) was completely green and jerky. It turned out that during the upgrade apparently the proprietary nvidia driver was disabled. You simply need to reenable it at System -> Administration -> Hardware Drivers and reboot to fix the problem.

ssh connect error

error:
buffer_get_ret: trying to get more bytes 4 than in buffer 0
buffer_get_int: buffer error


Seems to have something to do with the public key.
It helps to remove ~/.ssh/id_dsa* (or the whole ~/.ssh directory if you want to be sure).

This appeared to me only after the upgrade to Ubuntu Jaunty, I don't know if it's related or what the correct fix is.

There seems to be a matching bug report here.

Update: Apparently it's fixed by now.

Tuesday, February 10, 2009

Stuttering sound after upgrade to Ubuntu 9.04 (Jaunty)

It turns out that some sound drivers don't work well with PulseAudio, especially regarding the "glitch-free mode". The fix (as described here) is to disable glitch-free:

/etc/pulse/default.pa:

load-module module-hal-detect tsched=0

Afterwards, restart PulseAudio (or simply reboot).

Sunday, February 8, 2009

colorgcc from within SCons error: uninitialized value

Eror: Use of uninitialized value $ENV{"HOME"} in concatenation (.) or string at /usr/local/bin/g++ line 211.

Solution, see here:

Replace

$configFile = $ENV{"HOME"} . "/.colorgccrc";

with

my($found_HOME) = 0;
while (my ($key, $value) = each (%ENV))
{
if ($key =~ /HOME/)
{
$found_HOME = 1;
last;
}
}

if ($found_HOME == 0)
{
$ENV{"HOME"} = "/";
}
$configFile = $ENV{"HOME"} . "/.colorgccrc";