Skip to content

Instantly share code, notes, and snippets.

View zerg000000's full-sized avatar

Albert Lai zerg000000

View GitHub Profile
; copy from https://github.com/daveray/seesaw/blob/develop/src/seesaw/options.clj
(defrecord Option [name setter getter examples])
(defmacro bean-option
[name-arg target-type & [set-conv get-conv examples]]
(let [[option-name bean-property-name] (split-bean-option-name name-arg)
target (gensym "target")]
`(Option. ~option-name
(fn [~(with-meta target {:tag target-type}) value#]
(-> (frame :title "Why Swing, why?"
:on-close :exit
:content (label :text "Hiya"
:border 5
:background "#888"
:foreground :blue))
pack!
show!)
@zerg000000
zerg000000 / gist:5019830
Last active December 14, 2015 03:19
Convert Java Bean to Clojure map
(bean (java.util.Date.))
{:seconds 40, :date 23, :class java.util.Date,
:minutes 47, :hours 21, :year 113,
:timezoneOffset -480, :month 1, :day 6,
:time 1361627260711}
@zerg000000
zerg000000 / bst.clj
Created February 15, 2013 03:35
A clojure implement of binary search tree
(ns com.example.bst)
; using {:val :left :right} as tree data structure
(defn node [val & [left right other]]
{:val val :left left :right right :bag other})
(defn insert [parent i-node]
(let [i-val (:val i-node)
p-val (:val parent)
side (cond (> i-val p-val) :left
@zerg000000
zerg000000 / simple-fizzbuzz.clj
Created January 6, 2012 03:02
A clojure version of fizzbuzz in 5 minutes
(defn mod3? [num] (= (mod num 3) 0))
(defn mod5? [num] (= (mod num 5) 0))
(defn fizzbuzz [num] (cond (and (mod3? num) (mod5? num)) "FizzBuzz"
(mod5? num) "Buzz"
(mod3? num) "Fizz"
:else num))
(map fizzbuzz (range 1 101))