ClojureWise

Small and furry, well ... definitely furry. [source]

Sunday, August 14, 2011

Backing down

Seems like my affair with Clojure is coming to an end, don't expect too many posts in the future :)

(But who knows, I might be wrong)

Friday, June 17, 2011

Create "executable" Clojure programs

Sometimes you want to distribute one executable. You can create a standalone uberjar (using lein uberjar), however the user still need to call java -jar . One wait is to use one of the Java installers out there.

Another simple way is to embed the jar in a script (we'll use base64 here). And then have the script extract the jar and run Java on it. (Note that I'm using the base64 utility that comes with Linux, you can probably use MIME::Base64 as well).


EDIT: Seems like there is a simpler solution.

Friday, April 15, 2011

Graphing Metrics

At work, we have a lot of metrics. These really help us diagnose problems when things go South. On of the conventions is that every server exposes a URL for metrics in plain text, where every line is in the format "metric: value".

You can track a metric simply by running

watch 'curl -s localhost:8001/metrics | grep metric2'
However this will only bring you the current value. I personally prefer graphs, so I wrote this little Clojure application that let you pick URLs and metrics to follow, then displays graphs for these metrics. It's a small web server where the UI is the browser (which will open automagically when you run the program).

Here's the main screen:

And here's the configuration screen

What's nice about this project is that you can build a single "uberjar" and give it away to people.

Technologies used:
As usual, the sources at at bitbucket

(Note that the demo server there also have a dummy /metrics handler that generate random metrics).

Thursday, March 17, 2011

Static resources in Compojure "uberjar"

I've wrote a little web server to show some graphs at work, and wanted to distribute it as an "uberjar". James Reeves was kind enough to supply an answer.

What you need to do:
  • Place your files under resources/public
  • Add (route/resource "/") to your handler map
    •  And (require '[compojure.route :as route]) somewhere before
  • Add :resources-path "resources" to project.clj
After that you can access your resources both when developing and from the jar.

See an example here.

Sunday, February 27, 2011

csvlib - A library for reading/writing CSV files

csvlib is a library for reading and writing CSV files. It is based on CSVReader which we use here a lot a Adconion.

csvlib will try to do the right thing™ It can write either vectors or hash maps and supports formatters and converters (for writing/reading).

The code is not that long, let me know if you find any bugs.

Thursday, February 24, 2011

digest 1.2.0 is out

Updated digest with methods to do files digest and more. Thanks to 
Benoit who reported a bug.

Monday, February 14, 2011

popen - A sub process library

A small library to ease the pain of launching sub processes and reading/writing from/to them. The library lives here.

Use [popen "0.1.0"] in your project.clj.