Skip to content

Instantly share code, notes, and snippets.

@yogthos
yogthos / clojure-beginner.md
Last active April 18, 2025 02:43
Clojure beginner resources

Introductory resources

@eviltester
eviltester / gist:11093f0e4c501a41990e227393184eda
Last active February 14, 2025 09:30
uncheck twitter interests
var timer=100;document.querySelectorAll("div > input[type='checkbox']:checked").forEach((interest) => {setTimeout(function(){interest.click()},timer);timer+=2000;});
@mourjo
mourjo / with-local-redefs.clj
Last active July 27, 2024 12:07 — forked from gfredericks/with-local-redefs.clj
thread-local version of with-redefs
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Commentary ;;
;; ;;
;; The goal for writing this started with the idea to have tests run in ;;
;; parallel using the leiningen plugin eftest ;;
;; https://github.com/weavejester/eftest. ;;
;; ;;
;; With tests using with-redefs, it was not possible to run them in ;;
;; parallel if they were changing the root binding of the same ;;
;; vars. Here, we are binding the root of the var to one function that ;;
@sashton
sashton / explore_datafy_nav.clj
Last active October 25, 2024 01:51
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.
@mfikes
mfikes / lein-tools-deps-cursive.md
Last active October 31, 2020 12:35
Using `lein-tools-deps` from Cursive (on macOS)

Note: These workarounds covered issues in lein-tools-deps 0.3.0-SNAPSHOT. If using 0.4.1 or later, you should not encounter the issues below.

The following provides some workarounds for some issues when using lein-tools-deps from Cursive on macOS.

Path to clojure

By default, the lein-tools-deps plugin won't see /usr/local/bin/clojure when Cursive processes project.clj, as it evidently has a degenerate path.

You will see an error like the following in the IntelliJ Event Log when it tries to process your project.clj file:

@favila
favila / last-touched-tx.clj
Created February 27, 2018 23:41
datomic query to return the tx at which an entity or its components were last touched
(require '[datomic.api :as d])
(defn last-touched-tx
"Return the tx of the oldest assertion on `entity` or any of its components."
[db entity]
(or (d/q '[:find (max ?tx) .
:in $ % ?root
:where
(component-entities ?root ?ce)
(union ?root ?ce ?e)
[?e _ _ ?tx]]
@green-coder
green-coder / tree-seq.clj
Last active April 8, 2018 20:43 — forked from mfikes/tree-seq.clj
Directly-reducible PoC in Clojure
(defn nth' [coll n]
(transduce (drop n) (completing #(reduced %2)) nil coll))
(defn tree-seq'
[branch? children root]
(eduction (take-while some?) (map first)
(iterate (fn [[node pair]]
(when-some [[[node' & r] cont] (if (branch? node)
(if-some [cs (not-empty (children node))]
[cs pair]
@robert-stuttaford
robert-stuttaford / build.clj
Last active August 1, 2018 14:18
Basic nREPL / cljs compile / cljs repl / figwheel script for use with clj cli command: `clj build.clj TASK`
(require '[cljs.build.api :as api]
'[clojure.string :as string]
'[figwheel-sidecar.repl-api :as figwheel]
'[figwheel-sidecar.components.nrepl-server :as figwheel.nrepl])
(def source-dir "src")
(def compiler-config
{:main 'app.main
:output-to "target/app.js"
@roman01la
roman01la / core.clj
Created February 4, 2018 16:46
Parsing with clojure.spec
(require '[clojure.spec.alpha :as s])
[:h1 {} "0" 1 [:span]]
(s/def :hiccup/form
(s/or
:string string?
:number number?
:element :hiccup/element))
@mfikes
mfikes / tree-seq.clj
Last active May 22, 2020 21:03
Directly-reducible PoC in Clojure
(defn nth' [coll n]
(transduce (drop n) (completing #(reduced %2)) nil coll))
(defn tree-seq'
[branch? children root]
(eduction (take-while some?) (map first)
(iterate (fn [[node pair]]
(when-some [[[node' & r] cont] (if (branch? node)
(if-some [cs (not-empty (children node))]
[cs pair]