Instantly share code, notes, and snippets.

View pedestal.clj
(defn- add-path-prefix [[path & more] prefix]
(vec (concat [(str prefix path)] more))) ;;TODO handle stray slashes
(defn- prepend-interceptors [[path verb chain & more] interceptors]
(let [new-chain (if (vector? chain)
(vec (concat interceptors chain))
(vec (concat interceptors [chain])))]
(vec (concat [path verb new-chain] more))))
View solver.clj
(ns sat.core
(:require [rolling-stones.core :as sat :refer [!]]
[clojure.string :as str]))
(def rows 9)
(def cols 9)
(def values 9)
(defn possible-square-values
View alias.clj
(defn ensure-namespace-alias [ns alias-sym]
(when-not (find-ns ns)
(create-ns ns))
(alias alias-sym ns))
(ensure-namespace-alias 'this.is.a.long.namespace 'long)
::long/foo => :this.is.a.long.namespace/foo
View pedestal-chain-diff.clj
(require '[io.pedestal.log :as log]
'[clojure.data :as diff]
'[io.pedestal.interceptor.chain :as chain])
(defn log-diffs [previous current]
(let [[deleted added] (diff/diff (dissoc previous ::chain/queue ::chain/stack ::previous-ctx)
(dissoc current ::chain/queue ::chain/stack ::previous-ctx))]
(when deleted (log/debug :deleted deleted))
(when added (log/debug :added added))))
View trace-forms.clj
;; there are quite a few cases where this code would not work, use with caution and check the macro expansion
(require '[clojure.walk :as walk])
(defn- clean-dont [form]
(walk/postwalk
(fn [form]
(if (and (list? form) (= 'dont (first form)))
(second form)
form))
View strict_keys.clj
;;; strict keys mode for spec
;; disclaimer: untested, most likely buggy
(require '[clojure.spec.alpha :as s])
(require '[clojure.walk :as walk])
(defmacro only-keys
[& {:keys [req req-un opt opt-un] :as args}]
`(s/and (s/keys ~@(apply concat (vec args)))
View spec.clj
(gen/generate (s/gen (:args (s/get-spec (resolve `calculate-limits)))))
View beam.clj
(let [p (Pipeline/create (PipelineOptionsFactory/create))]
(doto
(.. p
(apply TextIO.Read/from ("..."))
(apply "ExtractWords"
(ParDo/of (reify DoFn
(processElement [this context]
...
))))
(apply (Count/perElement))
View windows.el
(require 'hydra)
(global-set-key (kbd "§") 'hydra-windows/body)
(make-face 'move-window-buffer-face)
(set-face-attribute 'move-window-buffer-face nil
:background "#073642")
(setq ss/window-move-remap-cookie nil)
(defun remove-window-move-indicator ()
(if ss/window-move-remap-cookie
(face-remap-remove-relative
View naive_diff.clj
(defn lcs [as bs]
(if-not (and as bs)
[]
(let [[a & ra] as
[b & rb] bs]
(if (= a b)
(cons a (lcs ra rb))
(let [la (lcs as rb)
lb (lcs ra bs)]
(if (> (count la) (count lb)) la lb))))))