Saturday, July 7, 2012

Formula Evaluation in Apache POI (or jxls)

Wasted an afternoon on this. If you create formulas in Apache POI or jxls, you need to force Excel to recalculate, otherwise you get the value from your template.  See link below !

Formula Evaluation: wb.setForceFormulaRecalculation(true);

Monday, March 19, 2012

Installing QJoyPad on Linux (Ubuntu, Mint)

After searching high and low, stumbled upon this post on how to install qjoypad, a useful application to turn a USB gamepad into a keyboard for playing games, or for using gamepads as control devices for sports refereeing applications.  The article is in French. Search qjoypad in the page (it is at the bottom).  I was not able to use apt-get to retrieve the package as stated, but adding the repository to synaptic, giving it the GPG authentication key, and using synaptic to retrieve the package all worked just fine.

Much easier than downloading half the universe to compile the thing.

Monday, February 20, 2012

Packaging third-party jars with project

A problem with Maven is when some jars are not publicly available, yet need to be published with the project -- otherwise the source won't compile or the program won't run. When doing it for yourself, you can always "mvn install" the jars so they are found in the local cache, or push them to a local repository. But this doesn't work when others need to checkout your source... And the winner is...

Leonid Dubinsky's Blog: Maven in-project repository

Sunday, January 30, 2011

Running Mercurial hg serve on Linux, allowing push

In a previous post I showed how to run "hg serve" on Windows.  I then tried the same approach on Linux, and things did not quite work the same.

After much tinkering, here is my recipe for running on Linux.

1) Create a directory called /var/hg

2) Create a file called /var/hg/hg.conf with the following content -- this peculiar directive states  all subdirectories of /var/hg/repos are treated as repositories and can be accessed directly using the subdirectory name (e.g. /var/hg/repos/myrepo is accessed as myrepo).

/var/hg/repos = /var/hg/repos

3) Create a directory called /var/hg/repos -- this is where you will create the repositories

4)  Create a repository as follows (repeat for any repository you want to create).
cd /var/hg/repos
mkdir myrepo
cd myrepo
hg init

5) Edit /etc/mercurial/hgrc and add the following lines to allow pushing

push_ssl = false
allow_push = *

6) Create a file /etc/init.d/hg.init and make it executable (chmod a+x) with the following contents

# Startup script for mercurial server.
# Change following ines
SRCNAME=" package source"
# Path to PID file of running mercurial process.


case "$state" in
    echo "Mecurial Server service starting."
   (cd ${SRC} ;${APP_BIN} serve -d --webdir-conf ${SRC}/hg.conf -p 8000 --pid-file ${PID_FILE})

  if [ -f "${PID_FILE}" ]; then
    PID=`cat "${PID_FILE}"`
    if [ "${PID}" -gt 1 ]; then
      kill -TERM ${PID}
      echo "Stopping the Mercurial service PID=${PID}."
      echo Bad PID for Mercurial -- \"${PID}\"
    echo No PID file recorded for mercurial

  echo "$0 {start|stop}"
  exit 1

7) You can now start the server (the -p 8000 parameter in the script makes it listen on port 8000)
/etc/init.d/hg.init start

Wednesday, January 26, 2011

Running a simple Mercurial server (hg serve) and allowing push

I've been using mercurial (via Google Code Repository) as a simple solution for version control. The best feature is that Mercurial (hg for short) allows me to commit things to the repository that no-one else sees until I "push" them out (committing and pushing are two separate operations).

Lately I've had a need to quickly share code for an internal, non-FOSS project.  Running an internal hg server seems, at first glance, much harder than for SVN or CVS : while there is a simple "hg serve" command, the documentation is sparse, and in fact misleading.  The documentation would have you believe that hg serve is read-only, whereas it is not.  There are a few tricks required to run it as a cheap solution just for sharing between colleagues and avoiding the "oops, lost my laptop" issues.

First, run the program in daemon mode, and force it to read a config file:
hg serve -d --web-config E:\hg\config.txt

The following configuration file (config.txt in the command-line above) allows you a)  to have multiple repositories b) enables your colleagues to push changes and c) does not require an SSL connection.

e:\hg = e:\hg

allow_push = *
push_ssl = false

Obviously, the setup is insecure, and is meant for private LANs or VPNs -- anything sensitive should use the more tedious solutions that rely on Apache and SSL.

Tuesday, October 12, 2010

Jetty Maven Plug-in vs Native Libraries.

My web application at uses a native library to drive a LED display.  I could not get it to reload correctly under the Jetty Maven Plug-in because of a
java.lang.UnsatisfiedLinkError: Native Library foo.dll already loaded in another classloader

The solution is very easy:
  • Find the jar that invokes the native library.
  • Locate the dependency  for that jar in the pom.xml file.
  • Move the dependency so that it is inside the dependencies section  of the Jetty plugin.  By making it a dependency of the Jetty plugin (as opposed to a dependency of your application), Jetty won't try to reload it and won't mess up the classloaders
Kudos to David Yu's suggestion on a forum.