Skip to content

Instantly share code, notes, and snippets.

View thread_usage.clj
1 Hehe!
2 Hehe!
3 Hehe!
4 Hehe!
5 Hehe!
6 Hehe!
7 Hehe!
8 Hehe!
9 Hehe!
10 Hehe!
View thread_usage.clj
user> (require '[zolo.utils.thread :as zthread])
nil
user> (def x (atom 0))
#'user/x
user> (defn print-x []
(if (> (swap! x inc) 10)
(throw (RuntimeException. "OUCH!")))
(println @x "Hehe!"))
View thread.clj
(ns zolo.utils.thread
(:use zolo.utils.clojure)
(:require [zolo.utils.logger :as logger])
(:import [java.util.concurrent ThreadFactory ScheduledThreadPoolExecutor TimeUnit]))
(defn- random-thread-name [prefix]
(str prefix "-" (random-guid-str)))
(defn thread-factory [thread-name-prefix]
View gist:4699679
(ns cms.data
(:require [cms.domain.author :as au]
[cms.domain.article :as ar]))
(defn setup []
(au/create "Siva" "s@e.com")
(au/create "Amit" "a@e.com")
(let [siva (au/find-by-email "s@e.com")]
(au/add-article-with-tags siva "Datomic Workshop" "Datomic is cool" :category/tech ["database" "logic"])
View gist:4699135
(ns cms.datomic.schema
(:require [datomic.api :as db]))
(def author-schema
[;; name
{:db/id #db/id[:db.part/db]
:db/ident :author/name
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "A author's name"
View pp_str_usage.clj
user> (println (pp-str m "blah blah" m))
{:a 1,
:c {:a 1, :c {:a 1, :b 2}, :b 2},
:b [2 3],
:d [{:a 1, :c 3, :b 2} {:a [1 2 3], :b {:a 1, :b 2}}]}
"blah blah"
{:a 1,
:c {:a 1, :c {:a 1, :b 2}, :b 2},
:b [2 3],
:d [{:a 1, :c 3, :b 2} {:a [1 2 3], :b {:a 1, :b 2}}]}
View pp_str.clj
(defn pp-str [& things]
(let [s (with-out-str (pprint things))]
(-> s
(.substring 0 (-> s .length dec dec))
(.replace "(" " ")
(str "\n"))))
View m_printed.clj
user> (println m "blah blah" m)
{:a 1, :c {:a 1, :c {:a 1, :b 2}, :b 2}, :b [2 3], :d [{:a 1, :c 3, :b 2} {:a [1 2 3], :b {:a 1, :b 2}}]} blah blah {:a 1, :c {:a 1, :c {:a 1, :b 2}, :b 2}, :b [2 3], :d [{:a 1, :c 3, :b 2} {:a [1 2 3], :b {:a 1, :b 2}}]}
View m.clj
{:a 1,
:c {:a 1, :c {:a 1, :b 2}, :b 2},
:b [2 3],
:d [{:a 1, :c 3, :b 2} {:a [1 2 3], :b {:a 1, :b 2}}]}
View using_pmapcat.clj
(defn handle-batch [batch]
(blah blah...))
(->> coll
(partition-all n)
(pmapcat handle-batch))