Posts Tagged thisreallyworks
Maven: Colorized
Posted by JohannesTheDeveloper in fun with Linux on January 7th, 2009
If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!
Maven was written by people who obviously have no idea on how to create good tui (Text User Interface)-tools. They should sit together with the portage, git or other Linux-devs.
The output is unreadable (not to mention that the startup is slow).
So, what I did was wrap maven in a script that colorizes the output. The result looks like this:

This is how to do it:
create the file ~/bin/mvn with the following content (mvn (0 KB))
#!/bin/bash
/usr/bin/mvn $* | sed -e 's/Tests run: \([^,]*\), Failures: \([^,]*\), Errors: \([^,]*\), Skipped: \([^,]*\)/[1;32mTests run: \1[0m, Failures: [1;31m\2[0m, Errors: [1;33m\3[0m, Skipped: [1;34m\4[0m/g' \
-e 's/\(\[WARN\].*\)/[1;33m\1[0m/g' \
-e 's/\(\[INFO\].*\)/[1;34m\1[0m/g' \
-e 's/\(\[ERROR\].*\)/[1;31m\1[0m/g'
replace /usr/bin/mvn with wherever your mvn is (find out with which mvn).
Double-check that you get the encoding right, the weird sign should be hexadecimal 1b. Use a editor that supports encodings for copy+paste.
Give your ~/bin/mvn execute permissions (chmod +x ~/bin/mvn)
Try it out: call ~/bin/mvn in one of your maven projects
What is left to do is to register your new mvn-wrapper so it is called everytime.
Add the following line to your ~/.bashrc :
alias mvn=~/bin/mvn
Execute the command you just added in your running shells so you can use it there too.
You are done.
Changing the distributed mvn startup script
Even better, but a little more intrusive (you need root rights):
change the distributed mvn file. It is a bash script actually.
In gentoo:
$ which mvn
/usr/bin/mvn
$ file /usr/bin/mvn
/usr/bin/mvn: symbolic link to `/usr/share/maven-bin-2.0/bin/mvn'
$ file /usr/share/maven-bin-2.0/bin/mvn
/usr/share/maven-bin-2.0/bin/mvn: Bourne shell script text executable
$
Change the last call in that file to:
exec "$JAVACMD" \
$MAVEN_OPTS \
-classpath "${M2_HOME}"/boot/classworlds-*.jar \
"-Dclassworlds.conf=${M2_HOME}/bin/m2.conf" \
"-Dmaven.home=${M2_HOME}" \
${CLASSWORLDS_LAUNCHER} $QUOTED_ARGS |
sed -e 's/Tests run: \([^,]*\), Failures: \([^,]*\), Errors: \([^,]*\), Skipped: \([^,]*\)/[1;32mTests run: \1[0m, Failures: [1;31m\2[0m, Errors: [1;33m\3[0m, Skipped: [1;34m\4[0m/g' \
-e 's/\(\[WARN\].*\)/[1;33m\1[0m/g' \
-e 's/\(\[INFO\].*\)/[1;34m\1[0m/g' \
-e 's/\(\[ERROR\].*\)/[1;31m\1[0m/g'
That way you have it there directly. Maybe the gentoo devs could add a color use-flag. That’d be fun…
PDF merge/join/split
Posted by JohannesTheDeveloper in Happy Hacking on November 13th, 2008
You always wanted it to be this simple. Now it is.
.
Download:
=> 8KB pdfjoin-nosrc.tar.bz2
14712KB pdfjoin.tar.bz2 (with Ghostscript sources)
I programmed it in Python+Glade+GTK. It uses ghostscript as backend.
Unpack and run “python pdfjoin.py”.
I’ll make a Windows package sometime.
Python: HTML database descriptions from create statements
Posted by JohannesTheDeveloper in Happy Hacking on April 2nd, 2008
This code produces HTML database descriptions from create statements.
Feed into stdin, await from stdout.
For example: python dbdesc.py < DATASCHEME > dbdesc.html
It isn’t perfect nor meant to be, but gives a good starting point for a documentation.
#!/usr/bin/python
import sys
import re
a = ''
for i in sys.stdin.readlines():
a = a + " " + re.sub('--.*', '', i).strip()
a = a.strip().lower()
a = re.sub('\/\*[^*]*\*\/', '', a)
print """
<html>
<head>
<link rel="stylesheet" href="dbdesc.css" />
</head>
<body>
"""
for m in re.findall('create table ([^ (]*)[ (]*([^;]*)[ )]*;', a):
tablename = m[0]
content = m[1]
print "<h2>%s</h2>" % tablename
print """<table class="dbdesc"><thead><tr>
<th class="name">Feldname</th>
<th class="type">Typ</th>
<th class="option">Option</th>
<th class="comment">Bemerkung</th>
</tr></thead>"""
atts = {}
for l in content.split(','):
l = l.strip()
if l == '':
continue
if l.startswith('constraint') or l.startswith('foreign key'):
continue
l = l.split(None, 2)
if len(l)<2:
continue
name = l[0]
if name == 'constraint' or name.__contains__('(') or name.__contains__(')'):
continue
type = l[1]
if len(l)<3:
l.append('')
op = ""
if 'not null' in l[2]: op = op + '!'
if 'primary key' in l[2]: op = op + '1+P'
elif 'unique' in l[2]: op = op + '1'
print """ <tr>
<td class="name">%s</td>
<td class="type">%s</td>
<td class="option">%s</td>
<td class="comment"><!-- TODO: Bemerkungen --></td>
</tr>""" % (name, type, op)
print """ </table> """
print """</html> """
CSS file dbdesc.css
table.dbdesc{ width: 40em; border: 1px solid #080; border-width: 1px 0;}
table.dbdesc th{ border-bottom: 1px solid #080;}
table.dbdesc td{ border: none;}
table.dbdesc td, table.dbdesc th{ width: 15em;}
table.dbdesc th{ font-style: italic; font-weight: normal; }
table.dbdesc td.option{ text-align: center;}
table.dbdesc td.type{ text-transform: uppercase;}
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?'
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.
Copy files from Playlist (.pls) to usb stick
Posted by JohannesTheDeveloper in fun with Linux on March 24th, 2007
cat TopRated.pls |
grep -Eo "/mnt/.*"|sed "s/%.\{2\}/*/g"|
while read line; do cp "$line" /mnt/sda1/Music/TopRated/ -v; done
Get a nice pic for your desktop every day
Posted by JohannesTheDeveloper in fun with Linux on November 13th, 2006
Gets a daily picture from a site and sets the softlink “newest” to it.
Needs executable rights on the shellscript and a
The shell script next.sh:
DATE=$(date +%y%m%d)
SERVER=antwrp.gsfc.nasa.gov
URL=http://${SERVER}/apod/ap${DATE}.html
NEWIMG=${DATE}.img
[ -e $NEWIMG ] && exit;
rm -rf *.jpg *.png *.gif
wget --recursive --level=1 $URL --accept jpg,png,gif --no-clobber --no-directories --tries=0
FIRST=$( ls -U *_f.* *_big.* *.jpg *.png *.gif 2>/dev/null|head -n 1 );
if [[ "$FIRST" != "" ]]; then
cp $FIRST $NEWIMG
unlink newest
ln -s $NEWIMG newest
fi
If you want a cronjob for that, use e.g.:
0,30 * * * * cd bgimg/astro/data; sh ../next.sh
Don’t forget to set the background image of your window manager to the link … obviously
Recent Comments