Skip to content

Instantly share code, notes, and snippets.

View raymcdermott's full-sized avatar

Ray McDermott raymcdermott

  • OpenGrail
  • Belgium
View GitHub Profile

If you're using clojure.tools.logging 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">
    <MDCKey>logging</MDCKey>
    <Value>on</Value>
(ns kafka.test-helpers
"Here, we define a simpler version of jackdaw's test-machine
Tries to capture the two essential features of jackdaw via
a simple functional interface rather than having to learn a
whole new data format to write tests.
See `journal`/`with-journal` and `wait-for` for the main
entrypoints to this ns.
@pablo-develop
pablo-develop / auto-convert-casing.clj
Created February 19, 2020 20:23
auto-convert-casing.clj
(ns example.server
(:require [camel-snake-kebab.core :as csk]
[clojure.spec.alpha :as s]
[clojure.string :as str]
[clojure.walk :as walk]
[muuntaja.core :as m]
[reitit.coercion.spec :as spec]
[reitit.dev.pretty :as pretty]
[reitit.ring :as ring]
[reitit.ring.coercion :as coercion]
@mfikes
mfikes / ESP32-REPL.md
Last active July 6, 2022 22:32
ClojureScript REPL into ESP32

To set up a REPL that has cljs.core available, we need to re-partition the ESP32 and allocate more memory in Espruino for "JsVars".

The default Espruino bootloader.bin, pre-built variants of partitions_esprinuo.bin and rebuilt espruino_esp32.bin, and the ClojureScript runtime core.bin are also available here.

bootloader.bin gets flashed to 0x1000, partitions_espruino.bin gets flashed to 0x8000, and espruino_esp32.bin gets flashed to 0x10000 as per a usual ESP32 Espruino setup, and we put the ClojureScript runtime at 0x2C0000:

Loading :advanced Code into an Unmodified WROVER running Espruino

You can load ClojureScript :advanced code directly into an ESP32 WROVER running Espruino for execution upon boot, by creating a binary and flashing it to the JavaScript "boot ROM" area. This has the same effect as when loading code via the Espruino Web IDE, in the "Direct to Flash (execute code at boot)" mode, but flashing is much quicker and more reliable.

Note: To do this, you'll need an ESP32 WROVER with SPI PSRAM, as opposed to just a WROOM, as the ClojureScript in this example uses more RAM than is available in the WROOM.

Create :advanced Code

Here is a small program that uses enough to pull in data structures, etc, leading to nearly 100 KiB:

@sashton
sashton / explore_datafy_nav.clj
Last active January 18, 2023 17:50
Clojure datafy/nav exploration
(ns explore-datafy-nav
"Sample code demonstrating naving around a random graph of data.
The graph very likely will have circular references, which is not a problem.
To see the results, execute the entire file.
Each step in the nav process will be printed out, as well as the initial db.
Subsequent executions will generate a new random db."
(:require [clojure.datafy :refer [datafy nav]]))
(defn generate-db
"Generate a random database of users and departments.
@ziluvatar
ziluvatar / token-generator.js
Last active April 11, 2024 07:10
Example of refreshing tokens with jwt
/**
* Example to refresh tokens using https://github.com/auth0/node-jsonwebtoken
* It was requested to be introduced at as part of the jsonwebtoken library,
* since we feel it does not add too much value but it will add code to mantain
* we won't include it.
*
* I create this gist just to help those who want to auto-refresh JWTs.
*/
const jwt = require('jsonwebtoken');
@thegeez
thegeez / spec_parsing.clj
Last active December 30, 2023 18:17
Parsing with clojure.spec for the Advent of Code challenge
(ns net.thegeez.advent.spec-parsing
(:require [clojure.string :as str]
[clojure.spec :as s]
[clojure.spec.gen :as gen]
[clojure.test.check.generators :as tgen]))
;; Dependencies:
;; [org.clojure/clojure "1.9.0-alpha14"]
;; [org.clojure/test.check "0.9.0"]
;; Advent of Code is a series of code challenges in the form of an advent
// ensure the keys being passed is an array of key paths
// example: 'a.b' becomes ['a', 'b'] unless it was already ['a', 'b']
const keys = ks => Array.isArray(ks) ? ks : ks.split('.')
// traverse the set of keys left to right,
// returning the current value in each iteration.
// if at any point the value for the current key does not exist,
// return the default value
const deepGet = (o, kp, d) => keys(kp).reduce((o, k) => o && o[k] || d, o)
@a2ndrade
a2ndrade / gist:5655005
Last active March 1, 2023 09:31
Datomic: containment relationships i.e. db/isComponent
(require '[datomic.api :as d])
(def uri "datomic:mem://test")
(d/create-database uri)
(def conn (d/connect uri))
(d/transact conn [;; Article
{:db/id #db/id [:db.part/db]
:db/ident :article/title
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one