August 2008 Archives

2008-08-29 19:27:57

What's my public IP?

Here are 2 ways, to determine your public IP address using curl, sed and grep. I recommend using the second one.

curl -s www.wieistmeineip.de | grep class=\"ip\" | sed -r 's#(.*>)(.*)(<.*)#\2#'
curl -s checkip.dyndns.org | sed -r 's#(.*: )([0-9.]*)(<.*)#\2#'


Posted by haui | Permanent Link | Categories: linux

2008-08-25 00:56:25

Useful bash functions II

Most perl scripts I write start like this:

#!/usr/bin/perl
use strict;
use warnings;
#maybe the GPL or some other stuff...
Additionally it's always required to set the "x flag" via chmod - all in all quite annoying.
That's why I added the function shown below to my ~/.bashrc
np() {
        gplfile=~/Dokumente/gpl.txt
        if [ $# -eq 0 ]
        then 
                echo "filename required..."     
                return  
        fi
        if [ -e "$1" ] 
        then
                echo "file already exists!"
                return
        fi
        touch "$1" || { echo "can't touch $1" ; return ; }
        echo "#!/usr/bin/perl" >> "$1"
        if [ "$2" = "gpl" ] && [ -e "$gplfile" ]
        then
                cat "$gplfile" >> "$1"
        fi
        echo "" >> "$1"
        echo "use strict;" >> "$1"
        echo "use warnings;" >> "$1"
        echo "use 5.10.0;" >> "$1"
        echo "use feature 'say';" >> "$1"
        echo "" >> "$1"
        chmod 700 "$1"
        [ $EDITOR ] || EDITOR=vim
        $EDITOR "$1"
}


Usage: np filename [gpl]

Posted by haui | Permanent Link | Categories: linux

2008-08-21 19:53:24

Useful bash functions I

Put the following in your ~/.bashrc

up() {
        if [ $# == 0 ]
        then 
                cd ..
                return  
        fi
        if [ "${1//[^0-9]/}" != "$1" ]
        then
                echo "Not a number"
                return
        fi
        STRING=""
        for (( i=0; i<$1 ; i++ ))
        do 
                STRING="$STRING../"
        done
        cd $STRING
}

up is equivalent to cd .. and up N jumps up N directories in the directory tree.

Posted by haui | Permanent Link | Categories: linux

2008-08-18 21:52:36

Battery status script

Some weeks ago, my laptop suddenly turned off, because its battery was completely flat. To prevent this from happening again, I wrote a small script that notifies me, when a critical charge state is reached. Additionally it shuts the computer down before the battery does. ;-)
Please note that this isn't meant to be a general purpose solution, so feel free to adapt it to your own needs.


Posted by haui | Permanent Link | Categories: scripts

2008-08-15 00:36:06

screen - ein kurzer Einblick

Ich habe ein kurzes Einsteigertutorial zur Verwendung von GNU screen verfasst. Zu finden ist es hier.


Posted by haui | Permanent Link | Categories: articles

2008-08-13 21:41:07

Indent a file in 2 seconds

Indenting a whole file in Vim is pretty easy: Type the following in normal mode

ggVG=

Done!

Posted by haui | Permanent Link | Categories: vim

2008-08-11 02:15:35

new website online!

A few days ago, I stumbled across Volker Birk's blog. 'Cause I really liked the design, I decided to rebuild my own website using NanoBlogger.
Although I'm not completely satisfied with it yet, I think the result's already pretty considerable. :-)
BTW: The old site is still available here.


Posted by haui | Permanent Link | Categories: news

2008-08-11 01:27:50

palindromic numbers

Find all numbers from 1 to 999999, which are palindromic in base 2 and base 16.


Posted by haui | Permanent Link | Categories: linux

2008-08-11 01:24:17

Remove the last character from a string/variable (bash)

echo ${var:0:${#var}-1}
echo ${var%?}
echo $var | sed 's/.$//'

You could also use chop ;)


Posted by haui | Permanent Link | Categories: linux

2008-08-11 01:17:53

bash: list just directories


ls -d */ 
ls -l | grep ^d
find . -maxdepth 1 -type d
ls -F | grep /$
ls -1 | while read line; do if [ -d "$line" ]; then echo $line; fi; done
ls -1|while read l;do [ -d "$l" ]&&echo $l;done
perl -e 'foreach(glob(".* *")){print "$_\n" if (-d $_)}'
perl -e 'opendir(DIR,".");foreach(readdir(DIR)){print $_ ."\n" if(-d $_);}'
just kidding ;)
...


Posted by haui | Permanent Link | Categories: linux

2008-08-11 01:13:48

zig-zag scan in Perl


Posted by haui | Permanent Link | Categories: scripts, perl

2008-08-11 01:10:09

hint on 2-dimensional arrays in Perl:

$width = @{$array[0]};
$height = @array; 

Posted by haui | Permanent Link | Categories: perl

2008-08-11 01:08:35

rot13 "encryption" of a file:

tr A-Za-z N-ZA-Mn-za-m < file

Posted by haui | Permanent Link | Categories: linux

2008-08-11 01:01:42

Calculate the sum of digits of a given number

echo 1234 | sed 's/\(.\)/\1\+/g' | sed 's/.$//' | bc -l
perl -e 'print eval join "+", split //, 12345;' 

Posted by haui | Permanent Link | Categories: linux

2008-08-11 00:39:10

perl password generator

Another password generator, written in perl. As it's more advanced than the old bash script I recommend using this one, if you're to lazy to create a secure password by yourself. The special thing about this script is, that it's possible to specify the characters, that will occur in the password (e.g. it's possible to create a password, containing just the letters a, b and c (don't do this...))


Posted by haui | Permanent Link | Categories: scripts

2008-08-11 00:33:45

bash password generator

A simple shell script, that generates a random password from a given set of characters.


Posted by haui | Permanent Link | Categories: scripts

2008-08-11 00:30:09

Irssi - kick.pl

Ever wanted to kick multiple users with just one command? 

kick.pl makes it possible!

Usage:

/kck user1 user2 user3


Posted by haui | Permanent Link | Categories: irssi

2008-08-11 00:26:18

Irssi - wiki.pl

This script provides a fast way to "search" wikipedia from irssi.

Example:

/wiki rolling stones

prints http://de.wikipedia.org/wiki/Rolling_Stones in the current channel

and 

/ewiki rolling stones

expands to http://en.wikipedia.org/wiki/Rolling_Stones


Note: this script requires curl.

Posted by haui | Permanent Link | Categories: irssi

2008-08-10 23:29:42

Irssi - f@h.pl

Folding@home (F@H) is the most powerful distributed computing cluster in the world and one of the world's largest distributed computing projects. The goal of the project is "to understand protein folding, misfolding, and related diseases."
To keep everyone on IRC informed about my current work progress, I created this small script. :-)


Note: this script requires curl.

Posted by haui | Permanent Link | Categories: irssi

2008-08-10 23:06:49

Irssi - mocnp.pl

This is a nowplaying script for moc and irssi. It also enables you to control moc from irssi. I recommend applying my patch to moc, as it's the only way to determine whether you turned shuffle/repeat on or off.


Usage:
/mocnp         prints the currently played song in the active channel 
/play          starts playing, if moc's in state "pause"
/pause         pause the current song
/start         starts moc if it's not running or if it's in mode "stop"
/stop          stops moc
/next          next song
/prev          previous song
/shuffle       turns shuffle on/off (requires >=mocp 2.5)
/repeat        turns repeat on/off (requires >=mocp 2.5)
 

Posted by haui | Permanent Link | Categories: irssi

2008-08-10 22:32:56

Irssi - nicklist.pl

This script displays a nicklist on the top of your irssi-window. Since it uses the split function of irssi, it works without any external programs. Although it works fine for me, a newer, better version will come soon...


Posted by haui | Permanent Link | Categories: irssi

2008-08-10 22:19:28

shuffle/repeat patch for moc

A lot of moc's functions can be easily controlled via command-line switches.  Unfortunately, by default, there's no way to determine whether shuffle/repeat is turned on or off, without checking the ncurses-interface of moc. So, I created a small patch, that enables moc to display these two values along with the song information on the command-line.

Applying this patch is pretty easy:

patch interface.c patch


Example for the altered output:
State: PAUSE
File: /my/favorite/musicfile.mp3
Title: foobar
Artist: foo
SongTitle: foobar
Album: bar
TotalTime: 01:28
TimeLeft: 00:54
TotalSec: 88
CurrentTime: 00:34
CurrentSec: 34
Bitrate: 192Kbps
AvgBitrate: 199Kbps
Rate: 44KHz
Shuffle: on
Repeat: off

Posted by haui | Permanent Link | Categories: projects

2008-08-10 22:08:44

yaydl - yet another youtube downloader (No longer maintained!)

yaydl - more than a youtube downloader!

Currently supports:

  • youtube
  • metacafe.com
  • clipfish.de
  • myvideo.de
  • video.google.com
  • vimeo.com
  • dailymotion
  • sevenload
  • video.golem.de
  • downloading of multiple videos "simultaneously"
  • encoding from flv to xvid using mencoder or ffmpeg
  • extracting the soundtrack of a video using ffmpeg or mplayer+lame
  • md3-tagging of the extracted sound-files
  • auto-renaming
  • support for HD videos on youtube/dailymotion

Requirements:

  • Getopt::Long
  • LWP::UserAgent
  • MP3::Info
  • Term::ProgressBar

On debian-based systems, a apt-get install libwww-perl libgetopt-long-descriptive-perl libmp3-info-perl libterm-progressbar-perl will suffice.


Installation:

Just run the included install file. :-)


Changelog

Download the current version:


Posted by haui | Permanent Link | Categories: projects

2008-08-10 21:19:21

brute

Now that's something pretty useless...

A simple MD5 brute forcer, written in C.

It calculates all combinations of a given set of characters and compares the MD5 sum of each combination to a given hash. brute calculates about 3 million hashes per second on a Pentium 4 (2,6 GHz).

Usage:

brute length hash

length represents the maximal length of a string, i.e. if it's 6, brute won't try words longer than 6 characters.
hash is a md5-hash, for example 5cfa779519a9789fad5dfe0de784ee4c

Posted by haui | Permanent Link | Categories: projects

2008-08-10 21:11:15

Welcome to NanoBlogger 3.3!

The basic syntax is: nb [-b blog_dir] [options]

How to ...
  • create new weblog (directory) = nb -b [blog_dir] -a
  • create new entry = nb -a
  • create new category = nb -c new -a
  • create new entry with category = nb -c [cat_id] -a
  • list entries = nb -l [all|DATE|max]
  • list categories = nb -l cat
  • list entries by category = nb -c [cat_id] -l [all|DATE|max]
  • edit entry = nb -e [entry_id]
  • move entry to category = nb -c [cat_id] -m [entry_id]
  • delete entry = nb -d [entry_id]
  • delete category = nb -c [cat_id] -d cat
  • delete entry from category = nb -c [cat_id] -d [entry_id]
  • draft entry = nb -E [draft_file]
  • import draft as entry = nb -f [draft_file] -a
  • force update of weblog files = nb -u [all|DATE|main]

Thank you for trying NanoBlogger. Please direct comments and suggestions to the mailing list or submit a bug report to the project page on sourceforge.net.


Posted by n1xt3r | Permanent Link