Skip to content

Instantly share code, notes, and snippets.

View malcolmsparks's full-sized avatar

Malcolm Sparks malcolmsparks

View GitHub Profile

If you're using with SLF4J.

It's often useful to 'switch on' logging for a given web request, or during the evaluation of a given form, etc.

Add this to your logback.xml configuration:

  <turboFilter class="ch.qos.logback.classic.turbo.MDCFilter">
malcolmsparks / thoughts-on-yada.adoc
Last active January 22, 2023 19:24
Thoughts on yada

Thoughts on yada


Let’s define a framework as any library that contains one or more functions that accept callbacks.

Web frameworks are great for beginner developers who need to get stuff done. But they ultimately force you into a corner. In most applications, experienced developers need to retain control. Libraries are better.

malcolmsparks / dom.clj
Created February 17, 2021 08:13
XML DOM builder in Clojure
(defmacro dom [doc parent el]
(let [docsym (gensym "doc")
parentsym (gensym "parent")
elsym (gensym "el")]
`(let [~parentsym ~parent
[ens# enm#] ~(first el)
~docsym ~doc
~elsym (.createElementNS ~docsym ens# enm#)]
(for [item (next el)]
malcolmsparks / backup-photos.clj
Last active June 29, 2021 19:10
A babashka script for sorting and de-duping a photo collection on Linux.
#_( ;; Allow this script to be executed directly
"exec" "bb" -o "--classpath" "." "$0" "$@"
;; Copyright © 2020, Malcolm Sparks
;; Permission is hereby granted, free of charge, to any person obtaining a copy
;; of this software and associated documentation files (the “Software”), to deal
;; in the Software without restriction, including without limitation the rights
;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
malcolmsparks / vertx.clj
Created April 19, 2020 08:38
Starting a Vertx web server and handler
(defmethod ig/init-key ::http-server
[_ {:keys [vertx port]}]
(let [server
(new HttpServerOptions)
(setPort port))))]
malcolmsparks / charset.clj
Created March 29, 2020 18:01
Parsing the RFC 7231 Accept-Charset header with reap
;; Accept-Charset = *( "," OWS ) ( ( charset / "*" ) [ weight ] ) *( OWS
;; "," [ OWS ( ( charset / "*" ) [ weight ] ) ] )
(let [parser
(let [charset-with-weight
(re-pattern charset))
(re-pattern (re/re-str \*))))
(:require [clojure.set :as set])
;;#{[0 1] [1 1]}
;;what about if we're at [1 1]
;; Copyright © 2014-2017, JUXT LTD.
[byte-streams :as bs]
[bidi.bidi :refer [RouteProvider tag]]
[bidi.vhosts :refer [uri-for redirect]]
[ :refer :all]
[ :as io]
[schema.core :as s]
malcolmsparks / gist:16e5618ebb759f15f7fc938eacd5c9f4
Last active May 28, 2019 14:28
json path parsing in clojure
(ns juxt.jsonschema.formula
(:require [clojure.set :as set])
(defn partition-into-ranges-iter
"Find consecutive number sequences. O(n)"
(loop [[x & xs] (sort coll)
subsequent 0
curr []
malcolmsparks / reset.clj
Created May 6, 2018 08:56
Reset on HUP signal
(defn reset-on-hup []
(let [bindings (get-thread-bindings)]
(sun.misc.Signal. "HUP")
(reify sun.misc.SignalHandler
(handle [_ signal]
(with-bindings bindings
(println (reset))))))))