[RSS Feed]

Get the GIT commit ID

last change: 2015-12-04
This command gives the commit id of the currently checked out revision:

git rev-parse HEAD

permlink: _.at: Get the GIT commit ID

Doing XSL and FOP transformations on the commandline using Saxon and Apache FOP

last change: 2014-11-28
Transfomation using Saxon:
# java -jar saxon9.jar -s:<inputfilename> -xsl:<xsl filename> -o:<outputfilename>

Classpath must include all jars necessary for FOP:
# for name in fop-1.1/lib/*.jar; do export CLASSPATH=$name:$CLASSPATH; done;

Use output from another transformation, i.e. an FO-File:
# java -classpath $CLASSPATH org.apache.fop.cli.Main -fo <fo filename> -pdf <pdf outputfilename>

Use internal transformation mechanism, i.e. input is xml, xsl file transforms to fo:
# java -classpath $CLASSPATH org.apache.fop.cli.Main -xml <xml input filename> -xsl <xsl filename> -pdf <pdf outputfilename>

A complete step from XML to PDF might look like this, using input.xml, transform2fo.xsl and output.pdf als filenames:

Using Saxon:
# java -jar saxon9.jar -s:input.xml -xsl:transform2fo.xsl -o:intermediate.fo
# java -classpath $CLASSPATH org.apache.fop.cli.Main -fo intermediate.fo -pdf output.pdf

Using only Apache FOP:
# java -classpath $CLASSPATH org.apache.fop.cli.Main -xml input.xml -xsl transform2fo.xsl -pdf output.pdf

permlink: _.at: Doing XSL and FOP transformations on the commandline using Saxon and Apache FOP

Setup a DBCP datasource for H2 Database connections

last change: 2014-06-02
package whatever;

import org.apache.commons.dbcp.BasicDataSource;
import javax.sql.DataSource;
import java.util.Properties;

public class SetupDataSource {

public static final String DRIVER_CLASS_NAME = "org.h2.Driver";

public static DataSource setup(Properties dbProperties) {
// load driver class -- just to be sure...
try {
} catch (ClassNotFoundException e) {

// seehttp://commons.apache.org/dbcp/configuration.html
BasicDataSource dataSource = new BasicDataSource();
dataSource.setUrl("jdbc:h2:file:" + dbProperties.getProperty("dbfile"));
final int maxConnections = Integer.parseInt(dbProperties.getProperty("maxConnections"));
// dataSource.setValidationQuery("SELECT 1 FROM dual");
// dataSource.setTestOnBorrow(true);
dataSource.setTimeBetweenEvictionRunsMillis(5 * 60 * 1000);

return dataSource;

public static void main(String[] args) {

Properties dbProperties = new Properties();
dbProperties.setProperty("dbuser", "sa");
dbProperties.setProperty("dbfile", "/location/of/your/datafile");
dbProperties.setProperty("maxConnections", "100");

DataSource dataSource = setup(dbProperties);

permlink: _.at: Setup a DBCP datasource for H2 Database connections

Maven Dependencies

last change: 2014-02-10
Using Maven to download dependencies when a project offers no direct downloads:

1. In an empty directory create a pom.xml outlining the dependencies to download, e.g.:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
<description>Download Maven dependencies</description>

2. Use Maven to download the JARs including transitive dependencies:
mvn dependency:copy-dependencies

This will put the JARs into the subdirectory target/dependencies

permlink: _.at: Maven Dependencies

Unix Timstamps in SQL

last change: 2014-01-27
Convert a Unix timestamp to a Date in Oracle 11g:

SELECT to_date('1970-01-01','YYYY-MM-DD') + numtodsinterval(1390828626,'SECOND') FROM dual;

Be careful: this seems to be off by 1h.

And on Postgres:
SELECT (TIMESTAMP WITH TIME ZONE 'epoch' + unix_tstamp * INTERVAL '1 second')::date

permlink: _.at: Unix Timstamps in SQL

Scala problems

last change: 2011-11-30
In a quite long message which seems to be written as private conversation that became public someone who worked with Scala for some time really points to its weaknesses. It is one thing to like or dislike the often symbol-heavy syntax, but that post mentions several problems they encountered as a team which should not be dismissed as simple preferences, such as problematic code structures loosing performance (for-loops) or the penalty of using Scalas collection library (both mutable and immutable), which is more or less imposed as mandatory when using the standard library.

My short encounter with Scala reflects several of the points made, but the really bad part that finally convinced me to look for another take on next-gen JVM-languages is summed up in this quote:
"(...) but at some point a best practice emerged: ignore the community entirely."

The Scala community, while quite large, always seemed quite hostile to me, with lots of talent and time wasted on waging war over preferences of style. I do not want to spend my time on figuring out, who is 'right' in the sense of which preference gets adopted by the Scala community at large... So I stopped investing time in Scala at all.

permlink: _.at: Scala problems

Node Package Manager via Squid

last change: 2011-09-20
In some configurations the Squid HTTP Proxy seems to deny NPM requests when using the HTTPS protocol. In this case the error message returned by npm will contin a phrase like this:

"Unsupported Request Method and Protocol"

Try to reconfigure npm to use HTTP instead with this command:

$ npm config set registryhttp://registry.npmjs.org/

The currently used configuration can be read by issuing

$ npm config get registry

permlink: _.at: Node Package Manager via Squid

Servlets with Clojure

last change: 2011-08-04
A simplistic servlet implemented in Clojure

HTTP Date format in Java

last change: 2011-05-17
To format a date according to the HTTP standard (needed in the Last Modified header):

public static String formatHttpDate(Date date)
SimpleDateFormat httpDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);

return httpDateFormat.format(date);

permlink: _.at: HTTP Date format in Java

Querying MongoDB from Clojure using regex Prefix matches

last change: 2011-04-15
Turns out to be quite simple... Assuming a collection with an indexed attribute called 'index' the code would look something like this:

(ns test
(:use somnium.congomongo))

(def mongo-server "mongo.test")
(def mongo-db "testdb")
(def mongo-collection "indexedtestcollection")

(defn find-test [input]
:host mongo-server
:db mongo-db )
(let [rx (. Pattern compile (str "^" (first input)))]
(println (.getName (.getClass rx)))
(take 3
(fetch mongo-collection
:where {:index rx}

The main point being that the value for rx must be a Regex instance. In this sample code the regex is dynamically created, using a static #"^regex" works as well.

MongoDB can only use the index on the column if the regex is a prefix match (i.e. uses the '^' anchor).

permlink: _.at: Querying MongoDB from Clojure using regex Prefix matches

Print a stacktrace in Clojure REPL

last change: 2011-04-06
To print a stracktrace after an exception occurred use these commands:

user=> (use 'clojure.stacktrace)
user=> (print-stack-trace *e 10)

permlink: _.at: Print a stacktrace in Clojure REPL

MySQL: JDBC Connect String with UTF-8 encoding

last change: 2011-04-04

permlink: _.at: MySQL: JDBC Connect String with UTF-8 encoding

Fileupload in Servlets

last change: 2010-08-10
Due to a problem with UTF-8 encoded data I recently switched from the old (in my case *very* old) com.oreilly.servlet.MultiPartRequest to Apache Commons FileUpload. Big mistake.

As often the commons package promises everything and the kitchen sink but in truth simply is not up to the job. In this case there are several things that annoyed me:

*) The interface to the parsed request data. Why can't I access parameters by name? Why do I have to collect them into a ServletRequest-like structure myself? I will upload the resulting helper class here soon... in case someone else can't do the obvious: switch to another library.

*) UTF-8 data does not work. The only position FileUpload accepts an encoding string is via setHeaderEncoding() -- which definitly does not influence parsing of request data... So every string read from a request field must be converted to UTF-8 by hand:

String value = new String (fileItem.getString().getBytes("iso-8859-1"), "UTF-8");

Today I downloaded a fresh copy of the com.oreilly.servlets package, added the encoding parameter to the constructor call of MultiPartRequest and it just works. The lesson is: avoid Apache commons wherever possible. Note: please read the licensing info of the com.oreilly.servlet package, which boils down to the fact that each member of the development team should own a copy of the corresponding O'Reilly book 'Java Servlet Programming', which is excellent but was not updated quite a while.

permlink: _.at: Fileupload in Servlets

IDEA with Mercurial Plugin

last change: 2010-03-01
When using IntelliJ IDEA 9 with the Mercurial plugin hg4idea, I've had problems updating local repositories from the central mercurial-server, suggesting to use 'hg rebase' while mentioning MQ patches.
Turns out that this plugin needs the MQ extension enabled in the Mercurial commandline client. Configure this extension by adding the following lines to your ~/.hgrc:

hgext.mq =

No value is necessary as this is a standard extension and hg will find the necessary library within its installation path.

permlink: _.at: IDEA with Mercurial Plugin

Graphical Mercurial Client for MacOS X

last change: 2010-02-05
A graphical client to the DVCS Mercurial for MacOS X 10.5+, written in Objective-C. Looks quite promising.

permlink: _.at: Graphical Mercurial Client for MacOS X

JavaScript grows up

last change: 2009-11-09
Besides being a complete scripting language in its own right (with some actually quite interesting design decisions -- as well as some fatal ones), recent advances in interpreter technology helped JavaScript gain acceptance as a client interface scripting language.
Looking beyond what is now being done with web applications utilizing AJAX, more performance sensitive areas like gaming seem to come into reach. Displace Flash -- how nice this prospect sounds... hope it becomes real rather sooner than later.

permlink: _.at: JavaScript grows up

Intellij IDEA goes Open Source

last change: 2009-10-16
Quite a bold move by Jetbrains, the people behind what I consider to be the best Java IDE by far: starting with Version 9 (soon to be released) they will split into two version, IDEA Community Edition and Ultimate Edition. While the latter remains a commercial offer, primarily targeting J2EE devlopers, the former will be published under the Apache 2.0 license.

One might suspect the free offer to be so crippled that it will just draw potential customers to IDEA and then convert them to commercial licenses. This seems not to be the case: while having a clear focus on J2SE, the Community Edition retains all the features that made IDEA a great offer for J2SE developers (even the powerful refactoring capabilities seem to be intact) while gaining additional support features for Groovy and Scala development.

I'm really looking forward to a greatly expanded IDEA audience. Many of those choosing Eclipse just because it is free now can reconsider their choice...

permlink: _.at: Intellij IDEA goes Open Source

Bolts 1.0 Functional Programming Library for Java

last change: 2009-09-15
While I still prefer Scala due to its concise syntax and ingenious type inference, this is certainly helpful when making functional programming more widely accessible. And the Collections API does look much nicer when seen through Bolts...

permlink: _.at: Bolts 1.0 Functional Programming Library for Java


last change: 2009-07-16
A typical state of Apache projects (except the Webserver) can be watched at the website presenting the Apache Logging / Log4J project:
Version 2 is "an experimental development branch for logging services designed for Java 5 and later." -- which in my understanding means, it was started several years ago (when Java 5 was new) and made no progress to date.
Better even the status of the 1.3 Branch: "log4j 1.3 development has been abandoned and no future releases or development is anticipated". The icing on this cake is the next sentence: "Users of log4j 1.3 are encouraged to migrate to log4j 1.2". No more questions, thank you.

permlink: _.at: Apache

Groovy Creator James Strachan on Scala

last change: 2009-07-07
The main point reflecting my own considerations on the subject Groovy vs. Scala:
"I can honestly say if someone had shown me the Programming Scala book by by Martin Odersky, Lex Spoon & Bill Venners back in 2003 I'd probably have never created Groovy."

I really like Scala being a statically typed language. And the elegant functional extensions to the object oriented modell are well worth learning this new language...

permlink: _.at: Groovy Creator James Strachan on Scala

David Pollak interview

last change: 2009-06-24
David Pollak on Scala and Lift.

Interesting excerpt regarding a test by Martin Odersky on perception of code:
"...no matter whether they were looking at Scala, Ruby or Java, they spent almost exactly the same time per language token looking at code, so if you say how few language tokens can we use to express our business logic, that's how fast somebody can look at the code and perceive it, that's how fast somebody can write the code because no matter what language you are writing in you write about the same number of line of code per day."

permlink: _.at: David Pollak interview

Monospaced Fonts for Programming

last change: 2009-06-16
A nice list of Fonts for programmers... Courier might not be your best bet ;-)

Update 16.06.2009:
Tried Consolas for a while and now switched to Anonymous Pro. Consolas 'f' tends to irritate me.

permlink: _.at: Monospaced Fonts for Programming

Using Intellij IDEA on windows as a client to a gitosis server

last change: 2009-05-05
Install the native Windows port msysGit from the Google Code page and follow the SSH public key setup instructions by Kyle Cordes given in the section 'Create your SSH Key'.

permlink: _.at: Using Intellij IDEA on windows as a client to a gitosis server


last change: 2009-04-28
Looking for a imperative/functional hybrid language running on top of the JVM? Take a look at Scala, the brainchild of Martin Odorsky.
Twitter adapted this language for their backend processing due to performance reasons (the interface still uses Ruby on Rails), IDEA supports it via a plugin, there is already some literature available...

permlink: _.at: Scala

all articles represent the sole opinion of their respective author. all content comes without any warranty for correctnes, despite due diligence.