Skip to content

Instantly share code, notes, and snippets.

View daveray's full-sized avatar

Dave Ray daveray

View GitHub Profile
@mecdemort
mecdemort / Clojure JTree.clj
Created March 27, 2010 03:45
JTree from a clojure collection
; Turn a map into a JTree
; keys can be any object using toString to display
; listener is called as (listener seq-of-keys-to-selected-node)
;root
; |-child-1
; | |-Child-1-1
; | |-child-1-2
; |-child-2
; |-child-3
@ordnungswidrig
ordnungswidrig / reify_generic.clj
Created June 8, 2011 14:06
Reify a protocol by giving a generic implementation function that will be called for all protocol methods. Like a proxy.
(ns reify-generic
"reify a protocol such that every method is delegated to a specified method")
(defmacro reify-generic
"Reify the given protocols. Every method of any protocol is implemented such
that f is called as (apply f protocol-method args)
Example:
(defprotocol Calculator
;; chouser's solution to Read Roman numerals
;; https://4clojure.com/problem/92
(fn [r]
(->>
(reverse r)
(map {\M 1000 \D 500 \C 100 \L 50 \X 10 \V 5 \I 1})
(cons 0)
(partition 2 1)
(reduce
@daveray
daveray / seesaw-keybinding.md
Created October 4, 2011 03:31
Seesaw Keybinding Design Notes

Thoughts:

  • Should make specifying keybindings externally easy, through resources.
  • Should be easy like (listen)
  • Should be consistent with rest of event system.

A function to set up one key binding

Arguments:

@kawabata
kawabata / tarai.clj
Created November 16, 2011 21:33
tarai mawashi in overtone
(ns tarai.core
(:use [overtone.live]))
;; basic.clj より
(defsynth foo [freq 200 dur 0.5]
(let [src (saw [freq (* freq 1.01) (* 0.99 freq)])
low (sin-osc (/ freq 2))
filt (lpf src (line:kr (* 10 freq) freq 10))
env (env-gen (perc 0.1 dur) :action FREE)]
(out 0 (pan2 (* 0.1 low env filt)))))
@gavq
gavq / midi
Created March 10, 2012 08:15
Clojure for General MIDI
;;
;; General MIDI defines instruments for 128 program numbers
;; http://www.midi.org/techspecs/gm1sound.php
;;
;; javax.sound.midi numbers the instruments from 0 rather than 1, so acoustic-grand-piano is 0.
;;
(def GM
{:acoustic-grand-piano 0
:bright-acoustic-piano 1
@alandipert
alandipert / macrofn.clj
Created March 15, 2012 19:44
invoke a macro like a function
; Invoke a macro like a function - if you dare.
; ______
; .-" "-.
; / \
; _ | | _
; ( \ |, .-. .-. ,| / )
; > "=._ | )(__/ \__)( | _.=" <
; (_/"=._"=._ |/ /\ \| _.="_.="\_)
; "=._ (_ ^^ _)"_.="
; "=\__|IIIIII|__/="
@Johnicholas
Johnicholas / shift-reset.soar
Created April 7, 2012 19:08
Delimited Continuations in Lambda Calculus in Soar
# This is a lambda-calculus interpreter with shift and reset,
# an implementation of BRICS-RS-3-41 "An Operational Foundation for Delimited Continuations",
# by Biernacka, Biernacki, and Danvy.
#
# Mistakes, misunderstandings and terrible un-idiomatic Soar style by Johnicholas
#
#
# This is the grammar:
#
# A term can have a single outgoing ^reset leading to a reset.
@hiredman
hiredman / scratch.clj
Created August 9, 2012 20:01
pomegranate-injector.clj
(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})
(.setContextClassLoader (Thread/currentThread) cl)
(try
(require '[cemerick.pomegranate :as pom])
(finally
@Chouser
Chouser / gist:3687532
Created September 9, 2012 21:52
Lazy seq as event subscription mechanism
;; Here is a spike of a lightweight in-process pubsub mechanism that allows pure ;; functional consumers, both blocking and asynchronous.
;; This defines the event stream, in this case just a series of numbers,
;; a new one produced each second
(defn timer []
(lazy-seq
(do
(Thread/sleep 1000)
(cons (System/nanoTime) (timer)))))