Skip to content

Instantly share code, notes, and snippets.

View whamtet's full-sized avatar

Matthew Molloy whamtet

View GitHub Profile
(defn- mk* [m [a b & rest]]
(keyword? a) (recur (assoc m a b) rest)
a (recur (assoc m (keyword a) (symbol a)) (list* b rest))
:else m))
(defmacro mk [& syms]
(mk* {} syms))
# mount -o remount,rw /media/mmcblk0p1
(def hidden-matcher #"(#)?([^\.]+)\.?(.+)?")
(defmacro hiddens [& args]
~@(for [[k-str v] (partition 2 args)]
(let [[_ id? k class] (re-find hidden-matcher k-str)]
[:input (cond-> {:type "hidden" :name k}
id? (assoc :id k)
class (assoc :class class)
(not= nil v) (assoc :value v))]))))
(defn sh
[dir & args]
(let [proc (.exec (Runtime/getRuntime)
^"[Ljava.lang.String;" (into-array args)
(make-array String 0)
(io/as-file dir))]
(with-open [stdout (.getInputStream proc)
stderr (.getErrorStream proc)]
(future (io/copy stdout *out*))
(future (io/copy stderr *err*))
(defn modal-scroll [width & contents]
[:div#modal {:class "fixed left-0 top-0 w-full h-full
:style {:background-color "rgba(0,0,0,0.4)"}
:_ "on click if === 'modal' add .hidden"}
[:div {:class (str "mx-auto border rounded-lg bg-white overflow-y-auto overflow-x-clip " width)
:style {:max-height "94vh"
:margin-top "3vh"
:margin-bottom "3vh"}}
(def cors-headers
{"Access-Control-Allow-Origin" "*"
"Access-Control-Allow-Methods" "POST, GET, OPTIONS, DELETE"
"Access-Control-Allow-Headers" "*"
"Access-Control-Expose-Headers" "*"})
(defn wrap-cors [handler]
(fn [req]
(if (-> req :request-method (= :options))
{:status 200
(defmacro format-js [s]
`(-> ~s
~@(for [[to-replace replacement] (re-seq #"\{([^\}]+)}" s)]
`(string/replace-first ~to-replace ~(read-string replacement)))))
(ns scripts.simplify-svg
[clojure.string :as string])
(defn- map-rest [f [x & rest]]
(map f rest)
(ns email-edit.core
(def encoder (Base64/getMimeEncoder))
(def decoder (Base64/getMimeDecoder))
(defn decode [^String s]
(String. (.decode decoder s)))
(defn encode [^String s]
#!/usr/bin/env bb -i
;; Usage:
;; Install babashka at
;; put this script on PATH and make it executable
;; copy logs to the clipboard
;; to filter SimpleAsyncTaskExecutor-3 run
;; pbpaste | slct.clj 3
(require '[clojure.string :as string])