I had to move some existing code into a namespace. As it was too much code for doing this manually, I developed the following bits of shell script:

#!/bin/bash
#
#############################################################
# "THE BEER-WARE LICENSE" (Revision 42):
# <robert -at- xenim -dot- de> wrote this file. As long as you
# retain this notice you can do whatever you want
# with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a beer in return.
#############################################################
NAMESPACE="mynamespace"
SRCDIR=/path/to/sources

find $SRCDIR -name '*.cpp' | while read f; do 
    LNUM=`awk '/#include/{a=NR}; END{print a}' "$f"`;
    if [ ! -z "$LNUM" ]; then LNUM=1; fi;
    sed -i -e "$LNUM a \\\nnamespace $NAMESPACE {" -e '$,$ a } /* end namespace $NAMESPACE */' "$f";
done

find $SRCDIR -name '*.h' | while read f; do
    LNUM=`awk '/#include/{a=NR}; END{print a}' "$f"`;
    if [ -z "$LNUM" ]; then 
        LNUM=`awk '/#define/{a=NR}; END{print a}' "$f"`;
    fi;
    sed -i -e "$LNUM a \\\nnamespace $NAMESPACE {" "$f";
    LNUM=`awk '/#endif/{a=NR}; END{print a}' "$f"`;
    sed -i -e "$LNUM i } /* end namespace $NAMESPACE */\n" "$f";
done

The first find loops over all source-files (assumed suffix is .cpp here) and inserts a namespace-declaration after the last occuring #include. If you keep all #inludes at the top of your file, this should work fine. The corresponding closing bracket is simply added at the end of the file.

The second loop edits the header-files. The namespace-declaration is also added after the last #include if there is any. Otherwise the declaration is inserted right after the include-guard. The closing bracket is added here before the include-guard ends.

And finally the usual warning: Backup your files before using this!

Posted Wed Aug 10 13:42:01 2011 Tags:

Im Rahmen einer Vorlesung über Augmented Reality war es vorgesehen, selbst eine kleine AR-Anwendung zu schreiben.

Da meine Kommilitonen und ich kleine Spielkinder sind, kam schnell die Idee auf, eine Aufbauanleitung für ein LEGO-Modell zu augmentieren. Das in der Vorlesung vorgestellte ARToolKit nahm dabei die komplizierteste Arbeit ab: Es erkannte die Marker, stellte eine Transformation zwischen Kamera und Marker bereit und erlaubte es damit in das Kameralivebild mit OpenGL zu zeichnen oder VRML-Modelle einzublenden. So blieb damit dann nur noch die virtuellen Bausteine zu modellieren, den Aufbauplan zu formulieren und einzubinden. Zur Steuerung des ganzen griffen wir aber auf die Tastatur zurücck, um den Aufwand nicht unnötig zu erhöhen.

Abschließend kann ich Linuxnutzern nur noch davon abraten zu versuchen die VRML-Integration von ARToolKit zum laufen zu bekommen. Zumindest im aktuellen Ubuntu Karmic ist die dafür benötigte Bibliothek openvrml nicht vorhanden. Es lässt sich zwar ein Paket aus Debian testing dafür installieren, aber dieses ist dann zu neu für das aktuellste - mittlerweile aber drei Jahre alte - Release von ARToolkit.

Und so sieht das aus, wenn es fertig ist (Direktlink):

Posted Wed Jan 13 15:10:29 2010 Tags:

During my work on a term paper for "nonlinear finite element method" I encountered the problem to do a study about the convergence of a certain problem.

As the the program we had to use to do the calculations (feap) reads all informations needed to solve the problem from an "so-called" inputfile and writes the results to another file called "outputfile". When there is the need to adjust five parameters, it gets a bit messy to change the inputfile, run FEAP and grab the resulting displacement out of the outputfile for several combinations of the parameters.

As an experienced user the fasted way to accomplish this, is to write a little which automates that. Since the people which evaluated the term paper where quite impressed about it, I am documenting it here too. (I am still wondering how they worked with FEAP for years without such a fairly easy wrapper)

So here is the code:

I reduced the number of parameters to three and removed the part which generates a some gnuplot-code for clarity. Just add another loop if you have more parameters.

In the inputfile all relevant parameters should be also declared as parameters:

...
para
p=2    !load
dx=30  !# of horizontal elmts
dy=10  !# of vertical elmts
nu=0.1 !
...
After calculating the solution, there should be a statement to output the displacement of the node you are interested in:
...
disp,node,0,50
...
The script which puts everything together looks like:
#!/bin/bash
#
#############################################################
# "THE BEER-WARE LICENSE" (Revision 42):
# <robert -at- xenim -dot- de> wrote this file. As long as you
# retain this notice you can do whatever you want
# with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a beer in return.
#############################################################
#

function setParm() {
  sed -i "s/^\($1=\)[^ ]*/\1$2/" $workfile;
}

INPUT=Igruendung
workfile=Ifound

output=${workfile/I/Out}
result=$INPUT-results

cp $INPUT $workfile

i=0
for nue in 0.1 0.499; do
  res=$result-$nue
  rm $res
  setParm nu $nue
  for n in {1..20}; do
    dx=$[ $n * 3 ]
    dy=$[ $n * 1 ]
    setParm dx $dx
    setParm dy $dy
    echo -n $[ dx*dy*2 ] >> $res
    echo -en "\t" >> $res
    echo -en "Run $i:\tdx=$dx\tdy=$dy\tnue=$nue ... "
    ./feap -i$workfile -o$output
    val=`grep -A1 '^   Node' $output | tail -n 1 | sed 's/.* //'`
    echo $val
    echo -en "$val\t" >> $res
    rm $output
    let i=i+1
    echo >> $res
  done
done
rm $workfile

Posted Mon Jul 13 15:44:10 2009 Tags:

Wer telnet nicht mag, aber trotzdem im Detail sehen will, was passiert, dem sei swaks empfohlen.

Posted Thu Jun 11 15:53:24 2009 Tags:

Bereits Mitte April wurde das erste, experimentelle Release von Paxle veröffentlicht. Paxle ist ein modulares Suchmaschinen-Framework, das bereits alles mitbringt, um eine eigene Suchmaschine zu betreiben. Mögliche Anwendungsbereiche wären beispielsweise als Intranetsuchmaschine im lokalen Netz, Desktopsuche auf dem eigenen Rechner oder auch als Suchportal im Internet mit spezifischen Themen.

Paxle wird mit Java unter Verwendung von Osgi für die Modularität entwickelt. Dadurch lassen sich auch zentrale Kompenenten wie Crawler, Parser und Indexer einfach austauschen bzw. erweitern. Mehr Informationen sowie Downloads finden sich auf der Webseite sowie im Projektwiki.

Golem, ProLinux, Symlink sowie einige Blogs berichten ebenfalls.

Posted Thu May 7 19:56:15 2009 Tags:

Bei StudiVZ hat man das klitzekleine Problem, dass man nur eine Benachrichtigungsmail bekommt, dass man eine Nachricht erhalten hat, aber nicht erfährt, was drin steht. Mit ein wenig Python und einem eigenen Mailserver (eventl auch ohne) kann man aber Abhilfe schaffen:

#!/usr/bin/python
from xml.dom.minidom import parse, parseString
from mechanize import Browser
import os, sys, smtplib

# args: SENDER TO ORIGTO

mail=sys.argv[3]
pw="studivzpassword"
to=sys.argv[2]
sendermail="postmaster@example.com"

process=False
origmsg=[]
preserve_headers=['From','To','Date','Subject','Content-Type','Content-Transfer-Encoding','MIME-Version']
inHeaders=True
for line in sys.stdin:
  line=line[:-1]
  if inHeaders:
    if line == '':
      inHeaders=False
      origmsg.append("")
    s = line.split(": ",1)
    if len(s) == 2:
      (name, value) = s
    else:
      continue
    if name in preserve_headers:
      origmsg.append(line)
    if name == "Subject" and "Neue Nachricht von " in value:
      process=True
    if name == "From" and "studiVZ Zentrale" in value:
      process=True
  else:
    origmsg.append(line)

if not process:
  server = smtplib.SMTP('localhost')
  server.sendmail(sendermail, to, "\r\n".join(origmsg))
  server.quit()
  sys.exit(0)

def getMessages(data, msgs={}):
  doc=parseString(data)
  for div in doc.getElementsByTagName('div'):
    if 'status_new' in div.getAttribute('class'):
      id=div.getAttribute('id')[4:]
      if not msgs.has_key(id):
        msgs[id]={}
      for subdiv in div.getElementsByTagName('div'):
        if 'body_text' in subdiv.getAttribute('class'):
          msgs[id]['content'] = ''
          for e in subdiv.childNodes:
            if e.nodeType == e.TEXT_NODE:
              msgs[id]['content'] += '> '+e.nodeValue.strip()
            if e.nodeName == 'br':
              msgs[id]['content'] += "\r\n"
        if 'fromName' in subdiv.getAttribute('class'):
          msgs[id]['sender'] = subdiv.getElementsByTagName("a")[0].firstChild.nodeValue.strip()
          msgs[id]['time'] = subdiv.getElementsByTagName("small")[0].firstChild.nodeValue.strip()
        if 'subject' in subdiv.getAttribute('class'):
          msgs[id]['subject'] = subdiv.getElementsByTagName('a')[0].firstChild.nodeValue.strip()
  return msgs

br = Browser()
res=br.open("http://www.studivz.net")
br.select_form(nr=0)
br['email']=mail
br['password']=pw
res2=br.submit()
res3=br.follow_link(text_regex=r'Nachrichtendienst')
res4=br.follow_link(text_regex=r'Inbox')
msgs=getMessages(res4.read())
toBeRead=[]
for (id,msg) in msgs.iteritems():
  if not msg.has_key('content'):
    toBeRead.append(id)
for id in toBeRead:
  resN=br.follow_link(url_regex=r'/Messages/Inbox/messageId/'+id+'/p/')
  msgs=getMessages(resN.read(),msgs)
res6=br.follow_link(text_regex='raus hier')
if len(msgs) > 0:
  server = smtplib.SMTP('localhost')
  for (id,msg) in msgs.iteritems():
    fromaddr = str(msg['sender'])+" <"+sendermail+">"
    mmsg = "From: %s\r\nTo: %s\r\n" % (fromaddr, to)
    mmsg += "Subject: [StudiVZ] %s\r\n" % msg['subject']
    mmsg += 'Content-Type: text/plain; charset="UTF-8"\r\n'
    mmsg += 'Content-Transfer-Encoding: 8bit\r\n'
    mmsg += 'X-StudiVZ-MsgId: %s\r\n' % id
    mmsg += '\r\n'
    mmsg += msg['sender'] + ' schrieb am ' + msg['time'] + ':\r\n'
    mmsg += msg['content']
    mmsg += '\r\n\r\n\t StudiVZ Nachrichten Mailing Robot'
    server.sendmail(fromaddr, to, mmsg)
  server.quit()

Dieses Script nimmt über STDIN eine Mail entgegen und erwartet als Argumente zuerst die Absendermailadresse, danach die Mailadresse, wo die Mail schlussendlich landen sollen und als drittes Argument die Mailadresse mit der man bei StudiVZ angemeldet ist. Man bindet dieses Script in Postfix analog zu den Autoreplies ein.

Posted Sun Mar 1 21:01:36 2009 Tags:

das mit dem Open Source nicht so ganz verstanden. (Hoffentlich ist das nur bei diesen Spielereien so)

Posted Thu Feb 19 18:45:41 2009 Tags:

Der Chef des ADFC fordert zwar nur eine geringere Mehrwertsteuer, aber - eine entsprechend geringere - Abwrackprämie würde nicht nur die Konjunktur ankurbeln, sondern auch einige nicht mehr verkehrssichere Räder auf den Schrott bringen, der TÜV hat ja in solchen Fragen nichts zu melden. Außerdem könnte man damit ja den einen oder anderen Autofahrer von einem - für sich und die Umwelt - gesünderem Leben überzeugen. (Und ich könnte mein Vehikel, das sich demnächst selbst zerlegt gegen was schickeres eintauschen, wenn nach der Überweisung an die Uni die Abwrackprämie dazu ausreicht)

Posted Tue Jan 27 12:32:53 2009 Tags:

Wahrscheinlich hatte Bismark recht, dass in Mecklenburg alles ein wenig später passiert: So auch das Online-Banking der dortigen Sparkasse. Das schließt regelmäßig jede Nacht zwischen eins und sechs, weil sich dann wahrscheinlich keiner mehr findet, der die Bytes aus der Leitung nimmt.

Posted Fri Dec 5 00:16:17 2008 Tags:

The simplest way to accomplish this is via jack:

So configure amarok to use the xine engine with the jack-output. When you are using Ubuntu, you need to make some changes in the "xine-lib" package and rebuild it:

diff xine/xine-lib-1.1.15/debian/libxine1-misc-plugins.install 
xine2/xine-lib-1.1.15/debian/libxine1-misc-plugins.install
21c21
< debian/tmp/usr/lib/xine/plugins/*/xineplug_ao_out_jack.so
---
> #debian/tmp/usr/lib/xine/plugins/*/xineplug_ao_out_jack.so
diff xine/xine-lib-1.1.15/debian/rules xine2/xine-lib-1.1.15/debian/rules
57c57
<       --with-jack \
---
>       --without-jack \

Download edcast-jack, do the usual ./configure, make (and probably make install). Adjust the configuration file in conf/sample.cfg to your needs.

Start jackd: jackd -d alsa

(Re-)Start amarok, play something Start edcast: ./edcast -c conf/sample.cfg xine:out0 xine:out1

Now you should be able to listen to your music played with Amarok via your icecast stream. If you want to have a bit more control over the stuff, which is streamed, have a look at "jackeq" which basically does the job of a mixer. To control the wirings inside jack you could use "qjackctl".

Posted Wed Dec 3 18:34:29 2008 Tags:

Es gibt auch eine Archivseite mit allen Einträgen, eine Übersicht der Tags, einen RSS-Feed, ein wenig Text über diese Seite und ein Impressum.