Skip to content

Instantly share code, notes, and snippets.

;; 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))
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.
(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}))
(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 #"/tmp/" String :append true))
(do
(spit "/tmp/somewhere-else" "nil")
(spit "/tmp/hello-world" "some data" :append true)))
(expect (interaction (spit #"/tmp/" "some data" :append true))
(do
(spit "/tmp/somewhere-else" "nil")
(spit "/tmp/hello-world" "some data" :append true)))
(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))
(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))
(given [x do-work] (expect x (let [i (atom 0)]
do-work))
0 @i
1 (do (swap! i inc)
@i)
2 (do (swap! i inc)
(swap! i inc)
@i))
(given [x] x
(expect 0 (let [i (atom 0)]
@i))
(expect 1 (let [i (atom 0)]
(swap! i inc)
@i))
(expect 2 (let [i (atom 0)]
(swap! i inc)