Skip to content

Instantly share code, notes, and snippets.

View mhuebert's full-sized avatar

Matt Huebert mhuebert

View GitHub Profile
S1
tap -> S3
S1default
click -> S1a
tap -> S1b
S1a
go -> S2
back -> S1
S1b
go -> S3
(require '[maria.eval :as e]
'[goog.object :as gobj]
'[clojure.string :as string])
(defn resolve-to-val [sym]
(let [{the-name :name} (e/resolve-var sym)]
(->> (string/split (str the-name) #"[\./]")
(map munge)
(to-array)
(apply gobj/getValueByKeys js/window))))
(defn lorenz-points [p sigma beta dt]
(loop [n 6000
x 0.01
y 0
z 0
out []]
(if (= 0 n)
out
(recur (dec n)
(+ x (* p (- y x) dt))
@mhuebert
mhuebert / localstorage.cljs
Last active July 11, 2017 14:24 — forked from daveliepmann/localstorage.cljs
HTML5 localStorage utility functions for ClojureScript. I find it makes for cleaner code when I wrap the native JS.
(ns localstorage)
#_[]
[1
2
3
4]
@mhuebert
mhuebert / pyrgiometry.clj
Created July 10, 2017 21:57 — forked from daveliepmann/pyrgiometry.clj
"Πυργεωμετρία ('Pyrgi-ometry')", a Processing sketch using Clojure and Quil. Inspired by artwork in the village of Pyrgi on the Greek island Chios: https://daveliepmann.exposure.so/pyrgi
;; "Πυργεωμετρία ('Pyrgi-ometry')", a Processing sketch using Clojure and Quil
(ns livecode.pyrgi
(:use quil.core))
(def stripe-height 50)
(def canvas-height (* 9 stripe-height))
(def canvas-width (* canvas-height (/ 3 2)))
;; Color conversion, courtesy of Jack Rusher
(defn hex-to-color [hex]
@mhuebert
mhuebert / as-vec.clj
Last active April 28, 2017 14:26
Return vectors from a Clojure spec regular expression generator
(ns spec-test.as-vec
(:require [clojure.spec :as s :include-macros true]
[cljs.spec.impl.gen :as gen]
[clojure.test.check.generators]))
(defn as-vec
"Wrap the generator of expr to return a vector"
[expr]
(s/with-gen expr #(gen/bind (s/gen expr)
(comp gen/return vec))))
@mhuebert
mhuebert / x.clj
Last active November 9, 2016 14:29
Macros that require macros, in ClojureScript. Remember, in your .clj file: use `:require` with `:include-macros true`
(ns app.x
(:require [app.y :refer [y-macro] :include-macros true]))
(defmacro x-macro [& args]
(y-macro args))
;; how can we use macros from one .clj namespace in another .clj namespace?
;; take a close look at the :require statement above. Two important points:
;; - it must say :require, not :require-macros
@mhuebert
mhuebert / flat_map.cljs
Created March 7, 2016 18:47
Flat-Map, for multi-path atomic updates in Firebase
(defn flat-map
([m] (clj->js (apply hash-map (flat-map "" m))))
([path m]
(mapcat (fn [[k v]] (if (map? v)
((partial flat-map (str path "/" (name k))) v)
[(str path "/" (name k)) v])) m)))
(= (flat-map {:users {"x0x0x0" {:name "Matt"
:email "me@matt.is"}}})
{"users/x0x0x0/name" "Matt"
@mhuebert
mhuebert / defroutes.clj
Last active March 3, 2016 16:40
defroutes macro for ClojureScript/Secretary - quickly define many routes at once
(defmacro defroutes [& routes]
`(do
~@(map (fn [[[path] body]]
(let [has-args? (or (vector? (first body)) (map? (first body)))
body (if has-args? body (cons [] body))]
`(~'secretary.core/defroute ~path ~@body)))
(partition 2 (partition-by string? routes)))))
@mhuebert
mhuebert / cljs_core_cache.cljs
Last active February 24, 2016 16:57
CLJS core analysis cache for use with self-hosted compiler
(ns app.cljs-core-cache
(:require
[cognitect.transit :as transit]
[cljs.js :as cljs]))
(defn print-core []
(let [writer (transit/writer :json)
cache (cljs.js/dump-core)]
(.log js/console (transit/write writer cache))))