Skip to content

Instantly share code, notes, and snippets.

View candera's full-sized avatar

Craig Andera candera

View GitHub Profile
(let [opacity-ch (async/chan (async/dropping-buffer 1))]
(async/go-loop [last-set (:opacity @app-state)
last-received nil]
(let [t (async/timeout 100)
[ch val] (async/alts! [t opacity-ch])
[new-set new-received] (cond
(= ch opacity-ch)
[last-set val]
(require '[scad-clj.scad :refer :all]
'[scad-clj.model :refer :all])
(defn degrees [d]
(-> d (/ 180.0) (* Math/PI)))
(def x-axis [1 0 0])
(def y-axis [0 1 0])
(def z-axis [0 0 1])
@candera
candera / fanout.clj
Created November 19, 2013 21:15
core.async fan-out across n threads
(require '[clojure.core.async :as async])
(let [l (Object.)]
(defn log
[fmt & args]
(locking l
(apply printf fmt args)
(flush))))
(let [req (async/chan 10)
@candera
candera / lein-play
Last active December 19, 2015 16:29
Creates a simple Leiningen project in a throwaway directory, includes dependencies, and starts a REPL.
#!/bin/bash
# Example usage:
#
# lein-play '[org.craigandera/dynne "0.2.0"] [incanter/incanter-core "1.5.1"]'
LIBS=$*
PROJECT_DIR=/tmp/lein-play-`date +%Y%m%d%H%M%S`
mkdir $PROJECT_DIR
@candera
candera / graph.clj
Last active December 19, 2015 02:48
A Prismatic Graph for doing sound operations.
{:i1-channels (plumbing/fnk ^long [] 1)
:i1-duration (plumbing/fnk ^double [] 60.0)
:i1-amplitude (plumbing/fnk ^double [^double t] (Math/sin (p/* t 440 2.0 Math/PI)))
:i2-channels (plumbing/fnk ^long [] 1)
:i2-duration (plumbing/fnk ^double [] 60.0)
:i2-amplitude (plumbing/fnk [^double t] (let [x (-> t (p/* 440 2.0) long)]
(if (even? x) 1.0 -1.0)))
:m1-channels (plumbing/fnk ^long [^long i1-channels] i1-channels)
@candera
candera / symbolic_composition.clj
Created June 23, 2013 19:35
Sketch of symbolic composition of sound operations
(defn ->op
"Create an operation that just samples that sound
without additional processing."
[s]
(let [s* (gensym "sound")]
`{:bindings {~s* ~s}
:duration (.duration ~s*)
:channels (.channels ~s*)
:amplitude (.amplitude ~s* ~'t ~'c)}))
@candera
candera / Foobar.md
Last active December 14, 2015 07:19
Test gist

title!

Text

image

@candera
candera / setup-encryption.sh
Created February 5, 2013 13:33
Set up transparent encryption in git using openssl
#!/bin/bash
# Sets up transparent encryption of files in /config/private as per
# https://gist.github.com/873637. You will need to edit the password
# in ~/.gitencrypt/password to match everyone else's if you want to
# share this repo.
# Note: due to me being in a hurry, only files in /config/private/ and
# its subdirectories DOWN TO FOUR LEVELS are encrypted.
@candera
candera / interop.clj
Created October 12, 2012 21:13
Trying to call ApplicationServices via JNA
(def eventcount (atom 0))
(def i khordr.ApplicationServicesLibrary/INSTANCE)
(def eventTap (.CGEventTapCreate
i
khordr.ApplicationServicesLibrary$CGEventTapLocation/kCGSessionEventTap
khordr.ApplicationServicesLibrary$CGEventTapPlacement/kCGHeadInsertEventTap
0
khordr.ApplicationServicesLibrary$CGEventType/kCGEventKeyDown
(reify khordr.ApplicationServicesLibrary$CGEventTapCallback
(onevent [this _ _ event _] (swap! eventcount inc) nil))
@candera
candera / statemachine.clj
Created June 3, 2012 03:34
RESTful state machines
(defn update [state event-name]
;; current state id | event-name | action
;;
(match [(:status state) event-name]
[:waiting :prepare] #(assoc state :foo f3)
[:ready :delete] #(assoc state :bar 19)
[_ _] (throw (ex-info "Boom: roasted" {:reason :invalid-transition :event-name event-name}))
))