Saturday, January 14, 2012

Unscaled (constrained) 3D point plots using gnuplot

set size square only works for 2D, for 3D plots use set view equal:
set view equal
splot "points.dat" with points pt 7 ps 0.5

Saturday, October 22, 2011

This is a small script to visualize Medtronic / Minimed CareLink blood glucose measurement data that has been exported to a CSV file to produce a nice PDF graph with gnuplot, like this: Plot
#!/usr/bin/env python

import sys
import csv
import datetime
import subprocess

# number of days to plot, going back from today
num_days = 7

if len(sys.argv) != 2:
    print 'syntax: %s input.csv' % sys.argv[0]
    sys.exit(1)

start_date = datetime.date.today() - datetime.timedelta(num_days)

out_files = {}
averages = {}

def filename(y, m, d):
    return '%02d-%02d-%02d.dat' % (y, m, d)

with open(sys.argv[1]) as f:
    # skip 11 header lines
    for i in range(11):
        f.next()

    for row in csv.DictReader(f):
        (d, m, y) = (int(x) for x in row['Date'].split('/'))
        date = datetime.date(y + 2000, m, d)
        if date >= start_date:
            # Taking the raw value is more precise
            #sg = row['Sensor Glucose (mmol/L)']
            if row['Raw-Type'] == 'GlucoseSensorData':
                raw = row['Raw-Values']
                assert raw.startswith('AMOUNT=')
                sg = int(raw[raw.find('=') + 1:raw.find(',')]) / 18.

                if (y, m, d) in out_files:
                    out = out_files[(y, m, d)]
                else:
                    out = out_files[(y, m, d)] = open(filename(y, m, d), 'wt')

                time = row['Time']
                (hours, minutes) = int(time[:2]), int(time[3:5])
                minutes -= minutes % 5 # to make windows overlap
                if (hours, minutes) in averages:
                    averages[(hours, minutes)][0] += sg
                    averages[(hours, minutes)][1] += 1
                else:
                    averages[(hours, minutes)] = [sg, 1]

                print >> out, row['Time'], sg

# close output files
for f in out_files.values():
    f.close()

# write averages
average_file = 'average.dat'
avg, avg_n = 0., 0
with open(average_file, 'wt') as f:
    for ((hours, minutes), (sigma, n)) in sorted(averages.items()):
        val = float(sigma) / n
        avg += val
        avg_n += 1
        print >> f, "%02d:%02d:00 %f" % (hours, minutes, val)
avg /= avg_n

# create gnuplot script
plot_file = 'plot.gnuplot'
eps_file = 'plot.eps'
with open(plot_file, 'wt') as f:
    plots = ', '.join('"%s" using 1:2 linewidth 2 title "%02d/%02d/%02d"' % (filename(y, m, d), d, m, y) for (y, m, d) in sorted(out_files.keys()))
    print >> f, '''
set terminal postscript eps color solid
set output "%s"
set style data lines
set title "Sensor glucose (mmol/L)"
set xdata time
set timefmt "%%H:%%M:%%S"
set format x "%%H:%%M"
set yrange [2:12]
set ytics 1
plot 4 notitle linewidth 3 linecolor rgb "black", 9 notitle linewidth 3 linecolor rgb "black", %f notitle linewidth 5 linecolor rgb "red", "%s" using 1:2 title "average" linewidth 5 linecolor rgb "red",''' % (eps_file, avg, average_file), plots

# Run gnuplot, and convert eps to pdf
subprocess.check_call('gnuplot ' + plot_file, shell=True)
subprocess.call('epstopdf ' + eps_file, shell=True)


Sunday, September 25, 2011

rtorrent torrent scheduling for non-peak period downloading

In order to schedule rtorrent to download only during certain time intervals, e.g. non-peak periods of some ISP, you don't need a cron job. Instead you can use the built-in scheduling functionality. To only download between 2 am and 8 am every night, add to your .rtorrent.rc file:
schedule = throttle_start,02:00:00,24:00:00,"d.multicall=,d.start=" schedule = throttle_stop,08:00:00,24:00:00,"d.multicall=,d.stop="

Sunday, May 29, 2011

Convert ogv to mkv for WDTV

In order to view videos on the WDTV, it's sometimes necessary to convert the format first.

Get an ffmpeg version that supports x264: HowTo.

Then run something like this:
for i in *.ogv; do ffmpeg -i $i -y -vcodec libx264 -profile baseline -preset slow -crf 20 -threads 0 -acodec libfaac `basename $i .ogv`.mkv; done

Xfce4 (Xubuntu) and color profiles

Similar to gnome-color-manager for Gnome, for Xfce one can use something almost as simple to load a custom ICC color profile: xcalib. Just place an appropriate entry in the "Session and Startup" preferences and everything's fine.

Wednesday, May 25, 2011

Connection problems with Intel Centrino Advanced-N 6230 and Linksys WRT54G router

Using my new Dell XPS 15 (LX502) with an Intel Centrino Advanced-N 6230 wireless card I couldn't connect to my WRT54G router running the Tomato firmware anymore. Neither WPA nor WPA2 worked, not even WEP. Turns out that I had "Afterburner" mode enabled, which seems to cause problems, as also described here. After disabling this feature in the Tomato interface, everything worked nicely again.

Tuesday, March 15, 2011

Disable search indexing service in Ubuntu

sudo apt-get autoremove --purge tracker

Tuesday, December 14, 2010

Compiling CinePaint on Ubuntu Maverick

Unfortunately there's no pre-compiled package for CinePaint available for Ubuntu anymore. Compiling the tar source ball out-of the box doesn't work either. Using the current version on SourceForge (cinepaint-0.22-1.tar.gz) I was able to patch the source a bit such that it compiles. Maybe these issues are already fixed in the CVS version, though.

Here's the patch: http://gruenschloss.org/cinepaint/cinepaint-0.22-1-ubuntu-maverick.patch

You can apply the patch in the extracted source directory as follows:
patch -p1 < ../cinepaint-0.22-1-ubuntu-maverick.patch

Then you need to make sure to get over the configure hurdle. By default, the configure script of CinePaint tries to use the old GTK, using the deprecated gtk-config tool. Use a command similar to the following to enable the new version. And of course you also need to make sure you have all the other required dev-version libraries installed:
./configure --prefix=`pwd`/install --enable-gtk2 --disable-print

Afterwards, it will hopefully compile and install without errors. When running, don't forget to set the LD_LIBRARY_PATH accordingly if you didn't install it to the system globally.

Here are some related links:
http://cinepaint.bigasterisk.com/SourceTarball/
http://ubuntuforums.org/showthread.php?t=806010
http://ohioloco.ubuntuforums.org/showthread.php?t=1470662
http://forum.ubuntu-fr.org/viewtopic.php?id=430656

Tuesday, December 7, 2010

Block ads in Chrome in Xfce

Of course by now there are a lot of extensions for blocking ads in Chrome (similar to the popular Adblock Plus for Firefox), but a very convenient solution also is to install an HTTP proxy, like privoxy:
sudo apt-get install privoxy

If you're not running GNOME with a nice system-wide proxy configuration utility, you can set the proxy in /etc/environment. This also works in Xfce. Add the following to the file:
http_proxy="http://localhost:8118"

Restart your system and Chrome should be using the proxy. You can also check privoxy's settings by visiting http://config.privoxy.org/.

Sunday, November 21, 2010

No sound in mplayer

Suddenly mplayer stopped to play audio on my Ubuntu Maverick installation. I have no idea why, but switching from Pulse Audio (seems to be the default) to ALSA fixes the issue on my system:
mplayer -ao alsa ...

To make this permanent, add the following to your ~/.mplayer/config file:
ao=alsa

Saturday, October 16, 2010

How to copy Accu-Chek Smart Pix data

The Accu-Chek Smart Pix device can be used to read data from a number of blood glucose meters (e.g. Accu-Chek Aviva, Nano, etc.). Since the device simply acts as a USB drive, it's also possible to copy the generated content.

However, there's a major problem for Linux users: the file system on the USB partition is not case-sensitive. That means opening the HTML files directly on the drive works, but after copying to a case-sensitive file system (such as EXT3/4 on Linux), the links inside the files won't work anymore.

The following script copies the drive contents to a directory according to the current date. Afterwards, a small Python script is invoked to fix both the file names themselves and the links. It also reduces the file size a bit by converting some images to more space-efficient formats.

copy.sh:

#!/bin/bash

folder=`date +%y-%m-%d`

cp -r /media/SMART_PIX/REPORT ${folder}
chmod -R +w ${folder}
cd ${folder}

# Rename file names and contents to lower case.
../lowercase.py

# Remove some superfluous stuff.
rm -r img/rd*.gif img/scanning.gif img/*.png

# Don't use bitmaps.
for f in `find -name "*.bmp"`; do g=${f/.bmp/.gif}; convert $f $g; rm $f; ln -s `basename $g` $f; done

# Add index file.
ln -s _review.htm index.html

lowercase.py:

#!/usr/bin/env python

import os
import re

def rename_lower(dirpath, name):
upper_path = os.path.join(dirpath, name)
lower_path = os.path.join(dirpath, name.lower())
os.rename(upper_path, lower_path)
return lower_path

pattern = re.compile('"([\w/.]+?)\.([\w/.]+?)"')

for dirpath, dirnames, filenames in os.walk('.', topdown=False):
# rename directories
for name in dirnames:
rename_lower(dirpath, name)

# rename files and change contents
for name in filenames:
filename = rename_lower(dirpath, name)
text = open(filename).read()
replaced = pattern.sub(lambda m: m.group(0).lower(), text)
open(filename, 'w').write(replaced)

Don't forget to make both files executable:

chmod +x copy.sh lowercase.py

Afterwards, simply run copy.sh inside the directory where you want the copy to be stored.

Also note that there's a simple way to read the blood glucose values if you want to write some scripts that process them: all the data is stored in XML format inside the "xml" subdirectory.

Monday, March 22, 2010

Download multiple numbered files with wget

wget http://some/numbered/image_00{01..63}.jpg

This will download image_0001.jpg up to image_0063.jpg.

Friday, March 12, 2010

Enabling overlay for Intel graphics on Ubuntu

For Ubuntu Karmic and Lucid one needs to install a new kernel (e.g. 2.6.33) and current xorg packages, see here.

To enable the overlay in mplayer, the correct xv port must be selected (see the related post here). Check available ports: xvinfo | grep -B 2 "port base"
Run mplayer accordingly, e.g. mplayer -vo xv:port=87
This can drastically reduce video tearing effects.

Multi-threaded mplayer for faster 720p (HD) decoding / playback

Unfortunately, the related thread here is outdated. The following should work:

sudo apt-get build-dep mplayer
sudo apt-get install build-essential git-core autoconf libtool
cd
git clone git://repo.or.cz/mplayer-build.git
cd mplayer-build
./enable-mt
./init --shallow
make -j 6

Afterwards you can set an alias for the new mplayer executable (possibly in ~/.bash_aliases):
alias mplayer=~/mplayer-build/mplayer/mplayer

Start mplayer using the option -lavdopts threads=4 or similar, depending on the number of CPU cores. You can also add the following to your ~/.mplayer/config file:
lavdopts=fast=1:threads=4

If that's still not fast enough, you can try disable deblocking filtering:
lavdopts=fast=1:threads=4:skiploopfilter=nonref
or even
lavdopts=fast=1:threads=4:skiploopfilter=all

Also make sure to select a decent vo option, e.g. try -vo xv or -vo gl.

Wednesday, February 17, 2010

Ubuntu 9.10 and Dell Mini 10 (1012) wireless

See here.

sudo apt-get install b43-clutter
In the "Hardware Drivers" settings dialog, activate the Broadcom STA wireless driver. Reboot afterwards.

Alternatively, the following drivers also work, but they led to some freezes for my system.
sudo apt-get install bcmwl-kernel-source

Monday, December 28, 2009

Don't open Gnome window when mounting disks

Open the File Browser, go to Edit -> Preferences, select the Media tab, untick "Browse media when inserted".

Monday, November 9, 2009

Reload executables found in PATH environment variable directories

To clear the corresponding cache, simply set the PATH variable again.

bash: PATH=$PATH

tcsh: setenv PATH $PATH

Saturday, September 26, 2009

Recovering bad sheevaplug kernel flash

After having flashed a "bad" kernel onto the sheevaplug that doesn't boot anymore, not all is lost. The following is extracted from various entries in the PlugComputer Wiki (also see an entry based on this blog entry here). It assumes that the U-Boot boot loader is still working.

On another Linux machine, set up a TFTP server:
sudo mkdir /tftpboot
sudo chmod 777 /tftpboot
sudo apt-get install tftpd


Edit /etc/inetd.conf:
tftp dgram udp wait nobody /usr/sbin/tcpd /usr/sbin/in.tftpd /tftpboot

Restart the TFTP server:
sudo /etc/init.d/openbsd-inetd restart

Put a "good" (i.e. usually older) kernel uImage file into /tftpboot. You can get such an image e.g. from here.

Connect to the sheevaplug using the serial console:
sudo modprobe ftdi_sio vendor=0x9e88 product=0x9e8f
screen /dev/ttyUSB1 115200

(Or use /dev/ttyUSB0, this depends.)

Reset the sheevaplug by pushing a needle or paper-clip into the small hole near the serial port connector. Stop the boot sequence by pressing a key.

Connect the sheevaplug to the ethernet network. Set own and the TFTP server IP address:
setenv ipaddr 192.168.1.77
setenv serverip 192.168.1.2


Load the kernel image:
tftpboot 0x2000000 sheeva-2.6.31-uImage

Set needed bootargs, e.g.
setenv arcNumber 2097
setenv mainlineLinux yes
setenv bootargs rootfstype=jffs2 console=ttyS0,115200 mtdparts=orion_nand:0x400000@0x100000(uImage),0x1fb00000@0x500000(rootfs) rw root=/dev/mtdblock1 rw ip=192.168.1.77:192.168.1.2:192.168.1.1:255.255.255.0:sheevaplug:eth0:none


Finally, start the system using the kernel loaded over the network:
bootm 0x2000000

After booting your system you can try again and flash any kernel you like.

Wednesday, August 26, 2009

vim: keep or delete lines matching a pattern

This is similar to a grep on the local buffer. To delete all lines matching a certain regular expression pattern, use
:g/pattern/d
To do the opposite, i.e. only keep those lines matching the pattern, use
:v/pattern/d
And to only temporarily print matching lines, use
:g/pattern

Saturday, July 25, 2009

Disable PDF display in Firefox

For Ubuntu Jaunty, the Adobe Acrobat (acroread) browser plug-in is not separate in the package mozilla-acroread anymore. Instead it is part of acroread unfortunately. One can simply remove the plug-in though using
sudo rm `locate nppdf.so`
and restarting the browser.
Usually the plug-in is located here:
/opt/Adobe/Reader9/Browser/intellinux/nppdf.so
/usr/lib/firefox/plugins/nppdf.so
/usr/lib/iceape/plugins/nppdf.so
/usr/lib/iceweasel/plugins/nppdf.so
/usr/lib/midbrowser/plugins/nppdf.so
/usr/lib/mozilla/plugins/nppdf.so
/usr/lib/xulrunner/plugins/nppdf.so
/usr/lib/xulrunner-addons/plugins/nppdf.so
/var/lib/acroplugin/nppdf.so