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.

Can't leave out variadic args in Java interop with Clojure

When calling interop functions into Java land with Clojure you have pass an empty array. While it's OK in Java/Groovy/... to:

RatpackPac4j.requireAuth(SAML2Client)

... you have to pass an empty array in Clojure:

(RatpackPac4j/requireAuth SAML2Client (into-array Authorizer []))

Split a sequence by function in Clojure

Split a collection on the sequence of elements, that match it.

(defn split-by
  ([pred]
   (comp (drop-while pred)
         (partition-by pred)
         (take-nth 2)))
  ([pred coll]
   (sequence (split-by pred) coll)))
; (split-by zero? [1 0 2 0 3]) => ([1] [2] [3])

Clojure REST-REPL

While tools like httpie give you a nice way to query web APIs, they only give you the means to query data easily and print the results nicely. Once you need to modify the results or need to drill down on them, you are on your own.

Therefor I wrote my own tool - REST REPL. It starts a Clojure REPL with some state handling (imagine cd from the shell), preloaded libraries, that make your live easier (clj-http, specter, clojure.data.xml, cheshire) and make it pretty print (with colors) the results using puget.

Since this is a (close to) regular Clojure REPL, you can handle the data as you are used too and you can place reoccurring code into functions.

Run Springboot fatjar with Palantir Docker Gradle plugin

When creating Docker images for a Springboot project using the Palantir Docker plugin I found no easy way to pick up the fat jar from the bootRepackage task.

One way around this is to set each the jar and the bootRepackage tasks as dependencies. The jar tasks provides the output (which the Docker plugin will pick up) and the bootRepackage actually generates the proper file (with the same name).

docker {
    name "ofnir/app:${project.version}"
    dependsOn tasks.jar, tasks.bootRepackage
}

Provide a fixed name for the jar, so it's easier to refer from the Dockerfile:

jar {
    baseName = 'ofnir-app'
    version = null
    manifest {
        attributes 'Main-Class': mainClassName
    }
}

This will generate ofnir-app.jar.

Then a Dockerfile can be as simple as:

FROM java:8
EXPOSE 8080
COPY onfir-app.jar /usr/local/
WORKDIR /tmp
CMD ["java", "-jar", "/usr/local/onfir-app.jar"]