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
@briandealwis
briandealwis / gist:782862
Created January 17, 2011 13:55 — forked from spullara/gist:782523
One-liner to turn jar with Main-Class into executable shell script
# turn a jar with a Main-Class into a stand alone executable
(echo '#!/usr/bin/env java -jar'; cat blahblah.jar) > blah
# turn a jar with a particular main clas into a stand alone executable
(echo '#!/usr/bin/env java -jar package.MainClass'; cat blahblah.jar) > blah
@weavejester
weavejester / gist:1001206
Created May 31, 2011 20:27
Clojure on Heroku
~/$ lein new ring-on-heroku
Created new project in: /home/jim/Development/ring-on-heroku
~/$ cd ring-on-heroku
~/ring-on-heroku$ echo 'web: lein run -m ring-on-heroku.core' > Procfile
~/ring-on-heroku$ cat > src/ring_on_heroku/core.clj
(ns ring-on-heroku.core
(:use ring.util.response
ring.adapter.jetty))
(defn app [req]
@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
@ordnungswidrig
ordnungswidrig / state-is-a-fold.clj
Created June 16, 2011 15:50
State is a fold over events
(ns state-is-a-fold
(:use clojure.test))
;;; After all, state is a fold of events. For example let's say the events are a sequence of numbers
;;; and we are folding by addition:
(deftest simple
(let [events [1 5 2 4 3]
state (reduce + events)]
(is (= 15 state))))
@Folcon
Folcon / clipboard-utils.clj
Created August 24, 2011 11:50
Just a quick clipboard slip/slurp I put together because I didn't find anything similar, don't know if it's useful for anyone but found it invaluable when getting large strings being returned from the repl and sticking the result in an editor for more car
(defn get-clipboard []
(.getSystemClipboard (java.awt.Toolkit/getDefaultToolkit)))
(defn slurp-clipboard []
(try
(.getTransferData (.getContents (get-clipboard) nil) (java.awt.datatransfer.DataFlavor/stringFlavor))
(catch java.lang.NullPointerException e nil)))
(defn spit-clipboard [text]
(.setContents (get-clipboard) (java.awt.datatransfer.StringSelection. text) nil))
@andrewsardone
andrewsardone / screen-crash-course.md
Created August 26, 2011 13:10
GNU Screen Crash Course

GNU Screen Crash Course

Introduction

A real quick GNU screen crash course with the key features I use.

man screen

  • Emulates terminals in a full-screen window manager
  • Detachable, so shell sessions aren't attached to a login process
;; 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)))))