This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(-> (frame :title "Why Swing, why?" | |
:on-close :exit | |
:content (label :text "Hiya" | |
:border 5 | |
:background "#888" | |
:foreground :blue)) | |
pack! | |
show!) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 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#] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function trickyToString(data, withComma) { | |
var outStr = ""; | |
for( key in data ) { | |
outStr = outStr + key; | |
if(withComma) { | |
outStr = outStr + "," + data[key]; | |
} else { | |
outStr = outStr + ";" + data[key]; | |
} | |
outStr = outStr + "\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function trickyToString(data, withComma, withQuot) { | |
var outStr = ""; | |
for( key in data ) { | |
outStr = outStr + quot(key, withQuot); | |
if(withComma) { | |
if(withQuot) { | |
outStr = outStr + "," + quot(data[key], withQuot); | |
} else { | |
outStr = outStr + ","; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Parameter Object opts instead of withQuot and withComma | |
function trickyToString(data, opts) { | |
//trickyToString become a Template method | |
// quot and comma flag become Strategy of trickyToString method | |
var quotFunc = opts.withQuot || function(s){ return s; }; | |
var commaFunc = opts.withComma || function(){ return ","; }; | |
var outStr = ""; | |
for( key in data ) { | |
outStr = outStr + quotFunc(key) + commaFunc() + quotFunc(data[key]) + "\n"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Mailer { | |
public void send(String content) { | |
String to = "[email protected]"; | |
String from = "[email protected]"; | |
String host = "localhost"; | |
// Get system properties | |
Properties properties = System.getProperties(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use 'clojure.core.logic) | |
(require '[clojure.core.logic.fd :as fd]) | |
(def result | |
(run* [q] | |
(fresh [a b c d e f g h p ab cd ef gh ppp] | |
(fd/in a b c d e f g h p (fd/interval 1 9)) ; why not zero? | |
(fd/in ab cd ef gh (fd/interval 10 99)) | |
(fd/in ppp (fd/interval 100 999)) | |
(fd/eq |
OlderNewer