You are here: start » blog

Ever wanted to shutdown your workstation and...

Ever wanted to shutdown your workstation and confused some random $xterm with an ssh-session and one with a local shell? Still want to use your pretty shell color scheme on all your accounts anyway? Look no further. After managing to shutdown the wrong machine once or twice a year I finally took the time to build some visual safeguards into my ZSH.

Colors, Yay

However, since both ssh sessions and X terminal emulators allocate the same kind of pseudo terminal the best thing I came up with so far was iterating over the chain of parent processes until finding init or sshd. If anyone got a cleaner solution for this problem please tell me ;-)

.zshrc

function ppid_of() {
	grep ^PPid /proc/$1/status | awk '{print $2}'
}
 
function is_ssh_login() {
	pid=$$
 
	while [ $pid != 1 ]; do
		if `grep -q sshd /proc/$pid/cmdline` ; then
			return 0
		fi
		pid=`ppid_of $pid`
	done
 
	return -1
}

.zshrc

## see console_codes(4) for number<->color relations
# red foreground
root_color=31
# green foreground
user_color=32
# blue foreground
cwd_color=34
 
 
if [ `id -u` == 0 ]; then
	hostname_color=$root_color
else
	hostname_color=$user_color
fi
 
if is_ssh_login ; then
	# background color = foreground color
	hostname_color=`expr $hostname_color + 10`
fi
 
PROMPT=`echo "%{\033[01;${hostname_color}m%}%n@%m%{\033[00m%}:%b%{\033[01;${cwd_color}m%}%~%{\033[00m%} %# "`

Staying Sane with RSI

I am not a doctor. Anything I post here is just based on my experiences and may help as well as harm you. Consult a doctor before following any of my advice.

Some time ago I suffered from a bad case of Repetitive Strain Injury (RSI) which german doctors usually diagnose as Sehnenscheidenentzündung or Tendovaginitis/Tenosynovitis. Not being able to normally use a computer or my hands for a prolonged period of time gave me plenty of opportunity to think about how to improve my situation (and how to stay sane). After going through this I figured I might as well share which tools I bought as a result of that thought process.

→ Read more...

Tools: unpaper

Recently I wanted to print a few scanned pages. However, due to the low quality of the source material (see below) reducing the pages to black&white didn't exactly improve them.

Enter unpaper. While unpaper is a rather unknown tool it's also extremely useful because it allows diverse image modifications to improve scanned pages, e.g.:

  • black-/gray-/noise-/blurfiltering
  • deskewing
  • border-aligning
  • mask-centering
  • etc.

If you aren't sold yet the documentation offers other great examples of applied image processing techniques.

Below I've included the minimal1) script I used to process the scanned pages. While the settings produced sufficient results for my needs they are probably still far from perfect – so don't forget to toy with your settings to get optimal results ,)

autounpaper

#!/bin/sh
# Usage: autounpaper *.jpg
 
inputfiles=$*
tmpin=`mktemp -t autounpaper-in-XXXXXXXXXX`.pgm
tmpout=`mktemp -t autounpaper-out-XXXXXXXXXX`.pgm
 
opts="-q --overwrite"
opts+=" --no-deskew --no-mask-scan"
opts+=" --grayfilter-size 1,1 --grayfilter-step 1,1 --grayfilter-threshold 0.4"
 
echo -n "Processing:"
 
for input in $inputfiles; do
	echo -n " $input"
	ending=${input#*.}
	output=${input%.*}-unpaper.$ending
 
	convert $input $tmpin && echo -n . && \
	unpaper $opts $tmpin $tmpout && echo -n . && \
	convert $tmpout $output
done
 
rm $tmpin $tmpout
 
echo
1) meaning: quick&dirty

I got tagged

Splitbrain just tagged me and so I guess I've got to list my “favorite desktop Linux software”. Here are the rules:

  1. blog a list with your favorite destktop Linux software (as many or few you want)
  2. add links to the software project's websites
  3. post these rules
  4. tag three other Linux using bloggers

however, I will just ignore the “desktop” part because the list would be short and boring otherwise.

→ Read more...

Simple Improvements for Simple Scripts

Did you ever suddenly notice that something simple you've been doing for years could be vastly improved with just a little bit of tweaking? I did yesterday concerning the transfer of files with netcat (e.g. when nobody got sendfile installed and standard paranoia forbids simply using scp instead) and figured I should share my sudden “enlightenment” ;-)

ncsend

#!/bin/sh
 
host=$1
shift
 
tar cv "$@" | pv -brt | nc -q0 $host 23000

ncrecv

#!/bin/sh
 
netcat -l -p 23000 | pv -brt | tar xv

Note: piping to pv is optional

Edit: fixed a word splitting bug and specified a default port

Older entries >>

blog.txt · Last modified: 2008/05/22 12:32 (external edit)