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.

Require local Babashka scripts

When writing more involved Babashka scripts, we usually want to extract some common functionality out into library files. Yet there seems to be no established default, where Babashka is looking for those. So if you want to require a lib-namespace, you can set it up like this:

  • Create a (or lib.clj) file; if both exist, the .bb one is used; add (ns lib) to the top.
  • Add . to the class-path.

The later can be done via:

  • Run Babashka with the -cp parameter:
bb -cp .
  • Create a bb.edn file and set :paths:
{:paths ["."]}

Slightly more involved ways can be found in the project setup section of the Babashka docs

Search Maven artifacts with Babashka

Since Maven Central changed the search I had to fix my helper script. Time to try out Babashka.

#!/usr/bin/env bb
(defn artifact [{:keys [g a v latestVersion]}]
  (str g ":" a ":" (or v latestVersion)))

(defn query [q]
  (let [query-params {:start 0 :rows 50}]
    (if (str/includes? q ":")
      (let [[g a] (str/split q #":" 2)]
        (assoc query-params
               :q (str "g:" g " AND " "a:" a)
               :core "gav"))
      (assoc query-params :q q))))

(defn request [q]
  (-> (org.httpkit.client/get
        {:content-type "application/json"
         :query-params (query q)})
      (cheshire.core/parse-string true)

(assert (= 1 (count *command-line-args*)))

(let [[q] *command-line-args*]
  (->> (request q)
       (map artifact)
       (run! prn)))