Skip to content

Instantly share code, notes, and snippets.

@petterik
petterik / deps.edn
Last active June 8, 2018 07:41
Making eduction and sequence faster for chunked-seqs
{:paths ["."]
:deps {org.clojure/clojure {:mvn/version "1.10.0-alpha4"}
org.clojure/clojurescript {:mvn/version "1.10.238"}
org.clojure/test.check {:mvn/version "0.10.0-alpha2"}}}
@petterik
petterik / some-reduce.clj
Created January 4, 2018 23:23
Benchmark code of clojure.core/some implemented with reduce and reduced
(require '[criterium.core])
(require '[clojure.pprint])
(defn some
"Returns the first logical true value of (pred x) for any x in coll,
else nil. One common idiom is to use a set as pred, for example
this will return :fred if :fred is in the sequence, otherwise nil:
(some #{:fred} coll)"
{:added "1.0"
:static true}
#!/usr/bin/env bash -eux
# Original by Austin Birch in http://austinbirch.co.uk/clojurescript-react-native-bundling-release.html
# updated for metro-bundler 0.9.0
# prevent metro-bundler applying code folding to our cljs output
sed -i .bak \
's/(options.minify)/(options.minify \&\& !filename.match(\/release\\.ios\\.js\/))/' \
./node_modules/metro-bundler/src/JSTransformer/worker/index.js
@petterik
petterik / inf-compile-cljs.loader.cljs
Created July 3, 2017 19:05
jstack calls to clojurescript compiler's pid when compiling cljs.loader.cljs takes forever forever
Did:
- Built optimizations :advanced, clojurescript 1.9.683 with cljs.loader
Happened:
- Compilation ran forever. Last output being:
`Compiling resources/public/release/js/out/cljs/loader.cljs`
Debug:
- Ran 5 times:
`jstack 54630 >> cljs-loader-compile.stack`
@petterik
petterik / transform-reads-missing-reads.clj
Created May 17, 2017 19:45
om.next transform-reads issue
;; Issue with om/transform-reads
;; Issue is when having two siblings or cousins with the same read-key
;; in nested at level 2 or deeper, transform-reads will two paths
;; with the same root. Parsing such query will overwrite the first path
;; returning only the second one.
;; Example:
;; (om/transform-reads r [:foo])
;; returns: [#:join{:parent [#:join{:child1 [:foo]}]}
;; #:join{:parent [#:join{:child2 [:foo]}]}]
@petterik
petterik / om-ui-with-locals.clj
Last active May 4, 2017 14:11
om-ui with defs for specified locals
(defmacro with-defs
"Takes a seq of symbols which will be called with def for generated symbols.
These symbols will be replaced in the body with the generated symbols
Examples:
(let [a 1] (macroexpand '(with-defs [a] [a]))) ;; => (do (def a_60267 a) [a_60267])
(let [a 1] (with-defs [a] [a])) ;; => [1]"
[vars & body]
{:pre [(every? symbol? vars)]}
(let [syms (into {} (map (juxt identity #(gensym (str (name %) "_")))) vars)
(defn join [{:keys [parser query target] :as env} k _]
(let [ret (parser env query target)]
(if target
(when (seq ret)
{target (assoc ast :query ret)})
{:value ret})))
(require '[datascript.btset :as btset])
(require '[datascript.arrays :as da])
;; What?
;; Fast equality check for btset/Iter
;;
;; Why?
;; There's no history or (d/since ) API and I want to know what's changed between two databases.
;; With fast Iter equality checks, I can quickly check if an attribute has changed between
;; my two database values like so:
;; Here are 4 different versions of the sieve function with slight changes to test my theories
;; around seq, chunked-seq and transducer (reduce) api.
;; Try running these yourself with: (run-all)
(declare sieves)
(defn run-all []
(doseq [[k sieve] sieves]
(prn "Running:" k)
(dotimes [_ 5]
(time (sieve 10000)))))
diff --git a/src/main/om/next.cljc b/src/main/om/next.cljc
index ff19d99..3ea9682 100644
--- a/src/main/om/next.cljc
+++ b/src/main/om/next.cljc
@@ -2517,10 +2517,10 @@
root (:root @state)]
#?(:cljs
(doseq [c ((:optimize config) cs)]
- (let [props-change? (> (p/basis-t this) (t c))]
+ (let [props-change? (and (iquery? c) (> (p/basis-t this) (t c)))]