Category Archives: Coding

Amazon Affiliate Weiterleitung für das richtige Land

Das Amazon Affiliate-Programm bringt zwar anscheinend vielen Webmastern einiges an Kohle ein, hat aber ein Problem falls man eine internationale/mehrsprachige Webseite hat: Der Webmaster muss mehrere Affiliate-Links für die Amazon-Webseiten in den verschiedenen Ländern (USA, England, Deutschland etc) erstellen.
Diese Problematik wurde natürlich erkannt, deswegen gibt es eine Reihe von WordPress-Plugins die den Besucher automatisch auf auf den richtigen Store weiterleiten (sogenanntes Geo-Targeting).
Falls man aber mal keine Lust hat noch mehr Plugins zu installieren oder vielleicht garkein WordPress benutzt (wie zum Beispiel unser Firmen-Blog) , habe ich einen kleinen Helfer-Webservice geschrieben der diese Arbeit erledigt: Der A-FWD Geo IP Forwarder für Amazon.
Viel Spass beim Ausprobieren!

Interview mit einem ehemaligen Adware-Programmierer

Nett zu lesen. Unter anderem interessant:

“We did create unwritable registry keys and file names, by exploiting an “impedance mismatch” between the Win32 API and the NT API. Windows, ever since XP, is fundamentally built on top of the NT kernel. NT is fundamentally a Unicode system, so all the strings internally are 16-bit counter Unicode. The Win32 API is fundamentally Ascii. There are strings that you can express in 16-bit counted Unicode that you can’t express in ASCII. Most notably, you can have things with a Null in the middle of it. That meant that we could, for instance, write a Registry key that had a Null in the middle of it. Since the user interface is based on the Win32 API, people would be able to see the key, but they wouldn’t be able to interact with it because when they asked for the key by name, they would be asking for the Null-terminated one. Because of that, we were able to make registry keys that were invisible or immutable to anyone using the Win32 API. Interestingly enough, this was not only all civilians and pretty much all of our competitors, but even most of the antivirus people.”

Hier lesen :)

Weird p300 connection problems

I have spent some hours with Hell4You debugging an issue with p300 connectivity on his network. The result of the issues were that browsing and chatting sometimes worked, sometimes it didn’t. By looking at the p300-generated hostfinder webpage and debugging around with the Eclipse debugger we were able to track it down: Some of his hardware / software is duplicating UDP packets and using its own IP as the source IP of the duplicated packet. Really really weird stuff. This resulted in connectivity sometimes not working because the wrong IP was used by p300.

The latest p300 version that will come in some weeks will fix this issue: It will always be checked with HTTP if some ip:port is really running p300. If you experience the same problem as described here, I can send it earlier :)

For the record, he is using a 3com OfficeConnect and a SpeedTouch 780wl.

Lesson learned? Never trust UDP!

Using Subclipse (Subversion Client) with Eclipse Ganymede on Mac OS X

I had some trouble with this (updated my Eclipse for my p300 development), however this works for me on 10.4.x:

  1. Install the CollabNet SVN package from
  2. Install Eclipse Ganymede
  3. In Eclipse, in Help -> Software Updates -> Add Site
  4. Check the latest Version of Subclipse and JavaHL and have it installed
  5. Restart Eclipse.. and you don’t get “unable to load default SVN client” anymore :)

The svn binaries are now in /opt/subversion, so maybe you also have to adapt your PATH variable in $HOME/.profile

Einnahmen von als RSS-Feed immer aktuell anzeigen

Wenn ihr gerne euren Layerads-Verdienst im Feedreader anzeigen wollt, koennt ihr mit diesem PHP Skript einen Feed erzeugen:

<rss version="2.0">
<title> Kontostand</title>
$contents = file_get_contents ("");
$simplexml = simplexml_load_string ($contents);
$amount = $simplexml->xpath ("//layerads/stats/balance");
foreach ($amount as $a)
print "<item>";
print "<title> Kontostand: " . $a . " EUR</title>";
print "</item>";

Die URL fuer oben findet ihr im Layer-Ads Webinterface bei “Statistiken”.

Ich habe uebrigens auch ein aehnliches Skript fuer Affilinet geschrieben.

Window locations in Java

I’m currently changing the windows in p300 to a MDI interface.

While doing this, I have found a nice Java thing: setLocationByPlatform enables you to let your JVM choose the position of a new Window. This means that windows won’t be placed at 0,0 but will be overlapped according to what your platform thinks is nice.

Catching Exceptions with an UncaughtExceptionHandler in Java

I’ve recently spent some hours to track down a mysterious bug and I just couldn’t find it. Since my application is using a lot of Threads/Workers  it came to my mind that a RuntimeException I did not catch could be the cause. I wrote a global handler for it and found where the problem was :)

The code in p300 I am using:

Somewhere in main():

Thread.setDefaultUncaughtExceptionHandler(new P300UncaughtExceptionHandler ());

The class:

public class P300UncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
    public void uncaughtException(Thread t, Throwable e) {
        System.err.println ("Uncaught exception by " + t + ":");

How to test it:

new Thread () { public void run () { throw new RuntimeException ("x");}}.start ();

Using a Selector in Java NIO

For p300 I am currently using a Selector to check if I can read from or write to a socket.

However this lead me to a weird problem: I am selecting for at most 30 seconds and I have received a timeout for writing even though this can’t really be and only happens with some OS combinations. I’ve found this thread in the Sun Forums and adapted my internal logic to the information from this thread:

Instead of always selecting for OP_WRITE when I want to write, I just try to write. If i was not able to write everything (that is, buffer.remaining () > 0) I select for OP_WRITE.

This seems to work fine :)

(That fix is not in p300 619 yet, it will come with the next bugfix release in the next days)

fileOutputChannel.transferFrom and RandomAccessFile in Java

I’ve had an interesting problem with the two above mentioned classes. If I understand the API correctly, it is enough to position(pos) on a FileOutputChannel and then use transferFrom. However transferFrom always returned 0. Then I used setLength on the RandomAccessFile the where the FileOutputChannel was derived from and then it worked.

Hope this helps :)

(Java 1.6 developer preview on OS X 10.4)

Das Lustigste was ich heute gelesen habe

“I wrote the first version of Gmail in one day. It was not very impressive. All I did was stuff my own email into the Google Groups (Usenet) indexing engine. I sent it out to a few people for feedback, and they said that it was somewhat useful, but it would be better if it searched over their email instead of mine. That was version two.”

(Paul Buchheit)

setSoTimeout of a Socket and Java NIO

A stupid thing about Java NIO and using blocking sockets (Who does that? Me in p300 because I want to use the increased performance of using FileChannel.transferFrom) is that the SO_TIMEOUT is not used anymore even if you set it.

However, switching to nonblocking IO is not that hard. You can use one Selector per SocketChannel and select() for OP_READ or OP_WRITE before every read or write. This way you can have a select (timeout in msec).

Java Server Faces – The Complete Reference

Ich beschaeftige mich zur Zeit u.a. mit oben genanntem (englischen) Buch. Im Kapitel ueber Lokalisierung sieht man als Beispiel-Screenshot ein deutschsprachiges Web-Formular mit so tollen Begriffen/Saetzen wie “Geslecht” oder “Registriert den Gewichtkonverter mit dem Konverterbezeichnung Gewicht”. Ich hoffe doch so internationalisiert man nicht ;)

Problems with the HTML id-Attribute and Java Server Faces

I had some problems using the id-Attribute to identify a JSF component from Javascript. The reason is that naming containers of JSF modify the id of their contained components. This has advantages and disadvantages. If you are using Javascript or CSS and need to identify a component, it is a disadvantage ;) The problem is known and the solution I used was using forceId of Tomahawk/Myfaces. It was the simplest thing to do, although it is not that nice to have really static ids.

You can use the Tomahawk components by changing the XML-prefix of your components in your JSF-Code from h: to t: .. that’s it :)