
![[RSS Feed]](/img/feed-icon32x32_1.png)
Get the GIT commit ID
permlink: _.at: Get the GIT commit ID
Doing XSL and FOP transformations on the commandline using Saxon and Apache FOP
# 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
Setup a DBCP datasource for H2 Database connections
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 {
Class.forName(DRIVER_CLASS_NAME);
} catch (ClassNotFoundException e) {
Logger.getLogger(AppConfigurator.class).warn(e);
} // seehttp://commons.apache.org/dbcp/configuration.html
BasicDataSource dataSource = new BasicDataSource();
dataSource.setUsername(dbProperties.getProperty("dbuser"));
//dataSource.setPassword(password);
dataSource.setDriverClassName(DRIVER_CLASS_NAME);
dataSource.setUrl("jdbc:h2:file:" + dbProperties.getProperty("dbfile"));
final int maxConnections = Integer.parseInt(dbProperties.getProperty("maxConnections"));
dataSource.setMaxActive(maxConnections);
dataSource.setMinIdle(1);
if(maxConnections>20)
dataSource.setMaxIdle(20);
dataSource.setMaxWait(20);
// 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);
}
}
Maven Dependencies
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>
<name>Download</name>
<groupId>at.compass</groupId>
<artifactId>Download</artifactId>
<version>1.0.0</version>
<description>Download Maven dependencies</description>
<dependencies>
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
</project> 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
And on Postgres:
SELECT (TIMESTAMP WITH TIME ZONE 'epoch' + unix_tstamp * INTERVAL '1 second')::date
permlink: _.at: Unix Timstamps in SQL
Scala problems
"(...) 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
permlink: _.at: Node Package Manager via Squid
Servlets with Clojure
HTTP Date format in Java
{
SimpleDateFormat httpDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
httpDateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); return httpDateFormat.format(date);
}
permlink: _.at: HTTP Date format in Java
Querying MongoDB from Clojure using regex Prefix matches
(:use somnium.congomongo)) (def mongo-server "mongo.test")
(def mongo-db "testdb")
(def mongo-collection "indexedtestcollection") (defn find-test [input]
(mongo!
: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).
Print a stacktrace in Clojure REPL
user=> (print-stack-trace *e 10)
permlink: _.at: Print a stacktrace in Clojure REPL
MySQL: JDBC Connect String with UTF-8 encoding
Fileupload in Servlets
Links:
Servlets.com: com.oreilly.servlet
Jason Hunter, William Crawford: Java Servlet Programming (Amazon)
Servlets.com: com.oreilly.servlet
Jason Hunter, William Crawford: Java Servlet Programming (Amazon)
permlink: _.at: Fileupload in Servlets
IDEA with Mercurial Plugin
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: [extensions]
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
JavaScript grows up
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
permlink: _.at: Intellij IDEA goes Open Source
Bolts 1.0 Functional Programming Library for Java
Apache
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
"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...
David Pollak interview
"...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
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
Scala
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...
Links:
artima.com: Twitter on Scala
Martin Odersky: Programming in Scala (Amazon)
The Scala Programming Language
artima.com: Twitter on Scala
Martin Odersky: Programming in Scala (Amazon)
The Scala Programming Language
permlink: _.at: Scala
all articles represent the sole opinion of their respective author. all content comes without any warranty for correctnes, despite due diligence.