This file contains hidden or 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
;; not sure whether this is an improvement but I don't really like letfn | |
(defn keep-only | |
[n bucket-fn s] | |
((fn my-filter | |
[s seen] | |
(lazy-seq | |
(when (seq s) | |
(let [e (first s) | |
b (bucket-fn e) | |
c (inc (get seen b 0))] |
This file contains hidden or 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
(defmacro defcomp [name doc args & fs] | |
(let [fnmeta {:doc doc :arglists `'(~args)}] | |
`(def ~(with-meta name fnmeta) (comp ~@fs)))) |
This file contains hidden or 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 'name.choi.joshua.fnparse) | |
(def tokenize (partial re-seq #"[\[\](){}]|[^\[\](){}]+")) | |
(defn initial-state | |
[input] {:remainder (tokenize input) | |
:brackets (list)}) |
This file contains hidden or 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
user> | |
(let [[_ e-class e-name & e-ret :as catch-clause] '(catch Exception _ x)] | |
`(catch ~e-class ~e-name (do (println ~e-name) ~@e-ret))) | |
(catch Exception _ (do (clojure.core/println _) x)) |
This file contains hidden or 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
(defmacro add-field [document field] | |
(let [fstr (str field)] | |
`(.add document (Field. ~fstr ~field | |
Field$Store/YES Field$Index/ANALYZED)))) | |
(defn create-document | |
[json] | |
(let [age (NumericField. "age" Field$Store/YES true) | |
vintage (NumericField. "vintage" Field$Store/YES true) | |
document (Document.) |
This file contains hidden or 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
cascalog.playground> (?<- (stdout) [?person ?age] (age ?person ?age) (< ?age 30)) | |
INFO - using default application jar, may cause class not found exceptions on the cluster | |
INFO - using application jar: /home/akm/src/clojure/hadoop/lib/cascading-core-1.2-wip-63.jar | |
INFO - [] starting | |
INFO - [] source: cascalog.MemorySourceTap@3e0 | |
INFO - [] sink: StdoutTap["SequenceFile[[UNKNOWN]->[ALL]]"]["/tmp/temp69430827573878467652505554465178270"]"] | |
INFO - [] parallel execution is enabled: false | |
INFO - [] starting jobs: 1 | |
INFO - [] allocating threads: 1 | |
INFO - [] starting step: (1/1) ...eFile[[UNKNOWN]->[ALL]]"]["/tmp/temp69430827573878467652505554465178270"]"] |
This file contains hidden or 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 break | |
[pred coll] | |
(lazy-seq | |
(if-let [[x & rest :as all] (not-empty coll)] | |
(if-not (pred x) | |
[() all] | |
(let [[a b] (break pred rest)] | |
[(cons x a) b])) | |
[() ()]))) |
This file contains hidden or 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
Which do you like better? Will the second have issues if the user has an unusual ns declaration, in which clojure.core/cond is not mapped? | |
(defmacro cond [& clauses] | |
(if-not (even? (count clauses)) | |
(throw (IllegalArgumentException. "cond requires an even number of forms")) | |
(reduce (fn [else [test then]] | |
`(if ~test ~then ~else)) | |
nil | |
(reverse (partition 2 clauses))))) |
This file contains hidden or 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
(import java.awt.event.ActionListener) | |
(defn add-action [cmp fn] | |
(doto cmp | |
(.addActionListener (doto (proxy [ActionListener] []) | |
(update-proxy {"actionPerformed" fn}))))) | |
(defn add-action [cmp fn] | |
(doto cmp | |
(.addActionListener (reify ActionListener |
This file contains hidden or 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
<!-- | |
Seriously guys, CSS has been around a long time. Don't send me these | |
disgusting nested <table>s; I will never buy a product after seeing this. | |
--> | |
</td> | |
</tr> | |
</table> | |
</td> | |
</tr> |