Skip to content

Instantly share code, notes, and snippets.

Jonathan Boston bostonou

Block or report user

Report or block bostonou

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@bostonou
bostonou / real-world-core-async.cljs
Created Jan 11, 2019
clojurescriptmadeeasy.com/blog/real-world-core-async.html
View real-world-core-async.cljs
(ns cljsmadeeasy.core
(:require [cljs.core.async :as a])
(:require-macros [cljs.core.async.macros :refer [go]]))
(defn fill-load-chan [number-of-pages]
(let [partitions (partition-all NUM-PAGES-PER-LOAD
(range 1 (inc number-of-pages)))
c (a/chan)]
(go
(doseq [page-numbers partitions]
View example-data.clj
;;examples with no valid matter look up or datomic
(add-matter-review-dbs
nil nil
'[({:a :b} {:review-id "123"
:matter-id "456"
:data "some-data"})
({:c :d} {:review-id "abc"})])
;;=>
[({:a :b}
@bostonou
bostonou / promise.cljs
Created Jul 14, 2015
Promise.all with core.async
View promise.cljs
(ns cljs-made-easy.core
(:refer-clojure :exclude [into])
(:require-macros [cljs.core.async.macros :refer [go go-loop]])
(:require [cljs.core.async :refer [<! >!] :as a]))
(enable-console-print!)
(defn resolving-promise [key t reject]
(go
(pr (str key " starting"))
@bostonou
bostonou / promise-all.cljs
Last active Aug 29, 2015
Promise.all with core.async
View promise-all.cljs
(ns cljs-made-easy.core
(:require-macros [cljs.core.async.macros :refer [go go-loop]])
(:require [cljs.core.async :refer [<! >!] :as a]))
(enable-console-print!)
(defn good-go-block [k t ctrl]
(go
(<! (a/timeout t))
(str k " waited " t "ms")))
@bostonou
bostonou / line-seq.cljs
Last active Oct 21, 2018
line-seq in cljs
View line-seq.cljs
;; This is a macro, and must be in clojure. It's name and location is the same as
;; the cljs file, except with a .clj extension.
(ns cljs-made-easy.line-seq
(:refer-clojure :exclude [with-open]))
(defmacro with-open [bindings & body]
(assert (= 2 (count bindings)) "Incorrect with-open bindings")
`(let ~bindings
(try
(do ~@body)
@bostonou
bostonou / cljs-line-reader.cljs
Last active Aug 29, 2015
Line by line reader in cljs
View cljs-line-reader.cljs
(ns cljs-line-reader.core
(:refer-clojure :exclude [flush])
(:require clojure.string
[cljs.core.async :refer [>!]])
(:require-macros [cljs.core.async.macros :refer [go]]))
(def fs (js/require "fs"))
(def stream (js/require "stream"))
(def ^:const eol (.-EOL (js/require "os"))) ;;eg "\n" or "\r\n"
View lazy-cat-fib-1.clj
(take 1 head-fibo)
(take 1 (lazy-cat [0N 1N] (map + head-fibo (rest head-fibo))))
(take 1 (concat (lazy-seq [0N 1N])
(lazy-seq (map + head-fibo (rest head-fibo)))))
View lazy-cat-fib.clj
;;So let’s work out the first couple of simple cases:
(take 1 head-fibo)
(take 1 (lazy-cat [0N 1N] (map + head-fibo (rest head-fibo))))
(take 1 (concat (lazy-seq [0N 1N])
(lazy-seq (map + head-fibo (rest head-fibo)))))
;;since we’re taking 1, the 0N of the first lazy-seq suffices and
;;we don’t need to further evaluate
;; => (0N)
View mutate-chan.clj
(defn mutate-chan
[c]
(<!! c))
(let [c (chan)]
(thread (>!! c 1))
(mutate-chan c)
(<!! c)) ; the 1 is now gone!
View delayed-args.clj
(defn =?
[a b]
(= a b))
(defn channel=?
[a c]
(thread (=? a (<!! c))))
(def partial=? (partial =? 10))
You can’t perform that action at this time.