Archive

Archive for August, 2009

how to put several pdf pages onto one page

August 26th, 2009 No comments
1
2
emerge -av app-text/pdfjam
pdfnup --nup 2x2 --column true --frame true your_pdf.pdf
Categories: website Tags:

microsoft XNA: whats the downfall?

August 17th, 2009 No comments

read this interesting article to get to know: http://www.xboxist.com/xbox-360/games/xna-community-games-is-a-failed-experiment-010122.php

nice quote:

As Fouts revealed in his blog post, Microsoft takes a base cut of 30% plus an additional 10-30% for advertising. Simply put, 40-60% of profits goes to Microsoft, and the remainder to the developers.

Categories: website Tags:

windows UAC (User Account Control) and cmake: simpler as you might think

August 16th, 2009 1 comment

its very simple to request admin rights for your application from the cmake file:

SET_TARGET_PROPERTIES(your-target-name PROPERTIES LINK_FLAGS /MANIFESTUAC:"level='highestAvailable'")

if it is working, your vista should add a small shield to your executable icon.

Categories: coding Tags:

small tip for the visual studio IDE

August 8th, 2009 No comments

press CTRL+SHIFT+*, enables the drawing of space/tab characters :)

Categories: website Tags:

failmail – forum mail integration for failed emails

August 6th, 2009 No comments

As i wrote earlier, you are able to write your own little mailserver.
With the following handling routine, it filters out the mailserver rejected mails correctly. (at least for the mailserver combination i am using)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
        def process_message(self, peer, mailfrom, rcpttos, data):
                if not '<SOME VERY LONG SECURE KEY>@<YOUR IP>' in rcpttos:
                        # drop spam
                        return
                if DEBUG:
                        print '%s' % '='*80
                        print 'peer: ', peer
                        print 'mailfrom: ', mailfrom
                        print 'rcpttos: ', rcpttos
                        print 'data: ', data
                lines = data.split('\n')
                counter = 0
                info = ''
                failline = ''
                failline_count = 0
                for line in lines:
                        if line.strip() == 'The mail system':
                                counter = 5
                                continue
                        if counter > 0:
                                counter -= 1
                                if counter == 0:
                                        break
                                if line.strip() != '' and failline_count < 2:
                                        failline += line
                                        failline_count += 1
                                info += line + '\n'

                mailsrch = re.compile(r'<[\w\-][\w\-\.]+@[\w\-][\w\-\.]+[a-zA-Z]{1,4}>')
                mails = mailsrch.findall(info)
                if len(mails) > 0:
                        email = mails[0].strip(' <>')
                        print "fail mail found: ", email
                        cmd = '/your/command/to/process/this/event %s "%s" "%s"' % (email, failline, data.replace('"', '\''))
                        commands.getstatusoutput(cmd)
                else:
                        print 'no emails found :('
                        print 'info: ', info

you might want to exchange '<SOME VERY LONG SECURE KEY>', '<YOUR IP>' and /your/command/to/process/this/event.
The custom command will post a new post in a forum thread in my case, but it could also move the user to a special group or something.

Categories: coding, website Tags:

new founded projects : overview

August 6th, 2009 No comments

small update on some side projects i started over the last months:

(all of those are currently actively used by me, so if you get problems, let me know)

Categories: coding, funstuff, python, website Tags:

syncing sourceforge SVN repos

August 6th, 2009 No comments

before you try to use svnsync, you might want to try this first:

rsync -av PROJECTNAME.svn.sourceforge.net::svn/PROJECTNAME/* .

as noted on http://sourceforge.net/apps/trac/sourceforge/wiki/SVN%20adminrepo

Categories: website Tags:

write your own mailserver in python

August 5th, 2009 No comments

so we have the problem that we have a forum of 10th's of users, and if we announce a topic or anything, we get back lots of mails of remote mailservers rejecting the email for various reasons. So we had a problem with handling those properly (inform the user, etc)

Thus we had the following idea:
- filter mails coming in using out google apps
- redirect mails to a special written new, slim mailserver that processes those emails correctly.

You can find that mailserver below, modify to what you need:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import sys
import asyncore
import threading
import smtpd
import time

# written by thomas fischer thomas{AT}thomasfischer{DOT}biz
# idea based on http://code.activestate.com/recipes/440690/

class MySMTPServer(smtpd.SMTPServer):
    def __init__(self, localaddr, remoteaddr):
        smtpd.SMTPServer.__init__(self, localaddr, remoteaddr)

    def process_message(self, peer, mailfrom, rcpttos, data):
        print '%s' % '='*80
        print 'peer: ', peer
        print 'mailfrom: ', mailfrom
        print 'rcpttos: ', rcpttos
        print 'data: ', data

class MyEmailServer(threading.Thread):
    def __init__(self, ipport):
        threading.Thread.__init__(self)
        self._stopevent = threading.Event()
        self.server = MySMTPServer(ipport, None)

    def run(self):
        while not self._stopevent.isSet():
            asyncore.loop(timeout = 0.001, count = 1)

    def stop(self, timeout=None):
        self._stopevent.set()
        threading.Thread.join(self, timeout)
        self.server.close()

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print "usage: ip:port"
        sys.exit(1)

    ar = sys.argv[1].split(":")
    ar[1] = int(ar[1])
    ipport = tuple(ar)
    mailServer = MyEmailServer(ipport)
    mailServer.start()
    print "running"
    running = True
    while running:
        try:
            time.sleep(1)
        except:
            print "stopping"
            mailServer.stop()
            del mailServer
            running = False

so, in order to test:

1
python mailserver.py 0.0.0.0:25

and send an email to your ip :)

below is an example of what it looks like when you send your IP an email using google mail with the above script:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$ python mailserver.py 0.0.0.0:25
running
================================================================================
peer:  ('209.85.211.186', 45480)
mailfrom:  thomas@thomasfischer.biz
rcpttos:  ['thomas@&lt;YOUR IP&gt;']
data:  Received: by ywh16 with SMTP id 16so461179ywh.24
        for &lt;thomas@&lt;YOUR IP&gt;&gt;; Wed, 05 Aug 2009 12:33:52 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.150.216.1 with SMTP id o1mr12837562ybg.183.1209500824x39; Wed,
        05 Aug 2009 12:33:44 -0700 (PDT)
Date: Wed, 5 Aug 2009 21:33:44 +0200
Message-ID: &lt;f4dad1470908051233l5c5f6ddea57878c8c0c0ek6ed@mail.gmail.com&gt;
Subject: test
From: Thomas Fischer &lt;thomas@thomasf1scher.biz&gt;
To: thomas@&lt;YOUR IP&gt;
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

foobar!
Categories: coding, python, website Tags:

wordpress upgrade, style change

August 4th, 2009 No comments

just upgraded wordpress from an ancient version to latest stable. As the previous theme was broken, i switched to the current, classic, version :)

Categories: website Tags:

svn export changed files per revision

August 4th, 2009 1 comment

this little script tool will export a whole tree of revisions, whith only the changed files in every directory.

first some script that exports a specific revision to a directory:

exportrev.sh:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash

REPO=https://svn.your-url.com/repos/your-repo
EXPORTDIR=/var/www/your/directory
REV=$1
REVF=$(printf "%04d" $REV)
REVDIR=$EXPORTDIR/$REVF
if [ -d $REVDIR ] ; then
 echo "revision $REV already exists, skipping ..."
 # fix links ...
 ln -s $REVDIR/log.txt $REVDIR/HEADER.txt >> /dev/null 2>&1
 exit 0
fi
mkdir $REVDIR >> /dev/null 2>&1
REVCHANGES=$(svn diff --summarize -r $[$REV -1]:$REV $REPO | grep -v 'D     ' | awk '{ print $2 }')
if [[ "$REVCHANGES" != "" ]] ; then
        for i in $REVCHANGES
        do
                p=$(echo $i | sed -e "s{$REPO{{")
                dn=$REVDIR/$(dirname $p)
                fn=$REVDIR/$p
                mkdir -p $dn >> /dev/null 2>&1
                svn export -r $REV --force $i $fn >> /dev/null 2>&1
        done
fi

svn log -v -r $[$REV]:$[$REV] $REPO > $REVDIR/log.txt
ln -s $REVDIR/log.txt $REVDIR/HEADER.txt >> /dev/null 2>&1
chown lighttpd:lighttpd $REVDIR -R

then a script that goes through all revisions of a repo:

1
2
3
4
5
6
7
8
9
10
#!/bin/bash

REPO=https://svn.your-url.com/repos/your-repo
REV_MAX=$(svn info $REPO | grep 'Revision' | awk '{ print $2 }')
REV_MAX=$REV_MAX
for REV in $(seq $REV_MAX)
do
        /path/to/XXXXXXX/exportrev.sh $REV
        echo $REV
done

just change the big variables in the script header and some paths and youre done :)
(you can always call export.sh since it ignores existing directories - thus no slowdow)

Categories: bash, server Tags: