Skip to content

Instantly share code, notes, and snippets.

View amitrathore's full-sized avatar

Amit Rathore amitrathore

View GitHub Profile
1 Hehe!
2 Hehe!
3 Hehe!
4 Hehe!
5 Hehe!
6 Hehe!
7 Hehe!
8 Hehe!
9 Hehe!
10 Hehe!
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!"))
(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]
(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"])
(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"
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}}]}
(defn pp-str [& things]
(let [s (with-out-str (pprint things))]
(-> s
(.substring 0 (-> s .length dec dec))
(.replace "(" " ")
(str "\n"))))
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}}]}
@amitrathore
amitrathore / m.clj
Last active December 10, 2015 23:19
{: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}}]}
@amitrathore
amitrathore / using_pmapcat.clj
Created November 26, 2012 08:20
using pmapcat
(defn handle-batch [batch]
(blah blah...))
(->> coll
(partition-all n)
(pmapcat handle-batch))