Skip to content

Instantly share code, notes, and snippets.

View jarohen's full-sized avatar
⚒️

James Henderson jarohen

⚒️
View GitHub Profile
@jarohen
jarohen / rafting.clj
Last active September 12, 2023 16:12
A quick hack at actually implementing the Raft algorithm to aid my learning - thanks @bbengfort and @krisajenkins for the podcast!
(ns rafting
(:require [clojure.tools.logging :as log])
(:import java.lang.AutoCloseable
(java.util.concurrent CompletableFuture Executors TimeUnit)))
(defn new-timeout-ms []
(+ (System/currentTimeMillis)
200
(rand-int 150)))
(let [bytes (with-open [os (java.io.ByteArrayOutputStream.)
oos (java.io.ObjectOutputStream. os)]
(.writeObject oos false)
(.toByteArray os))]
(with-open [is (java.io.ByteArrayInputStream. bytes)]
(if (.readObject (java.io.ObjectInputStream. is))
:truthy
:falsy))) ; => :truthy
clojure-agent-send-off-pool-3" #24 prio=5 os_prio=0 tid=0x00007f270800b000 nid=0xea3 runnable [0x00007f270eabf000]
java.lang.Thread.State: RUNNABLE
at clojure.lang.Numbers$LongOps.lt(Numbers.java:521)
at clojure.lang.Numbers.gt(Numbers.java:229)
at mranderson046.toolsreader.v0v10v0_alpha3.clojure.tools.reader.reader_types.StringReader.read_char(reader_types.clj:51)
at mranderson046.toolsreader.v0v10v0_alpha3.clojure.tools.reader.reader_types.PushbackReader.read_char(reader_types.clj:86)
at mranderson046.toolsreader.v0v10v0_alpha3.clojure.tools.reader.edn$read_token.invoke(edn.clj:60)
at mranderson046.toolsreader.v0v10v0_alpha3.clojure.tools.reader.edn$read_token.invoke(edn.clj:41)
at mranderson046.toolsreader.v0v10v0_alpha3.clojure.tools.reader.edn$read_symbol.invoke(edn.clj:241)
at mranderson046.toolsreader.v0v10v0_alpha3.clojure.tools.reader.edn$read.invoke(edn.clj:373)
@jarohen
jarohen / bug.clj
Last active September 22, 2015 14:22
reagent bug?
(defn child-1 [!cnt]
(let [cnt @!cnt]
(prn "child-1-mount")
(fn [!cnt]
(prn "child-1-render")
[:div
"child-1"])))
(defn parent-component []
(let [!count (r/atom 0)]
### Keybase proof
I hereby claim:
* I am jarohen on github.
* I am jarohen (https://keybase.io/jarohen) on keybase.
* I have a public key whose fingerprint is 091B 87FA 0F5D AE6F 0331 D013 956F 20CA 2105 F582
To claim this, I am signing this object:
@jarohen
jarohen / yoyo.clj
Last active August 29, 2015 14:22
Ideas for making 'yo-yo' easier to work with (https://github.com/james-henderson/yoyo)
(comment
;; Option 1 - the 'fn staircase' (current)
(defn make-system [latch]
(with-db-pool {...}
(fn [db-pool]
(let [web-config (read-config ...)]
(with-cljs-compiler {:config web-config
...}
(require '[com.stuartsierra.component :as c])
(c/start-system
(c/system-map
:a (-> {:d 4}
(c/using {:b :b}))
:b (-> {:c 4}
(c/using {:a :a}))))
@jarohen
jarohen / transpose-sexp-pairs.el
Last active August 29, 2015 14:16
In Clojure, I'd like to transpose *pairs* of s-exps (i.e. KVs in a map)
;; {:foo bar|
;; :baz quux}
;;
;; =>
;;
;; {:baz quux
;; :foo bar|}
;; This is my first attempt at ELisp of a 'bigger-than-hacking-around-in-init.el' size - please be kind!
;; At the same time, any feedback would be really valuable!
@jarohen
jarohen / phoenix-config.edn
Created December 13, 2014 23:04
Example phoenix config, dispatching on user
{:db {::component my-app.db/make-db-component
:host "host"
:port 5432
:schema "myapp_test"}
:webapp {::component my-app.web/make-webapp
:db ::dep
:port 3000}
:phoenix/environments {"prod"
@jarohen
jarohen / transducers.clj
Last active August 29, 2015 14:10
November 2014 Thoughtworks dojo - Transducers
;; We can write map and filter in terms of reduce
(defn my-map [f coll]
(reduce (fn [acc el]
(conj acc (f el)))
[]
coll))
(defn my-filter [pred coll]
(reduce (fn [acc el]