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 search-log [log term] | |
(with-open [rdr (java.io.BufferedReader. | |
(java.io.FileReader. log ))] | |
(filter #(not (= -1 (.indexOf % term)) | |
(line-seq rdr)))) |
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 static class ImageDownloader | |
{ | |
public static string Server = "http://foo.bar.com/images"; | |
public static GetImage(string id) | |
{ | |
return DownloadURL(url + "/" + id); | |
} | |
} |
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 async-test | |
(:require urllib)) | |
(defmacro await-async [& body] | |
`(py.bytecode/YIELD_VALUE ~@body)) | |
(defn download-google | |
[] | |
(future | |
(with-open [x (urllib/urlopen "http://www.google.com")] |
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
(defproject clj-lobapp "0.1.0-SNAPSHOT" | |
:description "A Line of Business App in Clojure" | |
:url "http://github.com/halgari/clj-lobapp" | |
:dependencies [[org.clojure/clojure "1.4.0"] | |
[com.datomic/datomic-free "0.8.3343"] | |
[midje "1.4.0"]]) |
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
tim@tim-desktop:~/clj-lobapp$ ~/bin/lein midje | |
>>> Output from clojure.test tests: | |
FAIL in (a-test) (core_test.clj:7) | |
FIXME, I fail. | |
expected: (= 0 1) | |
actual: (not (= 0 1)) | |
>>> clojure.test summary: | |
Ran 1 tests containing 1 assertions. |
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
(defrecord Foo [exprs]) | |
(defn foo [& exprs] | |
(Foo. exprs)) |
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
[13235a60055c] {jit-log-opt-loop | |
# Loop 0 (0 LOAD_ARG) : loop with 196 ops | |
[p0, p1, p2] | |
+84: label(p0, p1, p2, descr=TargetToken(140251232256032)) | |
debug_merge_point(0, 0, '0 LOAD_ARG') | |
+135: p4 = getfield_gc(ConstPtr(ptr3), descr=<FieldP system.interpreter.Interpreter.inst__call_stack 16>) | |
+148: p6 = call(ConstClass(W_InternalList.getFirst), p4, descr=<Callr 8 r EF=0>) | |
+167: i7 = getfield_gc(ConstPtr(ptr3), descr=<FieldS system.interpreter.Interpreter.inst__ip 24>) | |
+180: i9 = call(ConstClass(get_bcode_at), p6, i7, descr=<Calli 8 ri EF=0>) | |
+209: i11 = int_add(i7, 1) |
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
user=> (let [r (range 10 13 2)] | |
(apply str (interpose "/" | |
(take 3 (concat r (reverse r)))))) | |
"10/12/12" | |
user=> |
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
;; Example: | |
;; (doseq-indexed idx [name names] | |
;; (println (str idx ". " name) | |
(defmacro doseq-indexed-functional [index-sym [item-sym coll] & body] | |
`(doseq [[~item-sym ~index-sym] | |
(map vector ~coll (range))] | |
~@body)) |
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 update-my-atom [a name] | |
(let [new-state (assoc-in @a [:foo :bar] merge {:name name})] | |
(swap! a (fn [old] new-state)))) | |
;; refactored into: | |
(defn get-new-state [state name] | |
(assoc-in state [:foo :bar] merge {:name name})) |
OlderNewer