Skip to content

Instantly share code, notes, and snippets.

View daveray's full-sized avatar

Dave Ray daveray

View GitHub Profile
@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 / eclipse-shortcuts.txt
Created October 7, 2011 03:41
daily eclipse shortcuts
These are very Java-centric, but honestly, if you're not doing Java why would you want to use Eclipse? :)
Replace `ctrl` with `cmd` as needed. The translation to Mac is a little arbitrary.
* ctrl-. (period): Jump to next warning or error
* ctrl-1: Show quick-fix menu (great in conjunction with ctrl-.)
* ctrl-3: "smart" navigation. Type name of something (file, view, perspective, etc) to go to it.
* ctrl-D: delete current line
* ctrl-e: switch editor. Also try ctrl-F6
* ctrl-F7: switch between views
@daveray
daveray / JSplitPainInTheAss.java
Created June 12, 2011 21:05
Workaround JSplitPane.setDividerLocation without resorting to sub-classing and other abominations.
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.HierarchyEvent;
import java.awt.event.HierarchyListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JSplitPane;
@daveray
daveray / merge.clj
Created January 30, 2014 05:42
merge a channel of channels in core.async
(defn merge+
"Takes a *channel* of source channels and returns a channel which
contains all values taken from them. The returned channel will be
unbuffered by default, or a buf-or-n can be supplied. The channel
will close after all the source channels have closed."
([in-ch] (merge+ in-ch nil))
([in-ch buf-or-n]
(let [out-ch (async/chan buf-or-n)]
(async/go-loop [cs [in-ch]]
(if-not (empty? cs)
@daveray
daveray / mr-jr.clj
Created January 28, 2014 04:48
Map-Reduce Jr. via core.async
(ns mr-jr
(:refer-clojure :exclude [shuffle])
(:require [clojure.string :as string]
[clojure.core.async :as async]))
(defn async-group-by
"Kinda like clojure.core/group-by, but takes a channel and returns a channel"
[f g ch]
(->> ch
(async/reduce
@daveray
daveray / async-transient.clj
Last active January 4, 2016 10:59
transient + core.async
; Is there a way to tell assoc! "No really, I know what I'm doing."
; Do I know what I'm doing?
(->> (async/to-chan [[:a 1] [:b 2] [:c 3]])
(async/reduce (fn [acc [k v]]
(assoc! acc k v))
(transient {}))
(async/map< persistent!)
(async/<!!))
;=>
; Exception in thread "async-dispatch-52" java.lang.IllegalAccessError: Transient used by non-owner thread
@daveray
daveray / radio-binding.clj
Created January 22, 2014 07:08
Seesaw radio button binding example
(use 'seesaw.core)
(require '[seesaw.bind :as b])
(def f (let [bg (button-group)
f (-> (frame :title "test"
:content (border-panel :center (text :id :text :text "hi")
:south (horizontal-panel :items
[(radio :group bg :text "enabled")
(radio :group bg :text "disabled")])))
pack!
@daveray
daveray / shaped-window-demo.clj
Created December 30, 2013 14:20
ShapedWindowDemo.java
; http://docs.oracle.com/javase/tutorial/displayCode.html?code=http://docs.oracle.com/javase/tutorial/uiswing/examples/misc/ShapedWindowDemoProject/src/misc/ShapedWindowDemo.java
(use 'seesaw.core)
(require '[seesaw.graphics :as g])
(-> (doto (frame :undecorated? true
:content (border-panel :center (button :text "I am a button"))
:listen [:component-resized
(fn [e]
(.setShape (to-root e)
(g/ellipse (0 0 (width e) (height e)))))])
@daveray
daveray / scala-rx
Created November 5, 2013 07:46
Follow the Scala setup instruction for Coursera reactive course
[info] Compiling 3 Scala sources to /Users/dray/mine/coursera-rx/quickcheck/target/scala-2.10/classes...
[info] 'compiler-interface' not yet compiled for Scala 2.10.2. Compiling...
sbt appears to be exiting abnormally.
The log file for this session is at /var/folders/12/bkvfkd5j0fxbd0k1q71tqqnc49fbdt/T/sbt4624986011374152709.log
java.lang.OutOfMemoryError: PermGen space
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)