Skip to content

Instantly share code, notes, and snippets.

@cemerick
cemerick / gist:9207672
Created February 25, 2014 12:07
go-loop fail
; Clojure 1.6.0-alpha3, CLJS HEAD, [org.clojure/core.async "0.1.267.0-0d7780-alpha"]
; works
(go (loop [change (<! dom-change-chan)]
(when change
(js/console.log change)
(recur (<! dom-change-chan)))))
; doesn't work
(go-loop [change (<! dom-change-chan)]
$ lein repl
Compiling com.clojurebook.CustomException
Compiling com.clojurebook.imaging
nREPL server started on port 59292 on host 127.0.0.1
REPL-y 0.2.1
Clojure 1.3.0
Docs: (doc function-name-here)
(find-doc "part-of-name-here")
Source: (source function-name-here)
Javadoc: (javadoc java-object-or-class-here)
cemerick.pprng> (defn x [] 5)
#<Var@15e1180b:
#<pprng$eval8963$x__8964 cemerick.pprng$eval8963$x__8964@4dabde1e>>
cemerick.pprng> (tc/ann x (Fn [-> tc/AnyInteger]))
nil
cemerick.pprng> (tc/cf (x))
Type Error (/tmp/form-init6942836557449375495.clj:1:16) Unannotated var cemerick.pprng/x
Hint: Add the annotation for cemerick.pprng/x via check-ns or cf
in: x
(tc/defprotocol IRandom
(-seed [this] :- tc/AnyInteger)
(-next-double [this] :- Double)
(-next-float [this] :- Float)
(-next-int
[this] :- Integer
[this limit :- Integer] :- Integer)
(-next-long [this] :- Long)
(-next-boolean [this] :- Boolean))
@cemerick
cemerick / classpath.clj
Last active August 29, 2015 14:02
Clojure Atlas ontology + JSON "asset" generation
; This Source Code Form is subject to the terms of the Mozilla Public License,
; v. 2.0. If a copy of the MPL was not distributed with this file, You can
; obtain one at http://mozilla.org/MPL/2.0/.
(ns cemerick.atlas.classpath
(:import (java.net URI) java.io.File))
(defn- find-clojure-jar
"Returns a file referring to the clojure jar on the classpath."
[]
(def-repl-test ensure-no-*msg*-capture
(let [ids (set (map :id (repl-eval session "(println :foo)")))
ids2 (set (map :id (repl-eval session "(println :bar)")))]
(println ids)
(println ids2)
(is (empty? (clojure.set/intersection ids ids2)))))
clojure.test.check.generators> (sample bytes)
(#<[object Uint8Array]> #<[object Uint8Array]> #<[object Uint8Array]> #<[object Uint8Array]> #<[object Uint8Array]> #<[object Uint8Array]> #<[object Uint8Array]> #<[object Uint8Array]> #<[object Uint8Array]> #<[object Uint8Array]>)
clojure.test.check.generators> (lang/map #(.-length %) *1)
(0 0 2 3 2 4 5 7 1 8)
(define-pass optimize-direct-call L0 [x] L0
[]
{Expr
[[((fn [x*] e*) e1*)
(== (count x*) (count e1*))
`(let [~@(interleave x* e1*)] ~@e*)]]}
(Expr x))
lang> (optimize-direct-call '((fn [a b] _) 1 2))
(clojure.core/let [a 1 b 2] _)
@cemerick
cemerick / gist:6cc2a276f34177ebf52b
Created March 9, 2015 17:46
quartz scheduling job name / key leak
; CIDER 0.6.0alpha (package: 0.5.0) (Clojure 1.6.0, nREPL 0.2.3)
=> (schedule #(println "foo"))
=> (schedule #(println "foo"))
=> (schedule #(println "foo"))
...
=> (def s (immutant.scheduling.internal/scheduler {}))
#<Var@5f67764a:
#<QuartzScheduling org.projectodd.wunderboss.scheduling.QuartzScheduling@450109d4>>
; scheduled job names (and thus their JobKeys) are retained, even if they're not repeating
@cemerick
cemerick / gist:0556998b37ec4ab07c1d
Created March 17, 2015 09:41
newly-refactored ClojureScript (0.0-3058+) REPLs work well over nREPL in a terminal environment
$ lein repl
nREPL server started on port 50811 on host 127.0.0.1 - nrepl://127.0.0.1:50811
REPL-y 0.3.2, nREPL 0.2.3
Clojure 1.6.0
Java HotSpot(TM) 64-Bit Server VM 1.8.0_40-b25
Docs: (doc function-name-here)
(find-doc "part-of-name-here")
Source: (source function-name-here)
Javadoc: (javadoc java-object-or-class-here)
Exit: Control+D or (exit) or (quit)