This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (import '[java.io RandomAccessFile]) | |
| (require '[clojure.math.numeric-tower :refer [ceil]]) | |
| (require '[clojure.string :as str]) | |
| (defrecord Piece [file start end]) | |
| (defn handle | |
| ([file] | |
| (RandomAccessFile. file "r")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; Example | |
| (defn make-query-request [{parent-id :parent-id}] | |
| {:table-name "my-table" | |
| :query {:parent-id parent-id}}) | |
| (defn make-get-request [id] | |
| {:table-name "my-table" | |
| :get {:s id}}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns scratch.xml | |
| (:require [clojure.data.xml :as xml]) | |
| (:gen-class)) | |
| (declare xml-fn) | |
| (defn resolve-namespace [ns n] | |
| (some-> n | |
| symbol | |
| ((ns-aliases ns) n) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defn tag [k & tuple] | |
| (concat [k] tuple)) | |
| (def effect (partial tag :effect)) | |
| (defn tagged [k v] | |
| (when (and (sequential? v) (= k (first v))) | |
| (rest v))) | |
| (defn run-effectfully [& args] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns scratch.pipe | |
| (:gen-class)) | |
| ;; # Stepping functions | |
| (defn p-step | |
| "Lift a function into a pipeline function that runs, then passes onto the | |
| next function in the pipeline" | |
| [f] | |
| (fn [v p] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defn neighbours-simple [[x y]] | |
| #{[(dec x) (dec y)] [x (dec y)] [(inc x) (dec y)] | |
| [(dec x) y ] [(inc x) y] | |
| [(dec x) (inc y)] [x (inc y)] [(inc x) (inc y)]}) | |
| (defn neighbours-zipped [[x y]] | |
| (let [axis (juxt dec identity inc)] | |
| (clojure.set/difference | |
| (set (mapcat (partial map vector) | |
| (repeat (axis x)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; in the library | |
| ;; ... [reagi :as r] | |
| ;; [cloduino :as c] | |
| (defn digital-writer [board pin] | |
| (c/pin-mode board pin OUTPUT) | |
| (partial c/digital-write board pin)) | |
| (defn digital-reader [board pin] | |
| (c/pin-mode board pin INPUT) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; split-map sketch, after discussion with justin_smith | |
| (defn split-map [fn m] | |
| (->> m | |
| (group-by fn) | |
| (sort-by key) | |
| (map (comp (partial into {}) val)))) | |
| (comment | |
| (split-map (comp even? val) {:foo 1 :bar 2 :baz 3})) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; # Minimal logging library | |
| ;; | |
| ;; Principles: | |
| ;; | |
| ;; - https://12factor.net/logs | |
| ;; - single appender, e.g. STDOUT | |
| ;; | |
| ;; - functions all the way down | |
| ;; | |
| ;; - just Clojure data-structures |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;;; this works | |
| boot.user=> (def merge-2 (partial merge-with (partial merge-with merge))) | |
| #'boot.user/merge-2 | |
| boot.user=> (merge-2 {:a {:b {:c 1}}} {:a {:b {:d 2}}}) | |
| {:a {:b {:c 1, :d 2}}} | |
| ;;; but this doesn't | |
| boot.user=> (declare merge-rec) | |
| #'boot.user/merge-rec | |
| boot.user=> (def merge-rec (partial merge-with merge-rec)) |