LaTeX and PDF

Installing the Latin Modern fonts solves the problem that LaTeX's PDF output (pdflatex or ps2pdf) looks like rubbish, i.e. bad font rendering, missing ligatures (lat. ligare - to bind), etc.

apt-get install lmodern

gawk printf float pitfall

I had to use a shell script reading in some values and spitting out some values. Those were to be processed by a binary that hung in an endless loop for an unknown reason. The script used the gawk tool excessively and I figured out that there was a problem with the decimal delimiter, which is different in some countries.

sed -e 's/\./,/g'
replacing dots by commas and afterwards vice versa
sed -e 's/,/\./g'
corrected this problem.

But it turned out that tools like gawk do rely on the locales set for your environment. A setenv LANG C before calling the scripts solved the problem even better. Quoted from the GNU awk User's guide
[...] The locale also affects numeric formats. In particular, for awk programs, it affects the decimal point character. The "C" locale, and most English-language locales, use the period character (`.') as the decimal point. However, many (if not most) European and non-English locales use the comma (`,') as the decimal point character.
So when using gawk make sure to execute
setenv LANG C (ksh-style shell) or
export LANG=C (sh-style shell)
in your script before calling gawk. Otherwise it may not run under different localized environments.

Create new initrd with mkinitrd for Debian kernel

If you are using sata or scsi and your Debian 2.6 stock kernel won’t boot you need to tweak your initrd because with Debian all modules required to boot must be loaded from the initrd. Else the boot process will halt because e.g. the hard disk or other necessary stuff is not accessible.
Edit the file
to contain all the modules you wish to load (e.g. for your sata controller). You can find out which modules you need by doing
on an already running kernel (other kernel version or maybe a live-cd like knoppix). Then you need to run mkinitrd to create the new initrd manually. Here’s an example:
mkinitrd -o /boot/initrd.img-2.6.8-2-386_TEST 2.6.8-2-386
Change the kernel version and the filename to what you need. The kernel version is exactly the directory name under /lib/modules. Next you can check if your changes were applied. Mount the initrd image to a local directory to examine its conents:
cd /boot
mkdir loop
mount -o loop -t cramfs initrd.img-2.6.8-2-386_TEST loop/
cat loop/loadmodules

See the module(s) that you added here? Nice! Now you only need to tell your boot loader to use the new initrd. Edit /boot/grub/menu.lst or /etc/lilo.conf accordingly (with lilo, run lilo before rebooting!).

Calculate the DPI resolution of your display

I needed this when X displayed LyX with huge fonts. You can change the font's DPI setting when using Gnome (I didn't find it immediately): settings...fonts...details (very small button)

or without Gnome/supposedly KDE you can edit your ~/.xsession to execute
xrdb ~/.Xresource
and in the .Xresource you add a line (replace with what you calculated)
Xft*dpi: 85
But at least with gnome the second method does not work because gnome overrides this value with sheer brutality (try the fist method).

Now the brain-part (calculation): Pythagoras' theorem

a^2 + b^2 = c^2

is used to calculate the pixel-diagonal of your screen resolution (c) and c divided by the size of your monitor (screen diagonal in inches) yields the DPI

Example: 1024x768 on 15 inch (in german: "Zoll") screen

sqrt(1024^2 + 768^2) / 15 = ~85 DPI

Google to the rescue! Example calculation for 1280x1024 on 17 inch screen

Network interface speed shell script

A shell script to determine the current throughput of a network interface. Yay!
if test "$dev" = ""
echo "No link specified. Using eth0"

inA=`ip -s link show $dev | tail -n3 | head -n1 | tr -s " " | cut -d" " -f2`
outA=`ip -s link show $dev | tail -n1 | tr -s " " | cut -d" " -f2`
sleep 2
inB=`ip -s link show $dev | tail -n3 | head -n1 | tr -s " " | cut -d" " -f2`
outB=`ip -s link show $dev | tail -n1 | tr -s " " | cut -d" " -f2`
echo "RX: $[(($inB-$inA)*8)/1000] kbps"
echo "TX: $[(($outB-$outA)*8)/1000] kbps"

CPU usage shell script

This three-liner extracts the CPU idle-percentage from vmstat, subtracts it from 100 and stores the result in a file.
Vmstat arguments specify waiting time in seconds and number of captures. I chose {5,2} to be sufficient.

idle=`vmstat -n 5 2 | tail -n 1 | sed -e 's/ \{2,\}/ /g' | cut -d" " -f16`
echo $use >> load

Watch a file while it changes, dmesg example

This is so cool!

watch "dmesg |tail --lines=$(($LINES-4))"

Dump an image to floppy with m-tools

No access to dd? I needed this one on a terminal client (LTSP).

mcat -w a: < image

Extract the essence of .conf

This piece of code displays a .conf file without the rubbish:

cat /etc/ssh/sshd_config | grep -v ^# | sed '/^$/d;'

Apache2 and subversion (DAV-SVN)

Insert this into your apache2 SSL config file to enable subversion. This is the most simple example with user-defined styles and password protection.
<Location /~joe/svn>
DAV svn
SVNParentPath /path/to/subversion
SVNIndexXSLT "/~joe/svnstyle.xsl"

AuthType Basic
AuthName "Joe's subversion repository"
AuthUserFile /path/to/htpasswd
Require user joe

The code is pretty self-explanatory. First lines enable svn, last lines enable security.

Apache2 SSL

1. Create a self-signed certificate: Apache2 comes with the script

Note: It seems not to be documented at all (manpage?), so try --force and --days if your certificate has expired!

2. Create a new server configuration under apache2/sites-available
Listen 443

NameVirtualHost *:443

<VirtualHost *:443>
LoadModule ssl_module /usr/lib/apache2/modules/

DocumentRoot /var/swww

SSLEngine on
SSLCertificateFile /etc/apache2/ssl/apache.pem

ErrorLog /var/log/apache2/ssl_error.log

3. Enable the new site
cd /etc/apache2/sites-enabled
ln -s ../sites-available/new-site-name

4. Restart apache2
/etc/init.d/apache2 restart

This page is powered by Blogger. Isn't yours?