This file contains 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 proxy-byte-channels-example | |
(:import (java.io InputStream | |
OutputStream) | |
(java.nio ByteBuffer) | |
(java.net UnixDomainSocketAddress | |
StandardProtocolFamily) | |
(java.nio.channels ByteChannel | |
SocketChannel) | |
(java.nio.charset StandardCharsets))) |
This file contains 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 byte-channels-example | |
(:import (java.io InputStream | |
OutputStream) | |
(java.net UnixDomainSocketAddress | |
StandardProtocolFamily) | |
(java.nio.channels ByteChannel | |
SocketChannel | |
Channels) | |
(java.nio.charset StandardCharsets))) |
This file contains 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
{:paths ["src/main"] | |
:deps {org.clojure/clojure {:mvn/version "1.12.0-alpha11"} | |
ring/ring-core {:mvn/version "1.12.1"} | |
info.sunng/ring-jetty9-adapter {:mvn/version "0.33.1"} | |
metosin/jsonista {:mvn/version "0.3.8"}}} |
This file contains 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
#!/usr/local/bin/bb | |
(require '[clojure.java.shell :as sh] | |
'[clojure.string :as str]) | |
(import '(java.util.concurrent TimeUnit) | |
'(java.time ZoneId ZonedDateTime) | |
'(java.time.format DateTimeFormatter)) | |
This file contains 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
-- | |
-- Helper function to produce a diff of two jsonb values. | |
-- | |
-- Accepts: | |
-- val1: original jsonb value | |
-- val2: updated jsonb value | |
-- | |
-- Returns: | |
-- jsonb of changed values | |
-- |
This file contains 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 datomic-spike.audit-trail | |
(:require [datomic.api :as d])) | |
(defn entity-txs | |
"Accepts an entity, returns all transactions (as entities) that | |
have altered the given entity, sorted by transaction t" | |
[e] | |
(let [id (:db/id e) | |
db (d/entity-db e) | |
history (d/history db)] |
This file contains 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
(def authors [{:first "Margaret" :last "Atwood" :books 15} | |
{:first "Doris" :last "Lessing" :books 67} | |
{:first "Ursula" :last "Le Guin" :books 23} | |
{:first "Alice" :last "Munro" :books 21}]) | |
(defn get-name [author] | |
(get author :first)) | |
(defn first-name-short? [author] | |
(let [first-name (get-name author) |
This file contains 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
; start with: lein try clj-http | |
(require '[clj-http.client :as http]) | |
(defn fetch-random-users [n] | |
(->> (http/get "http://api.randomuser.me/" {:query-params {:results n} :as :json}) | |
:body | |
:results | |
(map :user))) | |
This file contains 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
(defmacro << [& body] | |
(let [[fmt args] (loop [fmt "" | |
args [] | |
[p & more] body] | |
(if p | |
(cond | |
(and (symbol? p) (starts-with (name p) "%")) (recur (str fmt (name p)) (conj args (first more)) (rest more)) | |
(symbol? p) (recur (str fmt "%s") (conj args p) more) | |
(string? p) (recur (str fmt (str p)) args more) | |
:else (recur (str fmt "%s") (conj args p) more)) |