Skip to content

Instantly share code, notes, and snippets.

Timothy Baldridge halgari

View GitHub Profile
View gist:3099717
(defn search-log [log term]
(with-open [rdr (java.io.BufferedReader.
(java.io.FileReader. log ))]
(filter #(not (= -1 (.indexOf % term))
(line-seq rdr))))
@halgari
halgari / gist:3181861
Created Jul 26, 2012
example image downloader with global scope
View gist:3181861
public static class ImageDownloader
{
public static string Server = "http://foo.bar.com/images";
public static GetImage(string id)
{
return DownloadURL(url + "/" + id);
}
}
@halgari
halgari / gist:3213067
Created Jul 31, 2012
Async example in clojure-py
View gist:3213067
(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")]
View gist:3223290
(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"]])
View gist:3223305
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.
@halgari
halgari / gist:3237283
Created Aug 2, 2012
varargs defrecord
View gist:3237283
(defrecord Foo [exprs])
(defn foo [& exprs]
(Foo. exprs))
View gist:3341474
[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)
@halgari
halgari / 101212
Created Oct 12, 2012
Rube Goldberg Dates
View 101212
user=> (let [r (range 10 13 2)]
(apply str (interpose "/"
(take 3 (concat r (reverse r))))))
"10/12/12"
user=>
View gist:4136116
;; 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))
@halgari
halgari / gist:4195378
Created Dec 3, 2012
Atom refactoring
View gist:4195378
(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}))
You can’t perform that action at this time.