Skip to content

Instantly share code, notes, and snippets.

View stoeckley's full-sized avatar

andrew stoeckley

  • Balcony Studio
  • Netherlands
View GitHub Profile
@stoeckley
stoeckley / waves.pde
Created April 4, 2018 20:29 — forked from beesandbombs/waves.pde
waves
int[][] result;
float t, c;
float ease(float p) {
return 3*p*p - 2*p*p*p;
}
float ease(float p, float g) {
if (p < 0.5)
return 0.5 * pow(2*p, g);
@stoeckley
stoeckley / missing_keys_specs.clj
Created October 14, 2017 12:37 — forked from stuarthalloway/missing_keys_specs.clj
I think it would be a mistake to introduce temporal coupling to prevent typos.
;; I think it would be a mistake to introduce temporal coupling to prevent typos.
;; The example program below lets you identify "missing" keys specs at
;; the time and place of your choosing, and then handle them as you
;; deem appropriate, without imposing those decisions on other
;; users of spec.
(require '[clojure.spec.alpha :as s]
'[clojure.set :as set])
@stoeckley
stoeckley / missing_keys_specs.clj
Created October 14, 2017 12:37 — forked from stuarthalloway/missing_keys_specs.clj
I think it would be a mistake to introduce temporal coupling to prevent typos.
;; I think it would be a mistake to introduce temporal coupling to prevent typos.
;; The example program below lets you identify "missing" keys specs at
;; the time and place of your choosing, and then handle them as you
;; deem appropriate, without imposing those decisions on other
;; users of spec.
(require '[clojure.spec.alpha :as s]
'[clojure.set :as set])
;; try this form-by-form at a REPL
(require '[clojure.spec.alpha :as s])
;; create an inline DSL to describe the FizzBuzz world
(defmacro divides-by
[nm n]
`(s/def ~nm (s/and pos-int? #(zero? (mod % ~n)))))
;; specify FizzBuzz
(divides-by ::fizz 3)
@stoeckley
stoeckley / vector drag
Created July 30, 2017 17:37
Drag index through a vector
(defn slide
"Returns the final vector after dragging an indexed item to another index, which means it swaps incrementally with each index it passes through. v should be a vector but if it isn't it will be converted to one."
[v o n]
(let [v (vec v) ;; ensures v is a vector
item (v o)
removed (if (= o (count v))
(pop v)
`[~@(concat
(subvec v 0 o)
(subvec v (inc o)))])]
@stoeckley
stoeckley / bench.clj
Created July 30, 2017 17:37 — forked from hiredman/bench.clj
core.logic for joinery
#!/usr/bin/java -jar clojure-1.7.0-master-SNAPSHOT.jar
(let [pom-uber-jar
(str "http://thelibraryofcongress.s3.amazonaws.com/"
"pomegranate-0.0.13-SNAPSHOT-jar-with-dependencies.jar")
cl (java.net.URLClassLoader. (into-array [(java.net.URL. pom-uber-jar)]))
cx (.getContextClassLoader (Thread/currentThread))]
(push-thread-bindings {clojure.lang.Compiler/LOADER cl})
@stoeckley
stoeckley / fold-right.clj
Created July 30, 2017 17:37 — forked from kohyama/fold-right.clj
fold-right and reduce-right in Clojure
(use 'clojure.test)
(defn fold-right [f z coll]
(loop [[c & cs] coll rvsd '()]
(if (nil? c)
(loop [acc z [r & rs] rvsd]
(if r (recur (f r acc) rs) acc))
(recur cs (cons c rvsd)))))
(defn reduce-right [f coll]
;; based on core.logic 0.8-alpha2 or core.logic master branch
(ns sudoku
(:refer-clojure :exclude [==])
(:use clojure.core.logic))
(defn get-square [rows x y]
(for [x (range x (+ x 3))
y (range y (+ y 3))]
(get-in rows [x y])))
@stoeckley
stoeckley / drain
Created July 30, 2017 17:34
drain a core.async chan
(defn drain
"Takes all values available on a chan then returns the number taken to the channel drain creates. Compatible with cljs too."
[c]
(go
(loop [r 0]
(alt!
(timeout 100) r
c ([v] (recur (inc r)))))))
(defn drainf
@stoeckley
stoeckley / destructuring.md
Created July 10, 2017 15:16 — forked from yang-wei/destructuring.md
Elm Destructuring (or Pattern Matching) cheatsheet

Should be work with 0.18

Destructuring(or pattern matching) is a way used to extract data from a data structure(tuple, list, record) that mirros the construction. Compare to other languages, Elm support much less destructuring but let's see what it got !

Tuple

myTuple = ("A", "B", "C")
myNestedTuple = ("A", "B", "C", ("X", "Y", "Z"))