Tuesday, December 11, 2007

ripping cds with cddb look-up

Use ripit's --save option for creating a config file ~/.ripit/config.

ripit -t http -S standard -D '"$year - $album"' -T '"$tracknum - $artist - $trackname"' --playlist 0 --core 4 -o .

Sunday, December 9, 2007

limit lftp upload rate

For 10 Kb/s:
set net:limit-rate 0:10240

convert / resize many images using 4 threads at a time

mkdir small
for i in *.JPG; do while [ `ps --no-headers -C convert | wc -l` == "4" ]; do sleep 1; done; convert -quality 95% -resize 30% $i small/$i & done

Friday, November 30, 2007

rename usb disk volume label (FAT32)

HowTo
sudo mlabel -i /dev/sdc1 ::my-label

Afterwards copy original boot sector to backup using
sudo dosfsck -ar /dev/sdc1

backup ubuntu / debian package selection list

HowTo

Backup:
sudo dpkg --get-selections > dpkglist.txt

Restore:
sudo dpkg --set-selections < dpkglist.txt
sudo apt-get -y update
sudo apt-get dselect-upgrade

Wednesday, November 21, 2007

mplayer down-mix stereo to mono

mplayer −af pan=1:0.5:0.5 input

Monday, November 19, 2007

remote firefox over ssh

ssh -Y
firefox -no-remote &

Saturday, November 10, 2007

typesetting poems with LaTeX

the texlive-humanities package includes the LaTeX package verse.

Tuesday, November 6, 2007

multiple plots in one window with gnuplot

Display colors and point types:
test

For data plots:
set terminal postscript eps monochrome enhanced dashed
set output "distplot.eps"
set style data linespoints
set title "Minimum Distance"
set xlabel "m"
set ylabel "toroidal minimum distance"
set logscale xy 2
plot "mindists.dat" using 1:2 title "Sobol'", "mindists.dat" using 1:3 lt 3 title "Larcher-Pillichshammer"

Modifying the data columns (e.g. plot differences):
plot 'force.dat' using 1:($3-$2)
plot 'force.dat' using (3*$2):(sin($3+$1))


Don't clear the window, very general method:
set multiplot

# common margins
set lmargin 10
set rmargin 2

# common y-range
set yrange [0:1.3e+9]

plot "values.dat" using 1:2 title "f1"
plot "values.dat" using 1:3 lt 3 title "f2"
...
clear
unset multiplot

converting binary and decimal numbers with maple

from decimal to binary:
convert(12345, binary);

from binary to decimal:
convert(11000000111001, decimal, binary);

Friday, October 26, 2007

renaming multiple pdf files

for i in *.pdf; do echo $i; xpdf "$i" & read k; mv "$i" "$k.pdf"; done

Wednesday, October 24, 2007

acroread 8.1 on ubuntu gutsy amd64

add the medibuntu repositories:
sudo wget http://www.medibuntu.org/sources.list.d/gutsy.list -O /etc/apt/sources.list.d/medibuntu.list
wget -q http://packages.medibuntu.org/medibuntu-key.gpg -O- | sudo apt-key add - && sudo apt-get update


Install acroread:
sudo apt-get install acroread

Get xulrunner for the 32-bit libgtkembedmoz version (see acroread FAQ):
wget http://releases.mozilla.org/pub/mozilla.org/xulrunner/releases/1.8.1.3/contrib/linux-i686/xulrunner-1.8.1.3.en-US.linux-i686.tar.gz
tar xfzv xulrunner-1.8.1.3.en-US.linux-i686.tar.gz

After acroread startup, insert the xulrunner directory under
Edit -> Preferences -> Internet -> libgtkembedmoz Folder

Restart acroread.

Tuesday, October 23, 2007

sharing LAN printers on ubuntu gutsy

HowTo
System -> Administration -> Printing.
Server Settings: "Share published printers connected to this system".
For each printer, check the state "Shared" under "Policies".
On the clients, check "Show printers shared by other systems".

Sunday, October 21, 2007

burn cd / dvd

cdrom:

burn data directory on-the-fly:
mkisofs -r -l -J -V "label" data/ | cdrecord -driveropts=burnfree -v dev=/dev/cdrom1 -

burn iso image:
cdrecord -driveropts=burnfree -v dev=/dev/cdrom1 img.iso

create iso image:
mkisofs -r -l -J -V "label" -o img.iso data/

mount iso image:
mount -o loop img.iso /mnt/iso


dvd:


burn data directory on-the-fly:
growisofs -l -Z /dev/dvd -V "label" -R -J data/

burn iso image:
growisofs -dvd-compat -Z /dev/dvd=img.iso

create dvd image of video dvd in VIDEO_TS / AUDIO_TS format:
mkisofs -dvd-video -o img.iso /path/to/dvd/filesystem/

Tuesday, September 25, 2007

allow shutdown for all users without password

set uid bit:
sudo chmod u+s /sbin/shutdown
and run shutdown without sudo.

alternative: Allow shutdown for all users in the admin group in the sudoers file (see here):
sudo visudo

Add at the end of the sudoers file:
%admin ALL=NOPASSWD: /sbin/shutdown

After logging out and in again, use sudo shutdown without the password prompt.

Monday, September 24, 2007

Compiling rtorrent on nslu2

Wiki with known issues.

libtorrent:
mkdir install
CXXFLAGS="-O2 -mcpu=xscale -mtune=xscale" ./configure --prefix=`pwd`/install
--enable-debug=no
make
make install


rtorrent:
mkdir install
PKG_CONFIG_PATH=/home/leo/rtorrent/libtorrent-0.11.8/install/lib/pkgconfig
CXXFLAGS="-O2 -mcpu=xscale -mtune=xscale" ./configure --prefix=`pwd`/install --enable-debug=no
make
make install

Saturday, September 15, 2007

convert avi to dvd

install tovid.

Adjust MTHREAD="--multi-thread 2" in tovid to MTHREAD="--multi-thread 4" for quadcore. However, the number of threads may not exceed 4.

PATH=~/soft/tovid/tovid-0.31/install/bin:$PATH tovid -dvd -pal -fit 4300 -parallel -noask -in input.avi -out output

use makexml and makedisc as stated in tovid output to generate dvd structure from mpg / burn the disc:

PATH=~/soft/tovid/tovid-0.31/install/bin:$PATH makexml output.mpg -out MyDisc
PATH=~/soft/tovid/tovid-0.31/install/bin:$PATH makedvd -burn -label "my movie" MyDisc.xml

fix mp3 tags

#!/usr/bin/env python

import sys
import os
import re

assert len(sys.argv) > 3

artist = sys.argv[1]
album = sys.argv[2]

for s in sys.argv[2:]:
    m = re.match(r'(\d\d) - ([^\.]*).mp3', s)

    if not m:
        print 'could not find match for', s
        continue

    track = m.group(1)
    title = m.group(2)
    cmd = 'id3v2 -a "%s" -A "%s" -T %s -t "%s" "%s"' % (artist, album, track, title, s)
    print cmd
    os.system(cmd)

Friday, September 14, 2007

gmail one-time-pad passwords

I have written some small scripts to allow logging in to the google mail web interface using one-time-pad passwords. This is quite useful if you want to read your e-mails using an untrusted computer in an internet cafe or something similar. However you will need a trusted webserver with working PHP and Python installation to use this. More info and the newest version can always be found at the project site on sourceforge.
Let me know if you find this useful.

Thursday, September 13, 2007

subtitle editor for ubuntu

gaupol or subtitleeditor (both available in the package manager)

Sunday, September 9, 2007

vlc lirc interface and subtitle positioning

vlc --freetype-fontsize=20 --sub-margin 60 -I lirc movie.avi

~/.lircrc:

#########
# Mplayer

begin
prog = mplayer
button = OK
config = pause
end

begin
prog = mplayer
button = VolUp
config = volume +1
repeat = 1
end

begin
prog = mplayer
button = VolDown
config = volume -1
repeat = 1
end

begin
prog = mplayer
button = ChanUp
config = sub_delay +0.1
repeat = 1
end

begin
prog = mplayer
button = ChanDown
config = sub_delay -0.1
repeat = 1
end

begin
prog = mplayer
button = forward
config = seek +20 0
end

begin
prog = mplayer
button = rewind
config = seek -20 0
end


begin
prog = mplayer
button = skip
config = seek +600 0
end

begin
prog = mplayer
button = replay
config = seek -600 0
end

begin
prog = mplayer
button = pause
config = pause
end

begin
prog = mplayer
button = up
config = seek +60 0
end

begin
prog = mplayer
button = right
config = seek +10 0
end

begin
prog = mplayer
button = down
config = seek -60 0
end

begin
prog = mplayer
button = left
config = seek -10 0
end

begin
prog = mplayer
button = enter
config = pause
end

begin
prog = mplayer
button = mute
config = mute
end

begin
prog = mplayer
button = play
config = pause
end

begin
prog = mplayer
button = power
config = quit
end

begin
prog = mplayer
button = stop
config = pause
end

begin
prog = mplayer
button = home
config = vo_fullscreen
end

begin
prog = mplayer
button = more
config = osd
end

begin
prog = mplayer
button = back
config = sub_visibility
end

#####
# vlc

begin
prog = vlc
button = OK
config = key-play-pause
end

begin
prog = vlc
button = VolUp
config = key-vol-up
repeat = 1
end

begin
prog = vlc
button = VolDown
config = key-vol-down
repeat = 1
end

begin
prog = vlc
button = forward
config = key-jump+medium
end

begin
prog = vlc
button = rewind
config = key-jump-medium
end


begin
prog = vlc
button = skip
config = key-jump+long
end

begin
prog = vlc
button = replay
config = key-jump-long
end

begin
prog = vlc
button = pause
config = key-play-pause
end

begin
prog = vlc
button = up
config = key-jump+medium
end

begin
prog = vlc
button = right
config = key-jump+short
end

begin
prog = vlc
button = down
config = key-jump-medium
end

begin
prog = vlc
button = left
config = key-jump-short
end

begin
prog = vlc
button = enter
config = key-play-pause
end

begin
prog = vlc
button = mute
config = key-vol-mute
end

begin
prog = vlc
button = play
config = key-play-pause
end

begin
prog = vlc
button = power
config = key-quit
end

begin
prog = vlc
button = stop
config = key-play-pause
end

begin
prog = vlc
button = home
config = key-fullscreen
end

begin
prog = vlc
button = back
config = key-crop
end

begin
prog = vlc
button = more
config = key-aspect-ratio
end

begin
prog = vlc
button = ChanUp
config = key-audio-track
end

begin
prog = vlc
button = ChanDown
config = key-subtitle-track
end

Thursday, September 6, 2007

listen to fm4 live stream

#!/bin/bash

while true
do
mplayer http://mp3stream1.apasf.apa.at:8000/listen.pls
sleep 1
done

download zdf heute stream

#!/bin/bash
curl http://wstreaming.zdf.de/zdf/veryhigh/`date +%y%m%d`_h19.asx | grep mms: | cut -d\" -f2 | xargs -n1 mplayer -dumpstream -dumpfile ~/tmp/heute.wmv

using the bash history

Link

sequoia-like disk-usage viewer

gdmap, uses cushion tree maps.

wait for process to end

If the process is a child of the current shell:
wait $pid

Otherwise:
while kill -0 $pid > /dev/null; do sleep 1; done

rename network interface

after removing a NIC, the name is not used anymore.
e.g. there is only eth2 and no eth0. this can cause problems with flexlm.
HowTo
sudo vim /etc/udev/rules.d/70-persistent-net.rules

dvd playback libdvdcss2

sudo apt-get install debhelper fakeroot
sudo /usr/share/doc/libdvdread3/install-css.sh

mplayer options

~/.mplayer/config:
fontconfig=yes
font='Bitstream Vera Sans'
subfont-text-scale=2
vo=gl:yuv=3:lscale=1:cscale=1
dr=yes
framedrop=yes
stop-xscreensaver=yes
fs=yes
double=yes
spualign=2
monitoraspect=16:10

nvidia-settings config is ignored

nvidia settings must be run every session to enable settings: HowTo.
Add to session startup programs:
nvidia-settings --load-config-only

convert flac to mp3

HowTo
flac2mp3.sh:

#!/bin/bash

DESTDIR=$1
PRESET=$2

if test "x$PRESET" = "x"; then
PRESET=standard
fi

if test "x$DESTDIR" = "x"; then
DESTDIR=.
else
mkdir -p "$DESTDIR"
fi

echo
echo "Preset=$PRESET Destination=$DESTDIR Source=`pwd`"
echo

for a in *.flac
do
OUTF=`echo "$a" | sed s/\.flac/.mp3/g`

echo
echo "Source=`pwd`/$a Destination=$DESTDIR/$OUTF"
echo

ARTIST=`metaflac "$a" --show-tag=ARTIST | sed s/.*=//g`
TITLE=`metaflac "$a" --show-tag=TITLE | sed s/.*=//g`
ALBUM=`metaflac "$a" --show-tag=ALBUM | sed s/.*=//g`
GENRE=`metaflac "$a" --show-tag=GENRE | sed s/.*=//g`
TRACKNUMBER=`metaflac "$a" --show-tag=TRACKNUMBER | sed s/.*=//g`
YEAR=`metaflac "$a" --show-tag=DATE | sed s/.*=//g | cut -b -4`

echo
echo "Launching: flac -c -d $a | lame --preset $PRESET - $DESTDIR/$OUTF"
echo

flac -c -d "$a" | lame --preset $PRESET - "$DESTDIR/$OUTF"

echo
echo "Setting id3 ($TITLE, $TRACKNUMBER, $ARTIST, $ALBUM, $GENRE, $YEAR)"
echo

if test "x$TITLE" != "x"; then
id3v2 -t "$TITLE" "$DESTDIR/$OUTF" > /dev/null
fi

if test "x$TRACKNUMBER" != "x"; then
id3v2 -T "$TRACKNUMBER" "$DESTDIR/$OUTF" > /dev/null
fi

if test "x$ARTIST" != "x"; then
id3v2 -a "$ARTIST" "$DESTDIR/$OUTF" > /dev/null
fi

if test "x$ALBUM" != "x"; then
id3v2 -A "$ALBUM" "$DESTDIR/$OUTF" > /dev/null
fi

if test "x$GENRE" != "x"; then
id3v2 -g "$GENRE" "$DESTDIR/$OUTF"
fi

if test "x$YEAR" != "x"; then
id3v2 -y "$YEAR" "$DESTDIR/$OUTF"
fi
done

citrix java client installation

HowTo

wget http://download2.citrix.com/files/en/products/nfr/ica/setup.class
java setup

configure connections:
java -cp JICAEngJ.jar com.citrix.pn

connect directly:
java -cp JICAEngJ.jar com.citrix.JICA uni-bib

install C manpages

apt-get install manpages-dev

embed fonts in gnuplot plots

set term postscript eps enhanced color "NimbusSanL-Regu,17" fontfile "/usr/share/texmf-texlive/fonts/type1/urw/helvetic/uhvr8a.pfb"
set output 'histogram.eps'

epstopdf histogram.eps

verification:
pdffonts histogram.pdf

gmail email notification

HowTo
sudo apt-get install checkgmail libextutils-depends-perl libextutils-pkgconfig-perl libsexy2 libsexy-dev
sudo perl -MCPAN -e 'install Gtk2::Sexy'
sudo perl -MCPAN -e 'install Crypt::Simple'

maple 11 (32 bit) on amd64 architecture

HowTo
in maple directory:
sudo ln -s bin.IBM_INTEL_LINUX bin.X86_64_LINUX
sudo ln -s jre.IBM_INTEL_LINUX jre.X86_64_LINUX

force fsck disk check at startup

touch /forcefsck

sshfs

HowTo
sudo apt-get install sshfs
sudo adduser username fuse

log-out and back in again.

OpenGL anti-aliasing, vertical sync and anisotropic texture filtering

__GL_SYNC_TO_VBLANK=1 __GL_FSAA_MODE=9 __GL_LOG_MAX_ANISO=3 /.doom3

searching for files in apt deb packages

sudo apt-get install apt-file
(configuration only takes a long time, it does not hang.)

pdflatex: bbm.sty not found

sudo apt-get install texlive-fonts-extra

asus p5b plus quad core q6600 cpu temperature sensors in gkrellm

sudo apt-get install gkrellm lm-sensors
sudo sensors-detect
sudo echo coretemp >> /etc/modules
sudo modprobe coretemp

concatenate avi files

mencoder -oac copy -ovc copy -o output.avi input1.avi input2.avi

LaTeX bold typewriter fonts for listings

LuxiMono package

Thanks to xemacs for his update!

### Get and unpack the font archive
wget http://tug.ctan.org/fonts/LuxiMono.zip
unzip LuxiMono.zip
cd LuxiMono

### Install the files and call the font tools for the system
sudo mkdir -p `kpsexpand '$TEXMFLOCAL'`/fonts/type1/public/luxi
sudo cp *.pfb `kpsexpand '$TEXMFLOCAL'`/fonts/type1/public/luxi
sudo mkdir -p `kpsexpand '$TEXMFLOCAL'`/fonts/afm/public/luxi
sudo cp *.afm `kpsexpand '$TEXMFLOCAL'`/fonts/afm/public/luxi
sudo unzip -d `kpsexpand '$TEXMFLOCAL'` ul9.zip
sudo mkdir -p `kpsexpand '$TEXMFLOCAL'`/fonts/map/dvips/luxi
sudo mv `kpsexpand '$TEXMFLOCAL'`/dvips/config/ul9.map `kpsexpand '$TEXMFLOCAL'`/fonts/map/dvips/luxi
sudo rm -rf `kpsexpand '$TEXMFLOCAL'`/dvips
sudo texhash
sudo updmap-sys --enable Map ul9.map


### Clean up ...
cd ..
rm -rf LuxiMono

LaTeX font memory

fix the error message "font ... not loaded: not enough room left":
increase in /etc/texmf/texmf.cnf:
font_mem_size = 500000

redirect stderr to stdin

ls > out 2>&1

redirect output from time, appending:
/usr/bin/time -a -o timinigs ./my-program

printing multiple pages per sheet

CUPS options:

portrait:
-o number-up=4 -o number-up-layout=rlbt

landscape:
-o number-up=4 -o number-up-layout=btlr

use EXIF-tag to rotate jpeg images losslessly

jhead -autorot *.jpg

extracting rpm packages

rpm2cpio php-5.1.4-1.esp1.x86_64.rpm | cpio -idmv

Intel C++ compiler 10 and ubuntu

tar xfzv l_cc_p_10.0.023_ia32.tar.gz
sudo apt-get install alien
cd l_cc_p_10.0.023_ia32/data
sudo alien -cv intel-icc100023-10.0.023-1.i386.rpm
sudo dpkg -i intel-icc100023_10.0.023-2_i386.deb
sudo mkdir -p /opt/intel/licenses
sudo cp ~/NCOM_L_CMP_CPP_NB96-WLC77F6B.lic /opt/intel/licenses
cd /opt/intel/cc/10.0.023/bin
sudo perl -pi -w -e 's/!\/bin\/sh/!\/bin\/bash/g;' *.sh icpc icc
sudo perl -pi -w -e 's/<INSTALLDIR>/\/opt\/intel\/cc\/10.0.023/g;' *.sh icpc icc

~/.bashrc
source /opt/intel/cc/10.0.023/bin/iccvars.sh

error "Catastrophic error: could not set locale "" to allow processing of multibyte characters":
export LANG=C

Myriad and Minion for LaTeX

Update: This is all much easier with FontPro.
You probably can safely ignore all the rest below when using the above scripts.

Minion CTAN archive

sudo apt-get install lcdf-typetools

Fonts are installed with Adobe Acrobat Reader, for example:
otfinfo -v /opt/acrobat/Resource/Font/MinionPro-Regular.otf
On Ubuntu Intrepid, the Acrobat Reader 8 fonts can be found in
/usr/lib32/Adobe/Reader8/Resource/Font

This should result in
Version 2.015;PS 002.000;Core 1.0.38;makeotf.lib1.7.9032.
wget ftp://dante.ctan.org/tex-archive/fonts/minionpro/scripts.zip ftp://dante.ctan.org/tex-archive/fonts/minionpro/enc-2.000.zip ftp://dante.ctan.org/tex-archive/fonts/minionpro/metrics-base.zip
unzip scripts.zip
cp /opt/acrobat/Resource/Font/MinionPro* otf
./convert.sh
sudo mkdir -p `kpsexpand '$TEXMFLOCAL'`/fonts/type1/adobe/MinionPro
sudo cp pfb/*.pfb `kpsexpand '$TEXMFLOCAL'`/fonts/type1/adobe/MinionPro
sudo unzip -d `kpsexpand '$TEXMFLOCAL'` metrics-base.zip
sudo unzip -d `kpsexpand '$TEXMFLOCAL'` enc-2.000.zip
sudo texhash
sudo updmap-sys --enable Map MinionPro.map

documentation:
acroread `kpsexpand '$TEXMFLOCAL'`/doc/latex/MinionPro/MinionPro.pdf
MnSymbol CTAN archive
wget ftp://tug.ctan.org/pub/tex-archive/fonts/mnsymbol.zip
unzip mnsymbol.zip
cd mnsymbol/tex
latex MnSymbol.ins
sudo mkdir -p `kpsexpand '$TEXMFLOCAL'`/tex/latex/MnSymbol
sudo cp MnSymbol.sty `kpsexpand '$TEXMFLOCAL'`/tex/latex/MnSymbol
cd ..
sudo mkdir -p `kpsexpand '$TEXMFLOCAL'`/fonts/source/public/MnSymbol
sudo cp -R source/* `kpsexpand '$TEXMFLOCAL'`/fonts/source/public/MnSymbol
sudo mkdir -p `kpsexpand '$TEXMFLOCAL'`/doc/latex/MnSymbol
sudo cp MnSymbol.ps MnSymbol.pdf README `kpsexpand '$TEXMFLOCAL'`/doc/latex/MnSymbol
sudo mkdir -p `kpsexpand '$TEXMFLOCAL'`/fonts/map/dvips/MnSymbol
sudo cp enc/MnSymbol.map `kpsexpand '$TEXMFLOCAL'`/fonts/map/dvips/MnSymbol
sudo mkdir -p `kpsexpand '$TEXMFLOCAL'`/fonts/enc/dvips/MnSymbol
sudo cp enc/*.enc `kpsexpand '$TEXMFLOCAL'`/fonts/enc/dvips/MnSymbol
sudo mkdir -p `kpsexpand '$TEXMFLOCAL'`/fonts/type1/public/MnSymbol
sudo cp pfb/*.pfb `kpsexpand '$TEXMFLOCAL'`/fonts/type1/public/MnSymbol
sudo mkdir -p `kpsexpand '$TEXMFLOCAL'`/fonts/tfm/public/MnSymbol
sudo cp tfm/* `kpsexpand '$TEXMFLOCAL'`/fonts/tfm/public/MnSymbol
sudo texhash
sudo updmap-sys --enable MixedMap MnSymbol.map

Myriad:
cp /opt/acrobat/Resource/Font/MyriadPro-* otf/
./convert.sh
wget faq.ktug.or.kr/wiki/uploads/MyriadProAR7.pdf faq.ktug.or.kr/wiki/uploads/MyriadProAR7.zip
mkdir myriad
cd myriad
unzip ../MyriadProAR7.zip
mv fonts/tfm/Adobe fonts/tfm/adobe
mv fonts/type1/Adobe fonts/type1/adobe
mkdir fonts/enc
mv dvips fonts/enc/
mkdir -p fonts/map/dvips/Myriad
mv fonts/enc/dvips/MyriadPro/MyriadPro.map fonts/map/dvips/Myriad/
cp ../pfb/MyriadPro-* fonts/type1/adobe/MyriadPro
sudo cp -R * `kpsexpand '$TEXMFLOCAL'`
sudo texhash
sudo updmap-sys --enable Map MyriadPro.map

In LaTeX file:
\usepackage[T1]{fontenc}
\usepackage{textcomp}

% Minion and Myriad fonts
\usepackage[minionint,mathlf]{MinionPro}
\renewcommand{\sfdefault}{Myriad-LF}

change file permission recursively

find -type f -exec chmod -x {} \;

PHP installation test

<? phpinfo(); ?>

ripping arccos protected dvds

vlc dvd:/dev/dvd@1 --sout "#standard{access=file,mux=ps,dst=output.ps}"

dvdshrink alternative for gnome

dvd95
(also available in package manager)

c++ editor for refactoring

slickedit
(use quick refactor to not scan standard c++ header files)

disable bell in terminal

add to ~/.bashrc:
# disable audible bell
if [ "$DISPLAY" ]; then
xset -b
fi

navigation keys in terminal

~/.inputrc:
"\e[1~": beginning-of-line
"\e[4~": end-of-line
"\e[1;5C": forward-word
"\e[1;5D": backward-word
"\C-H": backward-kill-word
"\e[3;5~": kill-word
set bell-style none

for vi-style controls:
set editing-mode vi
set keymap vi

(see man readline, inputrc)

screenshots using imagemagick

import screenshot.jpg

search and replace in files

perl -pi -w -e 's/search/replace/g;' *

with multi-line strings:

import sys

search = 'search over
multiple lines
'

replace = 'replace with
this string
'

for i in sys.argv[1:]:
f = open(i, 'r')
s = f.read()
f.close()

f = open(i, 'w')
f.write(s.replace(search, replace))
f.close()

tar bz2 backup over ssh

#!/bin/bash

# check for root
if [ `id -u` != 0 ]
then
echo "this script should be run as root:"
echo " sudo screen $0"
read -p "press [enter] to abort..." cd
exit 1
fi

echo "remember to run this inside screen."
read -p "press [enter] to continue..." cd

echo "dumping mysql database..."
mysqldump -u root --all-databases | bzip2 > ~/all_databases.sql.bz2

echo "starting backup. you will need to enter the password for leo@photon."
sudo tar cjf - --exclude=/tmp --exclude=/var/tmp --exclude=/lost+found --exclude=/proc --exclude=/sys --exclude=/mnt --exclude /media --exclude /home/leo/backup-photon / | ssh leo@photon "cat > ~/backup-nslu2/backup-nslu2_`date +%y-%m-%d`.tar.bz2"

bash wait for key press


read -p "press [enter] to continue..." cd

weekly crontab reminder


crontab -e

0 0 * * 6 echo "backup reminder" | mail -s "backup reminder" someone@googlemail.com

remove newline from argument list

ls | xargs -d '\n' touch
find -name "*.mp3" | sort | xargs -d '\n' mplayer

svn and apache

apt-get install apache2 subversion libapache2-svn libapache2-mod-php5 libapache2-svn

/etc/apache2/mods-available/dav_svn.conf:
# <Location URL> ... </Location>
# URL controls how the repository appears to the outside world.
# In this example clients access the repository as http://hostname/svn/
# Note, a literal /svn should NOT exist in your document root.
<Location /svn>

# Uncomment this to enable the repository
DAV svn

# Set this to the path to your repository
#SVNPath /var/lib/svn
# Alternatively, use SVNParentPath if you have multiple repositories under
# under a single directory (/var/lib/svn/repo1, /var/lib/svn/repo2, ...).
# You need either SVNPath and SVNParentPath, but not both.
SVNParentPath /var/lib/svn

# Access control is done at 3 levels: (1) Apache authentication, via
# any of several methods. A "Basic Auth" section is commented out
# below. (2) Apache <Limit> and <LimitExcept>, also commented out
# below. (3) mod_authz_svn is a svn-specific authorization module
# which offers fine-grained read/write access control for paths
# within a repository. (The first two layers are coarse-grained; you
# can only enable/disable access to an entire repository.) Note that
# mod_authz_svn is noticeably slower than the other two layers, so if
# you don't need the fine-grained control, don't configure it.

# Basic Authentication is repository-wide. It is not secure unless
# you are using https. See the 'htpasswd' command to create and
# manage the password file - and the documentation for the
# 'auth_basic' and 'authn_file' modules, which you will need for this
# (enable them with 'a2enmod').
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/dav_svn.passwd

# To enable authorization via mod_authz_svn
AuthzSVNAccessFile /etc/apache2/dav_svn.authz

# The following three lines allow anonymous read, but make
# committers authenticate themselves. It requires the 'authz_user'
# module (enable it with 'a2enmod').
#<LimitExcept GET PROPFIND OPTIONS REPORT>
Require valid-user
#</LimitExcept>
</Location>

initialize a password file (to add users, remove the '-c'):
htpasswd -c /etc/apache2/dav_svn.passwd <username>
chown www-data.www-data /etc/apache2/dav_svn.passwd

create repository:
mkdir /var/lib/svn
chown www-data.www-data /var/lib/svn
svnadmin create /var/lib/svn/<repository>
chown -R www-data.www-data /var/lib/svn/<repository>

set permissions for repository in /etc/apache2/dav_svn.authz:
[groups]
admin = foo
devs = foo, bar

[/]
@admin = rw

[myrepo:/]
@devs = rw
someone = r

import a project:
cd /my/path/to/myproject
svn import --username <user> . http://my.domain/svn/<repository> -m "initial import"
svn co --username <user> http://my.domain/svn/<repository>

websvn:
copy source to /var/www/wsvn and change /var/www/wsvn/wsvn.php:
$locwebsvnhttp = '/wsvn';

copy /var/www/wsvn/include/distconfig.php to /var/www/wsvn/include/config.php:
$config->parentPath('/var/lib/svn');
$config->setTemplatePath("$locwebsvnreal/templates/BlueGrey/");
$config->useMultiViews();
$config->useAuthenticationFile('/etc/apache2/dav_svn.authz');
$config->allowDownload();
$config->useEnscript();
$config->expandTabsBy(4);
$config->setMinDownloadLevel(0);
$config->hideRSS();

apt-get install enscript

RSS feeds are disabled above, but if you want to have feeds and the error "Error creating feed file, please check write permissions." appears:
chown -R www-data:www-data cache

at end of virtual host in /etc/apache2/sites-enabled/default:
# Location for WebSVN Interface
# the '/' behind /wsvn/ is important!!!
<Location /wsvn/>
Options MultiViews
DirectoryIndex wsvn.php
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/dav_svn.passwd
Require valid-user
</Location>

/etc/init.d/apache2 force-reload

reverting (undo local changes):
svn revert --recursive .

ddclient configuration

/etc/ddclient.conf:
pid=/var/run/ddclient.pid
protocol=dyndns2
use=web, web=checkip.dyndns.org
server=members.dyndns.org
login=my-username
password='my-password'
wildcard=yes
photon123.dyndns.org

command line e-mail using msmtp / gmail

sudo apt-get install ca-certificates

~/.msmtprc:
account default
host smtp.gmail.com
port 587
from my.account@googlemail.com
tls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
auth on
user my.account@googlemail.com
password my.password

for use with mail:
sudo apt-get install mailx

~/.mailrc:
set sendmail="/usr/bin/msmtp"

forwarding local mail, while keeping a copy: ~/.forward:
| mailx -s "Local mail on nslu2" someone@googlemail.com
leo

for use with mutt: ~/.muttrc:
set sendmail="/usr/bin/msmtp"
set use_from=yes
set from="my name <my.name@somewhere.com>"

REPLYTO="reply@here.com" mutt -s "test subject" -a attach.pdf -c carboncopy@somewhere.com address1@here.com address2@there.com < message.txt

samba sharing

Also see HowTo

sudo apt-get install samba smbfs

/etc/samba/smb.conf:
[...]
security = user
username map = /etc/samba/smbusers
map to guest = bad user
guest account = nobody
[...]

[some-share]
path = /media/some-share
available = yes
browseable = yes
read only = no
valid users = leo
guest ok = no

sudo smbpasswd -a username

/etc/samba/smbusers:
username = "username"

sudo testparm
sudo /etc/init.d/samba reload

client /etc/fstab:
//computer-name/some-share /media/some-share smbfs credentials=/home/leo/.smbpasswd,rw,exec,auto,uid=leo,gid=leo 0 0

ssh public key remote

locally generate ~/.ssh/id_dsa.pub:
ssh-keygen -t dsa

remote:
cat id_dsa.pub >> ~/.ssh/authorized_keys2

my vim settings

~/.vimrc:

set nocompatible

syntax on " syntax highlighting
"colorscheme developer

" font
"set guifont=Bitstream\ Vera\ Sans\ Mono\ 9

" indenting
set smartindent
set autoindent
set smarttab

set ic " ignore case in search
set incsearch " incremental search
set hlsearch " highlight search results
set smartcase " ignore case when lowercase

" expand tabs
set tabstop=8
set shiftwidth=4
set expandtab

" don't insert comment leader automatically on new line
autocmd BufRead,BufNewFile * set formatoptions-=cro

" don't want comments at the beginning of the line in python
au BufNewFile,BufRead *.py set nocindent
au BufNewFile,BufRead *.py set nosmartindent
au BufNewFile,BufRead *.py set autoindent

" don't want strange indenting for LaTeX files
au BufNewFile,BufRead *.tex set nosmartindent

" treat SConstruct as python
au BufNewFile,BufRead SConstruct set filetype=python

" underscore as word delimiter
"set iskeyword-=_

" show full path of file
:map 1

" don't jump over text-wrapped lines
map j gj
map k gk

" Turn of highlighting after a search
map ,, :nohl

" compilation
map :make!
map :cp
map :cn

" rewrap current paragraph
map {gq}

" backup options
set backupdir=~/tmp " backups (~)
set directory=~/tmp " swap files
set backup " enable backups

" change directory automatically
set autochdir

" filename auto completion
set wildmode=longest:full
set wildmenu

" show line numbers
set ruler

" delete to the left in insert mode with backspace
set backspace=indent,eol,start

" always have some lines of text when scrolling
set scrolloff=5

" ctags tutorial
" http://www.vim.org/tips/tip.php?tip_id=94
" omnicpp auto completion
" http://www.vim.org/scripts/script.php?script_id=1520
"filetype plugin on
" create ctags
"map :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .
" no automatic popup for '.', '->'
"let OmniCpp_MayCompleteDot = 0
"let OmniCpp_MayCompleteArrow = 0
" other stuff
"let OmniCpp_LocalSearchDecl = 1
"let OmniCpp_ShowPrototypeInAbbr = 1
" close preview window automatically
"autocmd CursorMovedI * if pumvisible() == 0|pclose|endif
"autocmd InsertLeave * if pumvisible() == 0|pclose|endif
" use STL sources using the _GLIBCXX_STD macro
"let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"]
" use system-wide tags created with
" ctags -R --c++-kinds=+p --fields=+iaS --extra=+q -o ~/system.tags /usr/include
"set tags+=~/system.tags

" no menu / toolbar / scrollbars
set guioptions-=r
set guioptions-=l
set guioptions-=m
set guioptions-=T

" stop blinking cursor
set guicursor=a:blinkon0

" Use Caps_Lock as Escape
" --- add to ~/.Xmodmap: ---
" remove Lock = Caps_Lock
" keysym Caps_Lock = Escape

update-alternatives vim standard editor

sudo update-alternatives --config editor

acroread on ubuntu gutsy

Bug report

get Linux .tar.gz package.
fix acroread script by replacing

echo $mfile| sed 's/libgtk-x11-\([0-9]*\).0.so.0.\([0-9]\)00.\([0-9]*\)\|\(.*\)/\1\2\3/g'

for feisty with

echo $mfile| sed 's/libgtk-x11-\([0-9]*\).0.so.0.\([0-9]*\)00.\([0-9]*\)\|\(.*\)/\1\2\3/g'

and for gutsy with

echo $mfile| sed 's/libgtk-x11-\([0-9]*\).0.so.0.\([0-9]*\).\([0-9]*\)\|\(.*\)/\1\2\3/g'

"Gtk-CRITICAL **: gtk_rc_get_style: assertion `GTK_IS_WIDGET (widget)' failed" error: HowTo
(this should be fixed with a recent Ubuntu Gutsy upgrade)
get libgtk2.0-0_2.10.11-0ubuntu3_i386.deb, extract and add at the beginning of acroread script:
export LD_PRELOAD=/opt/acroread/libgtk2.0-0_2.10.11/usr/lib/libgtk-x11-2.0.so.0.1000.11

~PPKLite.api plug-in failed to load:
sudo rm /opt/acroread/Reader/intellinux/plug_ins/PPKLite.api

find dangling / broken symlinks

sudo apt-get install symlinks
symlinks -r some/directory

disable flash / visual bell in screen

C-a C-g

alternatively: ~/.screenrc
vbell off

playing dvds with mplayer

identify subtitles and audio tracks:
mplayer -dvd-device mnt -vo null -ao null -frames 0 -identify dvd://1

deinterlace-post-processing and subtitles at the bottom:
mplayer -dvd-device mnt -vf pp=l5,expand=0:-50 -sid 0 -spualign 2 dvd://1

quake 3 nvidia options

without intro movie, but with anti-aliasing:
__GL_FSAA_MODE=5 ./quake3.x86 -

widescreen display: ~/.q3a/baseq3/q3config.cfg
seta r_customwidth "1680"
seta r_customheight "1050"
seta r_mode "-1"

catching ctrl-c in bash

trap "echo catched!" SIGINT

OPIE one time pad passwords for ssh

HowTo

apt-get install libpam-opie opie-server opie-client

/etc/pam.d/ssh:
#@include common-auth
auth sufficient pam_opie.so
auth sufficient pam_unix.so nullok_secure
auth require pam_deny.so

/etc/ssh/sshd_config:
#ChallengeResponseAuthentication no

over secure terminal:
opiepasswd -c -f

create password list:
opiekey -n 20 430 ph0650 | tac > list

encrypted partitions and container files

Partitions:
HowTo, HowTo, HowTo
- find out which partition to format: fdisk -l
- make sure partition is not mounted
- possibly create partition: cfdisk

sudo cryptsetup luksFormat -c aes-cbc-essiv:sha256 -s 256 /dev/sda1
sudo cryptsetup luksOpen /dev/sda1 encrypted
sudo mkfs.ext3 /dev/mapper/encrypted
sudo mkdir /media/encrypted
sudo mount /dev/mapper/encrypted /media/encrypted
sudo chown leo.leo /media/encrypted
sudo chmod 770 /media/encrypted

mcrypt.sh:
sudo cryptsetup luksOpen /dev/sda1 encrypted
sudo mount /dev/mapper/encrypted /media/encrypted


ucrypt.sh:
sudo umount /media/encrypted
sudo cryptsetup luksClose encrypted


Container Files:
Howto
dd if=/dev/urandom of=/media/USB-STICK/crypto bs=1M count=100
sudo losetup /dev/loop0 /media/USB-STICK/crypto
sudo cryptsetup -c aes-cbc-essiv:sha256 -s 256 --verify-passphrase luksFormat /dev/loop0
sudo cryptsetup luksOpen /dev/loop0 crypto
sudo mkfs.ext3 /dev/mapper/crypto
sudo mkdir /media/crypto
sudo mount /dev/mapper/crypto /media/crypto
sudo chown leo.leo /media/crypto
sudo chmod 770 /media/crypto


mount:
sudo losetup /dev/loop0 /media/USB-STICK/crypto
sudo cryptsetup luksOpen /dev/loop0 crypto
sudo mount /dev/mapper/crypto /media/crypto


unmount:
sudo umount /media/crypto
sudo cryptsetup luksClose crypto
sudo losetup -d /dev/loop0


Error message: "Check kernel for support for the aes-cbc-essiv:sha256 cipher spec and verify that /dev/sda5 contains at least 133 sectors":
Make sure partition is not mounted, and in case of the container file, that /dev/loop0 is usable (try /dev/loop1 for example, or check with sudo losetup -f. For example with wubi Ubuntu, only /dev/loop1 seems to work).

using backspace in Mathematica

Deactivate NumLock as it's a modifier in Mathematica.

scrolling in screen

Using screen
C-a Esc to enter copy mode
PageUp, PageDown to scroll
Esc to abort copy mode

Sending literal C-a to program: C-a a

duplex printing (CUPS)

CUPS documentation
portrait: -o sides=two-sided-long-edge
landscape: -o sides=two-sided-short-edge

starting services on boot (/etc/init.d)


sudo update-rc.d maya-doc-server defaults 85

Sunday, September 2, 2007

code blocks with Courier in Blogger

Posting Code Blocks / Snippets with Courier monospace font in Blogger is easy by using <code> and </code> tags in HTML mode.
for i in *.pdf; do xpdf "$i"; done
To preserve white space (e.g. important for the indenting of Python code), use <pre> and </pre>.