Skip to content

Instantly share code, notes, and snippets.

@dimovich
dimovich / deferred-ring.clj
Last active July 21, 2019 09:49
Handling Deferred responses for vanilla ring middleware
(require '[ring.middleware.session]
'[manifold.deferred :as d])
(defn wrap-ring-async-handler
"Converts given asynchronous Ring handler to Aleph-compliant handler."
[handler]
(fn [request]
(let [response (d/deferred)]
(ns ^:figwheel-hooks yourapp.core
(:require [reagent.core :as r]))
(defn title
[]
[:h1 "mooo"])
(defn app []
[title])
@dimovich
dimovich / deps.edn
Last active July 12, 2019 18:30
Compile SASS with deps.edn
{;; ...
:aliases
{
:figwheel
{
:extra-paths ["resources"]
:extra-deps {com.bhauman/figwheel-main {:mvn/version "0.2.0"}}
:main-opts ["-i sass.clj -m figwheel.main -b dev"]
}
@dimovich
dimovich / README.md
Last active March 8, 2019 12:05 — forked from mfikes/README.md
cljs.main rebel-readline

Start cljs.main with rebel-readline:

clojure -Sdeps '{:deps {github-mfikes/cljs-main-rebel-readline {:git/url "https://gist.github.com/dimovich/7bd42c51743e56b0929931b689bd7fc9" :sha "801a149bbf257eeda1bce2b77fc4fee10c6d632b"}}}' -i @setup.clj -m cljs.main
@dimovich
dimovich / datascript-set-intersection.clj
Last active January 11, 2019 17:46 — forked from pesterhazy/datomic-set-intersection.clj
DataScript set intersection query
;; A variation for DataScript
(defn make-intersection-q
"Generate an intersection q for searchable tags."
[n]
(assert (pos? n))
(into
[:find '[(pull ?e [*]) ...]
:in '$ (->> (range 1 (inc n)) (mapv #(symbol (str "?v" %))))
:where]
{:paths ["src/cljs" "src/cljc" "src/clj" "resources"]
:deps {org.clojure/clojure {:mvn/version "1.10.0-alpha5"}
org.clojure/clojurescript {:mvn/version "1.10.339"}
com.taoensso/timbre {:mvn/version "4.10.0"}
prismatic/dommy {:mvn/version "1.1.0"}
reagent {:mvn/version "0.8.1"}
thi.ng/geom {:mvn/version "1.0.0-RC3"}
thi.ng/math {:mvn/version "0.2.2"}
com.andrewmcveigh/cljs-time {:mvn/version "0.5.2"}}
@dimovich
dimovich / common.cljc
Created September 13, 2018 19:26
Use same component code for Reagent (client-side) and Hiccup (server-side)
(ns project.common
#?(:cljs (:require [project.util :refer [cc]])))
#?(:clj
(defmacro cc [args]
`(~@args)))
(defn child-component [& opts]
[:div "hello"])
;; can we make DS leave data unsorted?
(require '[datascript.core :as ds])
(def schema {:tags {:db/cardinality :db.cardinality/many}})
(def conn (ds/create-conn schema))
(ds/transact! conn [{:tags [33 1 12 1545 234]}])
(ds/pull @conn '[*] 1)
;; {:db/id 1, :tags [1 12 33 234 1545]}
(require '[thi.ng.color.core :as col]))
(defn cosine-coeficients
"amp = (R1-R2) / 2; dc offset = R1-amp; freq = -0.5"
([h1 h2]
(let [coerce #(col/as-rgba (col/hex->int %))
colors (->> [(coerce h1) (coerce h2)]
(map #(select-keys % [:r :g :b])))
[c1 _] colors
Unhandled java.lang.IllegalArgumentException
No implementation of method: :delta= of protocol:
#'thi.ng.math.core/IDeltaEquals found for class: clojure.lang.Ratio
core_deftype.clj: 583 clojure.core/-cache-protocol-fn
core_deftype.clj: 575 clojure.core/-cache-protocol-fn
core.cljc: 32 thi.ng.math.core$eval26713$fn__26714$G__26704__26727/invoke
core.cljc: 343 thi.ng.geom.viz.core$lin_tick_marks/invokeStatic
core.cljc: 341 thi.ng.geom.viz.core$lin_tick_marks/invoke
core.cljc: 352 thi.ng.geom.viz.core$linear_axis/invokeStatic