Skip to content

Instantly share code, notes, and snippets.

View daveray's full-sized avatar

Dave Ray daveray

View GitHub Profile
@daveray
daveray / gist:1124352
Created August 4, 2011 02:05
proxy-super on protected method
user=> (proxy [javax.swing.JPanel] []
(paintComponent [^java.awt.Graphics g]
(let [^javax.swing.JPanel this this]
(proxy-super paintComponent g))
(.fillRect g 100 100 10 10)))
Reflection warning, NO_SOURCE_PATH:27 - call to paintComponent can't be resolved.
#<JPanel$0 user.proxy$javax.swing.JPanel$0[,0,0,0x0,invalid,layout=java.awt.FlowLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=9,maximumSize=,minimumSize=,preferredSize=]>
@daveray
daveray / gist:1138754
Created August 11, 2011 01:59
Seesaw File Chooser
(use 'seesaw.core)
(use 'seesaw.chooser)
(def open-action
(action :name "Open" :key "menu O"
:handler
(fn [e]
(if-let [f (choose-file)]
(text! (select (to-root e) [:#my-text]) f)))))
@daveray
daveray / er.clj
Created August 13, 2011 03:32
Dorothy ER example
; http://www.graphviz.org/content/ER
(ns dorothy.examples.er
(:use dorothy.core))
(defn -main []
(->
(graph :ER [
{:rankdir :LR}
[:node {:shape :box}]
@daveray
daveray / match.pojo.clj
Created August 27, 2011 03:02
Generate match lookup for a Java class
(ns match.pojo
(:use [match.core :only [IMatchLookup val-at* match]]))
(set! *warn-on-reflection* true)
(defmacro pojo-match
"Generate an implementation of match.core/IMatchLookup for the given Java class.
Keys are mapped like this:
isVisible -> :visible?
@daveray
daveray / perf.clj
Created August 28, 2011 02:58
match.java/bean-object perf compared to clojure.core/bean
; If I'm doing something completely bogus here, let me know :)
user=> (use 'match.core)
nil
user=>
(extend-type java.awt.Color
IMatchLookup
(val-at* [this k not-found]
(get (bean this) k not-found)))
nil
@daveray
daveray / vim.core.clj
Created September 8, 2011 18:21
Async vimclojure
(ns vim.core)
(defn async* [f]
(future
(let [result (with-out-str
(try
(println (f))
(catch Exception e
(.printStackTrace e
(java.io.PrintWriter. *out*))))) ]
@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:

@daveray
daveray / swap-vs-reset.clj
Created October 5, 2011 02:45
swap vs. reset
; First with reset! (don't do this!)
user=> (defn id-generator []
(let [id (atom 0)]
(fn []
(reset! id (inc @id)))))
#'user/id-generator
user=> (def g (id-generator))
#'user/g
user=> (doseq [i (range 10)]
(future
@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 / example.rb
Created October 10, 2011 02:29
Familial example
# (println (map #(* % %) (range 10))) becomes:
x = Familiar.with do
map fn {|x| x * x}, range(10)
end
Familiar.println x
=> (0 1 4 9 16 25 36 49 64 81)