Posts Tagged tool
Current calendar week on Desktop
Posted by JohannesTheDeveloper in fun with Linux on February 29th, 2008
This should say all:

Your next week calendar as Desktop background.
This is a hack. The script opens Sunbird (which you configured before), takes a screen shot of the window, closes Sunbird, cuts away the borders of the image and sets it as GNOME desktop background.
You will have to edit the pixels to cut off (depending on your theme).
#!/bin/bash
#TEXT="2 Friday"
TEXT="Friday" # next friday, so on saturday we see the next week
TOP=176 # in px
LEFT=112
BOTTOM=26
RIGHT=18
BACKGROUND='#76848F'
DATE=$(date --date="$TEXT" "+%m/%d/%Y")
WEEK=$(date --date="$TEXT" "+%-V")
FILENAME="$HOME/current-calendar.png"
TITLE="Week $WEEK - Sunbird"
killall sunbird-bin 2>/dev/null
sunbird -showdate "$DATE" 2>&1 &
# mozilla is slooow...
sleep 20
#import -crop "+$TOP+$LEFT" -window "$TITLE" $FILENAME
#import -crop "+$TOP+$LEFT" -rotate 10 -window "$TITLE" $FILENAME
#import -crop "+$TOP+$LEFT" -rotate 10 -monochrome -window "$TITLE" $FILENAME
import -crop "+$TOP+$LEFT" -window "$TITLE" - |
convert - -gravity NorthWest -crop "-$RIGHT-$BOTTOM" -colorspace Gray - |
convert - -colorspace RGB -background "$BACKGROUND" -rotate -10 $FILENAME
killall sunbird-bin
which gconftool 2>/dev/null >/dev/null && GCT=gconftool
which gconftool-2 2>/dev/null >/dev/null && GCT=gconftool-2
$GCT --type=string --set /desktop/gnome/background/picture_filename "$FILENAME"
wait
Also see MDC Command Line Options
Converter Extension for deskbar
Posted by JohannesTheDeveloper in Happy Hacking on February 14th, 2008
Do you know units? It’s a small forgotten unix program (like cal) that converts units … It tells me it supports 2411 units, 71 prefixes and 33 nonlinear units. Not bad, huh?
So let’s use this in the deskbar-applet. Some friendly neighbor already did this, I updated it to 2.20 new-style classes.
Screenshot: 
Code: converter (py, 6 KB)
Don’t use this anymore. Try this updated version!
Download to your Desktop, then drag and drop it into the deskbar preferences window. Or copy it to ~/.gnome2/deskbar-applet/modules-2.20-compatible.
Don’t forget to enable it in the preferences.
Yaha, you need to install the units program first!
keeping old revisions
Posted by JohannesTheDeveloper in fun with Linux on January 14th, 2008
One might be to lazy to set up or use a revision control system like CVS, SVN or git for small projects or when working on 2-3 simple files.
This script creates a directory “backup”, and places there a archive of the files in the current directory (not recursive) with an increasing number.
e.g. you start it in a Folder “Bsp-3″, it will create “backup/Bsp3-1.tar.bz2″, next time “Bsp3-2.tar.bz2″, etc.
Also cleans up duplicates, so you cannot call it too often!
Small, clean, easy. I love it!
backup-point.sh
DIRNAME=$(basename $PWD)
EXT=tar.bz2
mkdir -p backup
cleanup_unneeded(){
cd backup
FILES=*.tar.bz2
UNIQ=$(md5sum $FILES|sort|uniq --check-chars=32 | cut -d ' ' -f 3-);
for i in $FILES
do
if ! echo "$UNIQ" | grep -wq "$i"
then
echo "deleting unnecessary $i."
rm "$i"
fi
done
cd ..
}
cleanup_unneeded
for((i=1;i<200;i++)); do
FILENAME="backup/$DIRNAME-$i.$EXT"
if ! test -f "$FILENAME"; then
find -maxdepth 1 -type f|xargs tar -cjf "$FILENAME"
echo "backup-point $i made."
cleanup_unneeded
exit
fi
done
echo '200 points reached! Clean up a bit?'
Reverse hash database for bittorrent files (info_hash)
Posted by JohannesTheDeveloper in Happy Hacking on September 16th, 2007
Hi!
This is probably the first reverse hash database for torrent files.
Before continuing, please accept that I am handling here with metadata, so no illegal material. Also, I don’t host anything illegal. The links to TPB are nofollow. So don’t sue me or do anything funny, al’right?
Who needs this?
After a .torrent-file is downloaded and the torrent is started, there is no way to find out what torrent it is, because it a hash, the info_hash (see http://wiki.theory.org/BitTorrentSpecification).
In order to know the .torrent-file that belongs to the hash, one has to have the torrent file. I here do a reverse linking of hashes to the torrents for the most popular torrent files on The Pirate Bay.
When watching torrent traffic as an network administrator, you might want to know if the data is legal and complies to your policies.
On the other hand, if you see a torrent loading in your network as a user, if you know what it is, it might be _very_ interesting to join it, as the speed can be expected to be very high.
Technical details are in the howto file.
Where is it?
The Bittorrent info_hash reverse database is here as html with links to TPB, and also available as txt.
Is this a complete database?
Of course not. I took only the most popular torrents down to ~37 leechers from TPB.
Update (2007-09-16):
Now with 12675 entries!!
C: Bdecode
Posted by JohannesTheDeveloper in Happy Hacking on July 25th, 2007
In the last hour or so I wrote this bdecode C-program (see the
specification of bencoding) since this python program doesn’t work and I hate wikis with logins (otherwise I’d posted it there).
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
void tabber(int t){
while(t-->0) printf("\t");
}
int bdecode(char * data, int tab){
/*printf("data: %c%c%c%c%c\n", data[0],data[1],data[2],data[3],data[4]);*/
if (isdigit(data[0])){
int i=0;
int j=0;
while (isdigit(data[i])) {
i++;
}
data[i] = 0;
int len = atoi(data);
i++;
tabber(tab); printf("Bytestring (%d long): ", len);
for (;j<len;j++) {
printf("%c", data[j+i]);
}
printf("\n");
i+=len;
return i;
}else if(data[0] == 'i'){
int i=0;
int n=0;
int sign = 1;
i++;
if(data[1]=='-'){
sign = -1;
i++;
}
while (isdigit(data[i])){
n=n*10+data[i]-'0';
i++;
}
n*=sign;
tabber(tab); printf("Integer: %d\n", n);
i++;
return i;
}else if(data[0] == 'l'){
int i=0;
i++;
tabber(tab); printf("List: \n");
while(data[i] != 'e'){
i += bdecode(&data[i], tab+1);
/*printf("continuing at: %c%c%c%c%c\n", data[i+0],data[i+1],data[i+2],data[i+3],data[i+4]);*/
}
i++;
return i;
}else if(data[0] == 'd'){
int i = 0;
tabber(tab); printf("Dict: \n");
i++;
while(data[i] != 'e'){
i += bdecode(&data[i], tab+1);
/*printf("continuing at: %c%c%c%c%c\n", data[i+0],data[i+1],data[i+2],data[i+3],data[i+4]);*/
tabber(tab+1); printf(" => \n");
i += bdecode(&data[i], tab+2);
/*printf("continuing at: %c%c%c%c%c\n", data[i+0],data[i+1],data[i+2],data[i+3],data[i+4]);*/
printf("\n");
}
i++;
return i;
}
printf("Shouldn't be here\n");
return -1000;
}
int main(int argc, char ** argv){
if(argc>1)
bdecode(argv[1], 1);
else
printf("No arg, sucker!");
return 0;
}
Compile & execute (use the examples from the spec):
$ gcc bdecode2.c -o bdecode2.exe -Wall
$ ./bdecode2.exe d9:publisher3:bob18:publisher.location4:home17:publisher-webpage15:www.example.come
Dict:
Bytestring (9 long): publisher
=>
Bytestring (3 long): bob
Bytestring (18 long): publisher.location
=>
Bytestring (4 long): home
Bytestring (17 long): publisher-webpage
=>
Bytestring (15 long): www.example.com
Seriously, wikis with logins! Where even the discussion pages are locked.
Good old C… and don’t tell me about “Oh, you could save 2 lines there!” I got a compiler for that …
Of course it contains bugs! Good quality ones!
You can run your .torrent files against it:
$ ./bdecode2.exe "$(cat Apocalypto.torrent)" | less
Dict:
Bytestring (8 long): announce
=>
Bytestring (44 long): <a href="http://vip.tracker.thepiratebay.org/announce">http://vip.tracker.thepiratebay.org/announce</a>
Bytestring (13 long): announce-list
=>
List:
List:
Bytestring (44 long): <a href="http://vip.tracker.thepiratebay.org/announce">http://vip.tracker.thepiratebay.org/announce</a>
List:
Bytestring (44 long): <a href="http://tracker.torrentbox.com:2710/announce">http://tracker.torrentbox.com:2710/announce</a>.
List:
Bytestring (41 long): <a href="http://axxo.sladinki007.net:6500/announce">http://axxo.sladinki007.net:6500/announce</a>
List:
Bytestring (39 long): <a href="http://tracker.torrent.to:2710/announce">http://tracker.torrent.to:2710/announce</a>
Bytestring (13 long): creation date
=>
Integer: 1178231686
Bytestring (4 long): info
=>
Dict:
Bytestring (5 long): files
=>
List:
Dict:
Bytestring (6 long): length
=>
Integer: 943704064
Bytestring (4 long): path
=>
List:
Bytestring (45 long): Apocalypto[2006]DvDrip[Eng.Hard.Sub]-aXXo.avi
Dict:
Bytestring (6 long): length
=>
Integer: 623
Bytestring (4 long): path
=>
List:
Bytestring (52 long): IMPORTANT.Read carefully before enjoy this movie.txt
...
Reading metainfo about illegal movies is arguably allowed, I don’t download this. (Nor do I take anything away from anyone using violence, as piracy is defined.)
Mail/Jabber/Bash/Perl: New mail notifications via jabber
Posted by JohannesTheDeveloper in fun with Linux on June 23rd, 2007
Based on an earlier post, the following is a solution to get jabber notifications for new mails.
We do this using a cronjob, but don’t worry, system administrator, it does take minimal resources.
This is dedicated to users of stud3/stud4, but will work on any server you have ssh access to.
![]()
HOWTO:
1: Get the sources here and extract them. jbiff.tar (gz, 152 KB) (tar.gz archive)
There is a perl script (jabbersend.pl) with the needed modules for sending jabber messages.
Also there is a bash script (jbiff.sh) that checks if the inbox changed and calls the perl script accordingly.
Modify the line
"perl jabbersend.pl jabber.ccc.de username="J13R" password="mybottybot" to="buchner.johannes@amessage.at" "body=$a | $b | $c"
to your needs. You probably don’t want me to receive your mails notifications. I don’t mind if you use my bot (J13R) as sender, otherwise just enter your jabber account details there.
2: Copy them to a folder in your home directory on the server. ~/test for example.
You can should test the functionality by calling “bash jbiff.sh”. It will create a .oldstatus file to not send the same notification twice.
3: add it to your crontab
export EDITOR="pico" # You probably don't want to use vi on a HP machine
crontab -e # edit the crontab and add the following line:
* * * * * cd test/; bash jbiff.sh
Watch out: Failing cronjobs will send you a error report by mail which could create a infinite loop. You can clear/remove your crontab with “crontab -r”.
Also, this script only detects that something changed and will output the last message in your mailbox, so don’t wonder if you move/delete messages.
Wanted features: I would like the messages to contain newlines (couldn’t find how to do that).
Studivz: Weg he!
Posted by JohannesTheDeveloper in Happy Hacking on June 14th, 2007

Was kann man an Studivz besser machen? Oder wo soll man anfangen?
studivz.user (js, 1 KB)
Dieses Greasemonkey-Skript (Greasemonkey vorher in Firefox installieren) ersetzt den öden Text “Log out” durch ein freundliches, flüchtendes, SIW-like “Weg he!”.
Außerdem versucht es ein bisschen Werbung zu entfernen, aber da is Adblock wohl besser.
LaTeX: Beamer Theme switcher
Posted by JohannesTheDeveloper in Happy Hacking on June 9th, 2007
LaTeX + beamer package … means cool presentations.
But how to select a theme and a color theme? Which are there anyway?
The first script takes you through a tour how your presentation will look like for each theme.
The second does quite the same thing for the color schemes.
#!/bin/sh
name="switchtheme"
THEMEFILEDIR="/usr/share/texmf/tex/latex/beamer/"
INFILE="presentation.tex"
TMPINFILE="$name.tex"
TMPOUTFILE="$name.pdf"
MAKECMD="pdflatex $TMPINFILE"
DISPLAYCMD="evince $TMPOUTFILE"
THEMELIST=$*
if [ "$THEMELIST" == "" ]; then
THEMELIST=$(ls $THEMEFILEDIR |
grep 'beamertheme[A-Z]' | sed 's/beamertheme\([A-Z].*\)\.sty/\1/')
fi
for theme in $THEMELIST; do
echo $theme
cat $INFILE | sed 's/\\usetheme{[^}]*}/\\usetheme{'$theme'}/g' |
sed 's/\\title{\([^}]*\)}/\\title{\1 - '$theme'}/g' |
cat > $TMPINFILE
$MAKECMD
$DISPLAYCMD
done
rm $TMPOUTFILE $TMPINFILE $name.{out,aux,log,nav,snm,toc}
#!/bin/sh
name="switchcolor"
THEMEFILEDIR="/usr/share/texmf/tex/latex/beamer/"
INFILE="presentation.tex"
TMPINFILE="$name.tex"
TMPOUTFILE="$name.pdf"
MAKECMD="pdflatex $TMPINFILE"
DISPLAYCMD="evince $TMPOUTFILE"
THEMELIST=$*
if [ "$THEMELIST" == "" ]; then
THEMELIST=$(ls $THEMEFILEDIR |
grep 'beamercolortheme' | sed 's/beamercolortheme\(.*\)\.sty/\1/')
fi
for theme in $THEMELIST; do
echo $theme
cat $INFILE | sed 's/\\usecolortheme{[^}]*}/\\usecolortheme{'$theme'}/g' |
sed 's/\\title{\([^}]*\)}/\\title{\1 - '$theme'}/g' |
cat > $TMPINFILE
$MAKECMD
$DISPLAYCMD
done
rm $TMPOUTFILE $TMPINFILE $name.{out,aux,log,nav,snm,toc}
Start it where your tex file lives (plus change the INFILE variable). Your .tex file has to have \usetheme{something} as this will be replaced (not in your file, but a temporary).
You can also give it themes names as parameter, and it will show you only these.
Maxima graphical output
Posted by JohannesTheDeveloper in fun with Linux on May 15th, 2007
I frequently use maxima (http://maxima.sourceforge.net/). Today I looked for related projects with GUIs.
wxMaxima is quite nice, it provides a good help at entering input.
But I miss writing mathematical sheets and just arrange the formulas and diagrams on it.
My first step to this is the php script at the end. I put my formulas in testformula1.txt, call the script php maxima2html.php >maxima2html.html and get a nice html output (at the left in the screenshot):

<style>
div.formula{
font-family: 'Lucida console', monospace;
font-size: small;
white-space: pre;
padding: 4px 1em;
margin: 2px;
clear: both;
float: left;
margin: 0px;
}
div.in{
border: 1px solid #FDD;
background-color: #D99;
margin-top: 5px;
}
div.out{
background-color: #9D9;
margin-left: 2em;
margin-bottom: 1px;
}
</style>
<?php
function cleantext($text){
$re = '/\(%[io][0-9]*\)/';
$ntext = preg_replace_callback(
$re,
create_function('$matches','return str_repeat("",strlen($matches[0]));'),
$text);
$ntext = str_replace("\t",str_repeat(' ',8),$ntext);
$lines = explode("\n",$ntext);
$padleft = NULL;
// find smallest intend
foreach($lines as $l){
$i = 0;
while($i<strlen($l)){
if($l[$i]!=" "){
if(is_null($padleft) or $i<$padleft){
$padleft = $i;
}
break;
}
$i++;
}
}
for($i=0;$i<count($lines);$i++){
$lines[$i] = substr($lines[$i],$padleft);
}
$nntext = join("\n",$lines);
return rtrim($nntext);
}
function readOutput($pipe){
$out = '';
$shell = '(%i';
while(!feof($pipe)){
$out .= fgetc($pipe);
if(substr($out,-strlen($shell),strlen($shell)) === $shell){
while(substr($out,-1,1)!=')')
$out .= fgetc($pipe);
break;
}
}
return $out;
}
function machflecken($pre, $class, $continue = false){
if(empty($pre)) return;
echo '<div class="formula '.$class.($continue?' continued':'').'">';
echo $pre;
echo '</div>',"\n";
}
$in = file('testformula1.txt');
$in[] = 'quit(a=b);';
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
);
$out = '';
$process = proc_open('maxima -q', $descriptorspec, $pipes);
if (is_resource($process)) {
$out = cleantext(readOutput($pipes[1]));
machflecken($out,'start');
while(true){
if(empty($in)) break;
$cmd = array_shift($in);
fwrite($pipes[0], $cmd);
#print 'in: '.count($in).': '."\n".$cmd."\n";
$out = cleantext(readOutput($pipes[1]));
if(FALSE === strpos($cmd,'=')){
machflecken($cmd,'in',true);
machflecken($out,'out');
}else{
machflecken($out,'out');
}
}
stream_get_contents($pipes[1]);
fclose($pipes[1]);
$return_value = proc_close($process);
#echo "command returned $return_value\n";
}
?>
Improving TUWEL
Posted by JohannesTheDeveloper in Happy Hacking on April 21st, 2007
Ich hab mir gedacht, TUWEL schaut so unübersichtlich aus, da muss man doch was dagegen machen können.
Vorher: (3 Seiten mit Zeugs, das keinen interessiert)
Und das is rausgekommen:
Nachher: 
Kleinerer Font, ein paar Dinge entfernt und angeordnet.
Download:
Download Greasemonkey (Extension für Firefox)
Danach dieses kurze Script anklicken tuwel.user (js, 2 KB).
Verbesserungswünsche willkommen!
Ich finde jedenfalls, dass TUWEL lesbarer und übersichtlicher aussieht.
Update:
Ich hab den Text in der mittleren Spalte bisschen größer gemacht, und in Blockschrift. URL ist die gleiche.
Eigentlich könnte man das ganze ein bisschen weiter spinnen und einen ganzen Gothic-Mode schreiben ;-) Wer csszengarden kennt, weiß wo die Grenzen sind.
Recent Comments