Skip to content

Instantly share code, notes, and snippets.

View pbaille's full-sized avatar
🏠
Working from home

Pierre Baille pbaille

🏠
Working from home
  • Freelance
  • France
View GitHub Profile
@pbaille
pbaille / rate-limitor.clj
Last active December 27, 2016 15:55
rate limitor sketch
(def state (volatile! {}))
(def c (chan))
(defn add-bucket! [id {:as opts
:keys [ttl len]
:or {ttl 1000 len 10}}]
(vswap! state
assoc
id
{:ttl ttl
(ns type.exp
(:refer-clojure :exclude [extend-type reify])
;; state ---------------------
(def types (atom {::any identity}))
(def facets (atom {}))
;; helpers -------------------
(ns rum-slave
(:require-macros [cljs.core.async.macros :refer [go-loop go]])
(:require [cljs.core.async :as async :refer [chan >! <!]]
[rum.core :as rum]))
;; helpers ---------------------------------------------------------------
(defn notify [s m]
((:notify s) m))
@pbaille
pbaille / rwrap.clj
Last active December 6, 2016 19:03
reactive wrapper
(defn rwrap [build deps-map]
(let [this (atom (build))
deps (keys deps-map)
propagating (atom nil)]
(add-watch this
:build
(fn [_ _ _ n]
(when-not @propagating
(reset! propagating true)
(doseq [[dep upd] deps-map]
(ns grayscott.core
"ported from toxiclibs by Karsten Schmidt
https://bitbucket.org/postspectacular/toxiclibs/src/44d9932dbc9f9c69a170643e2d459f449562b750/src.sim/toxi/sim/grayscott/GrayScott.java?at=default&fileviewer=file-view-default"
#?(:clj (:require [thi.ng.math.macros :as mm])
:cljs (:require-macros [thi.ng.math.macros :as mm])))
(defn clip [min max n]
(cond
(< n min) min
(> n max) max
@pbaille
pbaille / midi-parser.clj
Last active April 10, 2020 09:09
midi-parser in Clojure
(ns midi-parser.core
(:use clojure.java.data)
#_(:use utils.utils)
#_(:use vendors.debug-repl)
(:import (java.io File)
#_(java.util Arrays)
#_(java.nio ByteBuffer)
(javax.sound.midi MidiSystem Sequence MidiMessage MidiEvent ShortMessage MetaMessage Track)))
;***************** Utils ********************