Skip to content

Instantly share code, notes, and snippets.

(defn print-it [it]
(println it))
;;; the test needs to be in the form (expect expected actual),
;;; and the line we're testing is (println it)
;;; so you could envision a test similar to the one below
(expect (println 5)
(print-it 5))
(defn print-it [it]
(println it))
;;; the test needs to be in the form (expect expected actual),
;;; and the line we're testing is (println it)
;;; so you could envision a test similar to the one below
(expect (interaction (println 5))
(print-it 5))
(expect (interaction (spit #"/tmp/" "some data" :append true))
(do
(spit "/tmp/somewhere-else" "nil")
(spit "/tmp/hello-world" "some data" :append true)))
(expect (interaction (spit #"/tmp/" String :append true))
(do
(spit "/tmp/somewhere-else" "nil")
(spit "/tmp/hello-world" "some data" :append true)))
(defn true-or-nil? [x]
(or (true? x) (nil? x)))
;; this test passes
(expect (interaction (spit #"/tmp/" String :append true-or-nil?))
(do
(spit "/tmp/somewhere-else" "nil")
(spit "/tmp/hello-world" "some data" :append true)))
;; so does this test
(expect (interaction (spit String #"some da" keyword? (contains-kvs :a :b :c :d)))
(spit "/tmp/hello-world" "some data" :append {:a :b :c :d :e :f}))
Programming career distilled.
- holy shit programming in language X isn't that hard.
- okay, I have a hammer, everything is a nail.
- holy shit there are other tools that make working even faster.
- I can solve this problem using 3 different tools I know well.
- I'm bored by learning other tools, I solve everything using my favorite tool.
- become a manager.
;; a simple server that's generating a new int that's < 100, every millisecond
(ns synchro.core
(:import [org.jetlang.fibers ThreadFiber]))
(defonce server-list (atom []))
(defonce appender (atom nil))
(defonce fiber (doto (ThreadFiber.) .start))
;; server
(defonce server-list (atom []))
(defonce appender (atom nil))
(defonce appending-fiber (atom nil))
(defonce subscriber (atom identity))
(defn subscribe [f]
(reset! subscriber f))
;; client
(defonce client-list (atom nil))
(defn handle-update [{:keys [type val]}]
(if (= type :snapshot)
(reset! client-list val)
(when @client-list
(when (< 9 (count @client-list))
(swap! client-list butlast))
(swap! client-list conj val))))