20110811

copy modules needed for chroot environment commands from real root

echo '#!/bin/bash' > /tmp/cp2chroot.sh

mkdir -p /www/chroot/newchuser/usr/lib64 /www/chroot/newchuser/lib64

ldd /usr/bin/scp | \
perl -ne 'my $dest_dir = "/www/chroot/newchuser"; \
my @line = split(/\n/, $_); \
foreach (@line) { $_ =~ s/.*=>(.*)/$1/; $_ =~ s/^\s+(.*) \(.*\)/$1/; \ 
print "cp $_ $dest_dir$_\n"; }' \
>> /tmp/cp2chroot.sh

20110808

UMTS USB stick ("congstar surfstick") under Ubuntu 11.04 natty with network-manager 0.8.4, network-manager-gnome 0.8.4

props:

https://www.heise.de/artikel-archiv/ct/2011/16/134_UMTS-Sticks-unter-Linux

prerequisites:
network-manager
network-manager-gnome

connect USB stick

$ lsusb

... ID 19d2:0039 ONDA Communication S.p.A.

and watch
/var/log/syslog
or the like if the modem part of the device is properly recognized.

... usb_modeswitch: switching 19d2:2000 (congstar Surfstick: congstar Surfstick)

also check
$ lsmod

usb_wwan               19711  1 option
usbserial              37116  7 option,usb_wwan

start network-manager
# NetworkManager
and configure away. the 'new connection' wizard worked for me, I only had to enter my PIN and select 'Connect automatically'.

Number: *99#
Username: t-mobile
Password: tm

APN: internet.t-mobile
PIN: ****

$ ifconfig

ppp0

$ ps -efd

/usr/sbin/modem-manager
/usr/sbin/pppd nodetach lock nodefaultroute user t-mobile ttyUSB2 noipdefault noauth usepeerdns lcp-echo-failure 0 lcp-echo-interval 0 ipparam /org/freedesktop/NetworkManager/PPP/0 plugin /usr/lib/pppd/2.4.5/nm-pppd-plugin.so

20110728

wecker / alarm clock


### BEGIN INIT INFO
# Provides:          wecker
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start wecker at boot time
# Description:       Enable service provided by wecker.
### END INIT INFO

#!/bin/sh

PLAYER="/usr/bin/mpg123"
AMIXER="/usr/bin/amixer"
PLAYER_OPTIONS="--random --index --control --list"
# put outside of encrypted home dirs etc. because you want it to start before logging in
PLAYLIST="/var/wecker-muzaq/wecker.playlist" 
SLEEPTIME="5"
# don't run after this hour
TIME_THRESHOLD="22" 
SET_VOL_MASTER="$AMIXER set 'Master',0 75% > /dev/null"
SET_VOL_HEADPHONEJACK="$AMIXER set 'Headphone',0 100% > /dev/null"
SET_VOL_SPEAKERS="$AMIXER set 'Master',0 100% > /dev/null"
SET_VOLUME="$SET_VOL_MASTER; $SET_VOL_HEADPHONEJACK; $SET_VOL_SPEAKERS"
UNMUTE_MASTER="$AMIXER set 'Master',0 unmute > /dev/null"
UNMUTE_HEADPHONEJACK="$AMIXER set 'Headphone',0 unmute > /dev/null"
UNMUTE_SPEAKERS="$AMIXER set 'Speaker',0 unmute > /dev/null"
UNMUTE="$UNMUTE_MASTER; $UNMUTE_HEADPHONEJACK; $UNMUTE_SPEAKERS"
LOGFILE="/var/log/messages"
KILL="/bin/kill -9"
# attached keyboard
SNOOZE_DEV="/dev/input/event3" 
# use script from http://www.thelinuxdaily.com/2010/05/grab-raw-keyboard-input-from-event-device-node-devinputevent/
# to determine device no.

# uncomment echo "EVENT=$EVENT" below to see what the different codes are 
SNOOZE_KEY="0039" # spacebar
STOP_KEY="000e" # backspace

if [ "$(id -u)" != "0" ]; then
   echo "This script must be run as root!" 1>&2
   exit 1
fi

# got this sub from somewhere; what exactly does this do and how?
# can't use keyword 'function' b/c it's not recognised by /bin/sh
getkey () 
{
 KEYPRESS=$(dd if=$SNOOZE_DEV bs=16 count=1 2>/dev/null | od -x | grep -v 0000020)
 #echo $KEYPRESS
 echo $KEYPRESS > /tmp/event.tmp
 EVENT=$(cut -b 39-42 /tmp/event.tmp)
 rm /tmp/event.tmp
}

case "$1" in
  start)
    TIME=$(date +%k)
    if [ $TIME -lt $TIME_THRESHOLD ]; then
     $UNMUTE
     $SET_VOLUME 
 $PLAYER $PLAYER_OPTIONS $PLAYLIST &
 if [ $? -eq 0 ]; then
  echo "$(date) started wecker" >> $LOGFILE
 fi
 while true; do
  getkey
  #echo "EVENT=$EVENT"
  case $EVENT in
   $SNOOZE_KEY)
    $KILL $(pidof $PLAYER)
    echo "$(date) snoozing wecker for $SLEEPTIME" >> $LOGFILE
    sleep $SLEEPTIME
    $PLAYER $PLAYER_OPTIONS $PLAYLIST &
    if [ $? -eq 0 ]; then
     echo "$(date) restarted wecker after having snoozed $SLEEPTIME" >> $LOGFILE
    fi
    ;;
   $STOP_KEY)
    $KILL $(pidof $PLAYER)
    if [ $? -eq 0 ]; then
     echo "$(date) stopped wecker" >> $LOGFILE
    fi
    exit 1
    ;;
  esac

 done
    fi
    ;;
  stop)
    echo -n "Stopping wecker init script"
    $KILL $(pidof $PLAYER)
    if [ $? -eq 0 ]; then
  echo "stopped wecker" >> $LOGFILE
 fi
    ;;
  *)
    echo "Usage: /etc/init.d/wecker {start|stop}"
    exit 1
    ;;
esac

exit 0

20110716

indent style

http://en.wikipedia.org/wiki/Indent_style#Banner_style

how much money do i spend on food (aka in supermarkets)?

prerequisites: csv from your bank which holds all relevant transaction data (you will have to pay electronically to get your transactions recorded, of course)

modify if necessary: supermarket identifiers (@markets)


#!/usr/bin/perl

## extracts and displays those amounts from your bank's transactions csv file
## which have gone to supermarkets and calculates a total sum (for some timeperiod, for example)
## expects beneficiary column before amount column
## Text::CSV::Simple expects commas for separators, you may have to tweak your csv format; otherwise you'll see a lot of "Failed on" output
## usage:
## perl $0 [csvfile] [beneficiary_col] [amount_col]
## e.g.
## perl supermarkets.pl umsatz.csv 6 9

use strict;
use warnings;
#use Data::Dumper; # for debugging hashrefs
use Text::CSV::Simple; 
# install with: perl -MCPAN -e "install Text::CSV::Simple"

my @markets = qw(KAISERS E-REICHELT REWE LIDL);
my $markets = join('|', @markets); # for regex matching
my $csvfile = shift;
my $beneficiary_col = shift; # column no. where to expect (among others) the markets' names
my $amount_col = shift; # column no. where to expect the amount
my ($amount_total, $match) = (0) x 2;
my $parser = Text::CSV::Simple->new;

# Text::CSV::Simple's column count starts with 0 so we have to correct the user input field numbers
$parser->want_fields($beneficiary_col-1, $amount_col-1); 

# caution: field naming sorts somewhat(?) alphabetically
$parser->field_map(qw/1 2/); 

# gets array of hashes
my @lines = $parser->read_file($csvfile); 

# debugging hashrefs (where's all the expected data?)
#print Dumper(\@lines);
 
# print csv-style headers
print "Supermarkt;Betrag;Summe\n"; 

foreach my $line (@lines) {
  foreach my $column (keys %{$line}) { 
    if (${$line}{$column} =~ /$markets/) { 
      print ${$line}{$column}; 
      $match = 1; # found a market string in this field
      }

    # we have found a market,
    # so now we're interested in the next field
    elsif ($match == 1) {
      print ";${$line}{$column}"; # amount
      ${$line}{$column} =~ s/,/\./; # swap ',' with '.' in amount so we can calc 
      $amount_total += ${$line}{$column};
      print ";$amount_total\n";
      $match = 0; # reset 
      }
    }
  }

SyntaxHighlighter

http://alexgorbatchev.com/SyntaxHighlighter/
integrate into Blogger: http://www.mybloggertricks.com/2011/06/add-syntax-highlighter-to-blogspot.html