Categories
Miscellaneous

Prevent Spamming

I usually get annoyed by spam robots. They are able nowadays to even bypass captchas. So what helps? I recently read an article saying that scientists work on a new kind of spam filters that can identify spam by the way the actual text looks like. That raised an idea in my head. Why not just count the number of links that a new guestbook entry contains? Usually this is what they do at my guestbook. They leave dozens of links. So I added a simple count in my guestbook plugin. Whenever there are too many links, I just ignore the entry. 🙂

Categories
Java

SimpleCaptcha for Servers

Currently there is a bug in SimpleCaptcha library that prevents it running in non-graphics environments. It will throw a java.awt.HeadlessException. Although the code does not rely on various graphics classes, they were left causing this problem.

I fixed the code and recompiled it. You can download the fixed JAR file here. Do not forget to set the system property java.awt.headless to true, e.g. by specifying Djava.awt.headless=true at command line.

Categories
Java Typo3

TYPO3-like templating with Java

Here is a class I wrote to apply TYPO3-like templating mechanism within Java. I am quite familiar with that kind of templates, so I decided to use it within one of my projects, too. The implementation requires Java 5.

Java Templating class

You need to adopt the class’ package though 😉

Categories
Perl

Perl Message Logging

The following code is a quick and dirty, but nevertheless usefull snippet to add logging facility to any perl script. You might want to add additional severities at lines 2-6, change the timestamp format at line 14, or enable logging into a file at lines 42-54.

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
56
57
58
59
60
61
62
63
64
65
66
# Defines severities of messages to log
my %TYPES = (
   ERROR => 1,
   DEBUG => 1,
   INFO  => 1
);
 
# Creates the time string for log messages
# Usage: getTimestring($unixTimeValue)
sub getTimestring {
   my $t = shift;
   $t = time if !$t;
   my @T = localtime($t);
   my $time = sprintf("%02d/%02d/%04d %02d:%02d:%02d",
              $T[3], $T[4]+1, $T[5]+1900, $T[2], $T[1], $T[0]);
   return $time;
}
 
# logs an error message
# Usage: logError($message);
sub logError {
   my $s = shift;
   logEntry($s, 'ERROR');
}
 
# logs an information message
# Usage: logInfo($message);
sub logInfo {
   my $s = shift;
   logEntry($s, 'INFO');
}
 
# logs a debug message
# Usage: logDebug($message);
sub logDebug {
   my $s = shift;
   logEntry($s, 'DEBUG');
}
 
# logs a single entry with given message severity
# Usage: logEntry($message, $severity);
sub logEntry {
   my $s = shift;
   my $type = shift;
   return if !$TYPES{$type};
 
   # build timestamp and string
   $type = rpad($type, 5);
   my $time = getTimestring();
   $s =~ s/\n/\n$time $type - /g;
 
   # print to STDOUT if required
   print "$time $type - $s\n";
}
 
# Right pads a string
# Usage: rpad($string, $maxlen[, $padchar]);
sub rpad {
   my $s = shift;
   my $len = shift;
   my $char = shift;
 
   $char = ' ' if !$char;
   $s .= $char while (length($s) < $len);
   return $s;
}
Categories
Java Perl PHP

URL Parameter Transforming

Need to transform URL parameters and decode values such as “Hello%20World!”? Here is how:

Perl:

$s =~ s/%([\da-f][\da-f])/chr( hex($1) )/egi;

Java:

s = java.net.URLEncoder.encode(s, "UTF-8");

PHP:

$s = urldecode($s);
Categories
Miscellaneous

Country Codes and Timezones

My current job often challenge me with various country codes and timezones. So I prepared two lists providing you with this information. country_codes.csv list all country codes (ICAO, ISO 2-letter, ISO 3-letter, ISO 3-digit), country names and continents. timezones.csv will list the ISO 2-letter code together with country name and Unix Timezone. Both lists might not be complete. So if you find errors or omissions, just let me know.

Country Code List (CSV)

Unix Timezones (CSV)

Categories
GoogleEarth

Icons for usage in GoogleEarth

You’ll find all available icons for use in GoogleEarth here:

http://www.cems.uwe.ac.uk/~cjwallac/apps/phpxml/showIcons.php

Thanks to Chris Wallace, I might copy the page and make it available here in case the original gets lost 😉

Categories
Miscellaneous

Hello world!

Welcome to my TechBlog. This blog is about to remember solutions to important and less important technical details, and of course, to share it with you. I hope you will find interesting details about whatsover here that helps you surviving on- and offline.