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
| (let [method (.getMethod Long "valueOf" (into-array Class [String]))] | |
| (.invoke method Long (into-array Object ["123"]))) |
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
| (let [method (.getMethod String "indexOf" (into-array Class [String Integer/TYPE]))] | |
| (.invoke method "hello" (into-array Object ["ll" 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
| (with-open [rdr (io/reader (io/file "file.txt"))] | |
| (doseq [line (line-seq rdr)] | |
| (println "line:" line))) | |
| (with-open [lines (line-seq (io/file "file.txt"))] | |
| (doseq [line lines] | |
| (println "line:" line))) |
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 call [f & args] | |
| (when f (apply f args))) | |
| (def callbacks | |
| {:do-this #(println "this") | |
| :do-that #(println "that")}) | |
| (call (:do-this callbacks)) ;; prints "this" | |
| (call (:do-that callbacks)) ;; prints "that" | |
| (call (:do-other callbacks)) ;; nil |
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
| (deftype Foo [] | |
| Object | |
| (equals [this x] | |
| (.. this getClass (isInstance x)))) | |
| (let [f (Foo.)] | |
| (.equals f f)) ; false, creates problems when looking up items in map |
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
| (ns blah.test-mystuff | |
| (:use clojure.test)) | |
| (defn my-fixture [f] | |
| (println "setup") | |
| (f) | |
| (println "tear down")) | |
| (use-fixtures :each my-fixture) |
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
| (ns mefesto.qsort) | |
| (set! *warn-on-reflection* true) | |
| (defn- aswap! [^doubles vals ^ints idxs ^long x ^long y] | |
| (let [val (aget vals x) | |
| idx (aget idxs x)] | |
| (aset vals x (aget vals y)) | |
| (aset vals y val) | |
| (aset idxs x (aget idxs y)) |
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
| (require '[clojure.contrib.sql :as sql]) | |
| (sql/with-connection dbspec | |
| (sql/transaction | |
| (sql/do-prepared | |
| "update mytable set counter = counter + 1 | |
| where id = ?" | |
| [1000]))) |
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 encode [^String str] | |
| (ChannelBuffers/wrappedBuffer | |
| ^byte[] (into-array (concat (.getBytes "hello" "UTF-8") [(byte 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
| (defn encode [^String str] | |
| (ChannelBuffers/wrappedBuffer | |
| (.getBytes str "UTF-8") | |
| (byte-array [(byte 0)]))) |