Skip to content

Instantly share code, notes, and snippets.

View daveray's full-sized avatar

Dave Ray daveray

View GitHub Profile
@daveray
daveray / clojurescript-one-flow.md
Created January 28, 2012 05:13
ClojureScript One Execution Flow

And now that I've written this, I see that Brenton already documented pretty much the same thing here. Way it goes. Figuring it out myself is better than reading about it anyway :)

ClojureScript One is pretty nice and very well-documented. Despite that, it still wasn't clear to me exactly how we got from a browser request to stuff on the screen. CS1 is built around an event bus model which makes it beautifully decoupled, but hides the execution flow. Add multimethods to the mix and it's definitely a little confusing for a newcomer.

So, tonight, as a newcomer, I worked through the control flow for the initial (development) request from the browser all the way until stuff is displayed on the screen and ready for input. I found it to be an extremely enlightening exercise. The results are below, hopefully someone will find it useful.

@daveray
daveray / seesaw-repl-help.clj
Created December 13, 2011 04:24
Seesaw REPL help
; very preliminary example of querying a widget for its properties, with examples
; in a repl.
user=> (use 'seesaw.core)
nil
user=> (use 'seesaw.dev)
nil
user=> (show-options (text))
javax.swing.JTextField
:action
:background [:aliceblue "#f00" "#FF0000" "(seesaw.color/color 255 0 0 0 224)"]
@daveray
daveray / show-events.clj
Created December 9, 2011 04:56
Get Seesaw event and property info in the REPL
user=> (show-options (label))
javax.swing.JLabel
Option Notes/Examples
-------------------------- --------------
:background :aliceblue
"#f00"
"#FF0000"
(seesaw.color/color 255 0 0 0 224)
:border 5
"Border Title"
@daveray
daveray / seesaw-repl-tutorial.clj
Created December 7, 2011 04:55
Seesaw REPL Tutorial
; A REPL-based, annotated Seesaw tutorial
; Please visit https://github.com/daveray/seesaw for more info
;
; This is a very basic intro to Seesaw, a Clojure UI toolkit. It covers
; Seesaw's basic features and philosophy, but only scratches the surface
; of what's available. It only assumes knowledge of Clojure. No Swing or
; Java experience is needed.
;
; This material was first presented in a talk at @CraftsmanGuild in
; Ann Arbor, MI.
@daveray
daveray / giant-steps.clj
Created November 24, 2011 04:52
First chorus of Giant Steps solo by Overtone
; Final pre-processed "transcriptions" of several Coltrane "Giant Steps" solos
; are here: https://github.com/daveray/yardbird
; Please take the data and do something fun with it!
; TODO
; Incorporate changes
; Convert to concert pitch
; Convert to correct octave
(use 'overtone.live)
@daveray
daveray / swingx.clj
Created November 16, 2011 02:58
Seesaw Swingx Sample
; Creates a list with row striping and rollover highlighting of rows.
(->
(frame
:title "Seesaw Swingx Highlighters"
:content (scrollable
(xlistbox
:highlighters [:simple-striping
((h-color :background :lightblue) :rollover-row)]
:model (range 0 99))))
@daveray
daveray / p117.clj
Created November 4, 2011 03:33
4clojure problem 117 issue
; http://www.4clojure.com/problem/117
(fn [g]
(let [w (count (first g))
h (count g)
xys (for [x (range w) y (range h)] [x y])
at (fn [[x y]] (if (and (< -1 x w) (< -1 y h)) (get-in g [y x]) \#))
c? (fn [[n0 n1]] (and (not= \# (at n0)) (not= \# (at n1))))
ns (fn [x y]
(for [[dx dy] [[-1 0] [1 0] [0 1] [0 -1]]]
[(+ x dx) (+ y dy)]))
@daveray
daveray / p86.clj
Created November 4, 2011 01:34
4clojure problem 86 issue
; http://www.4clojure.com/problem/86
(fn [n]
(letfn [(ds [n]
(if (pos? n)
(conj (ds (int (/ n 10))) (mod n 10))))]
(loop [n n ns #{}]
(cond
(ns n) false
(= 1 n) true
:e (recur (->> (ds n) (map #(* % %)) (reduce +)) (conj ns n))))))
@daveray
daveray / chess.rb
Created October 18, 2011 03:55
Joy of Clojure Chess Example in Familiar/JRuby
# Rough translation from Joy of Clojure refs example in Familiar
# https://github.com/daveray/familiar
# https://github.com/joyofclojure/book-source/blob/master/src/joy/refs.clj
$initial_board = [[:o, :k, :o],
[:o, :o, :o],
[:o, :K, :o]].to_clojure
# (defn board-map [f bd]
# (vec (map #(vec (for [s %] (f s))) bd)))
@daveray
daveray / jruby_equals.rb
Created October 17, 2011 23:39
jruby_equals
[511,0] familiar [master]$ jirb -r familiar -I lib
irb(main):001:0> x = [[1, 2, 3], {"hi" => "bye", :foo => [4, 5, 6]}].to_clojure
=> [[1 2 3] {"hi" "bye", :foo [4 5 6]}]
irb(main):002:0> y = [[1, 2, 3], {"hi" => "bye", :foo => [4, 5, 6]}].to_clojure
=> [[1 2 3] {"hi" "bye", :foo [4 5 6]}]
irb(main):003:0> x == y
=> nil
irb(main):004:0> x.equals y
=> true