Skip to main content

Open Source Consultant, Software Developer and System Administrator

If you are interrested in hiring a consultant for the effective use of open source software on an enterprise grade, take a look around in the About section to see, what I have to offer.

Blog and snippets

Various snippets or code parts I found useful, so I keep them here for reference.

How to start a Clojure REPL since the Specs Alpha change

With the recent change in Clojure to use dedicated artifacts for Spec in an alpha sub-namespace, it is no longer easy to start a simple REPL just with the regular jar (e.g. java -jar $CLOJURE_JAR clojure.main). So how to start it now?

As of before you are better off to do a lein new somewhere, change the org.clojure/clojure dependency to the version you like and do a lein deps :tree to fetch all that is needed and display what things org.clojure/core now depends on. E.g.

[org.clojure/clojure "1.9.0-alpha17"]
   [org.clojure/core.specs.alpha "0.1.10" :exclusions [[org.clojure/clojure] [org.clojure/spec.alpha]]]
   [org.clojure/spec.alpha "0.1.123" :exclusions [[org.clojure/clojure]]]

All your artifacts end up in ~/.m2/repository. So next you have to build up your classpath to call the REPL. You can either run a lein cp in that dummy project to get the class path Leiningen is using (which often can be quite long depending on all the plugins you run. Or you can guess the locations from the versions above to build up the params for -cp for yourself.

M2="$HOME/.m2/repository"
java -cp $M2/org/clojure/clojure/1.9.0-alpha17/clojure-1.9.0-alpha17.jar:$M2/org/clojure/spec.alpha/0.1.123/spec.alpha-0.1.123.jar:$M2/org/clojure/core.specs.alpha/0.1.10/core.specs.alpha-0.1.10.jar: clojure.main

This is a very basic setup to get a basic REPL going, but paired with rlwrap this is a few times faster to fire up than a lein repl, which makes it perfect to quickly fool around with some ideas.

On the horizon to streamline this, there is https://github.com/clojure/tools.deps.alpha.

Generic Vaadin8 field for converted values

In Vaadin8 the conversion between the model data type and the field is done in the Binder. This prevents automatic mapping for the models as some manual step must be done beforehand. But since writing custom fields now is way more reasonable, here is a first draft for a generic converter field. Just provide the backing Field and an Converter.

https://gist.github.com/christoph-frick/947fec59cfd09f7140933b52102cc041

Null representation needed when using converters in Vaadin 8 binder

TextFields in Vaadin8 are no longer allowed to get a null set as value. This usually is no problem unless we use a Converter for the field binding. In that case a null value about to be bound will raise an assertion error. It also won't help if that field is bound with asRequired.

The solution in this case is to use withNullRepresentation before adding the Converter in the binding builder. This adds another converter at first, that turns null values into "something" so the real converter has to actually work.

See

https://github.com/christoph-frick/try-vaadin8/commit/8eee2ce6880b7a3dd4ce1526cf533ef356d3ec50

and

https://github.com/vaadin/framework/issues/8725