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.

TIL: collectEntries in Groovy also accepts a map input

collectEntries in Groovy works on collections: an optionally passed closure (otherwise identity is used) must return either tuples (two element arrays/lists -- think key and value) or maps and it turns that into a map. E.g.:

// → [1:2, 3:4]
[[a: 1, b: 2],[c: 3]].collectEntries()
// → [a:1, b:2, c:3]
[1,2,3].collectEntries{ [it, it] }
// → [1:1, 2:2, 3:3]

So this creates maps. But what map exactly? Educated guess: LinkedHashMap, which is also the implementation the Groovy map literal uses. Let's check:

// → class java.util.LinkedHashMap

So what if we want another data structure? A not so well know feature (at least to me), is the possibility to pass in an existing map.

So this can be used to pick an appropriate data type:

[3,2,1].collectEntries(new TreeMap()){ [it, it] }
// → [1:1, 2:2, 3:3]

Or to append to an existing map:

[1,2,3].collectEntries([(0): 0]){ [it, it] }
// → [0:0, 1:1, 2:2, 3:3]

Run Cargo via Docker for local development

My setup to run cargo via Docker as the current user. Put that in your Makefile or as shell alias.

docker run --rm -ti \                            # run, remove afterwards, use terminal
        -w /src -v `pwd`:/src \                  # map cwd to /src and make it the WORKDIR
        --user `id -u`:`id -g` -e USER=`id -u` \ # map to current user
        -e CARGO_HOME=/src/.cargo_registry \     # change the CARGO_HOME into the src
        rust:1.38 \                              # image:version

(Note: don't add the comments, the shell won't kike it)

Figwheel with Vim-Fireplace 2.0

With recent changes in Cider and the new Vim-Fireplace 2.0 release, let's update the setup for it.

In a project created by e.g. lein new figwheel hello-world, add the new setup for Ciders Piggieback:

:profiles {:dev {:dependencies [[cider/piggieback "0.4.1"]]
                 :repl-options {:nrepl-middleware [cider.piggieback/wrap-cljs-repl]}}}

Merge this settings with existing code from the template. Note, that both the group of the artifact and the namespace for Piggieback changed.

With the template you can not open Vim, start the REPL, and run (fig-start).

Now with Vim-Fireplace 2.0 to work via Piggieback, you call:

:CljEval (cider.piggieback/cljs-repl (figwheel-sidecar.repl-api/repl-env))