Skip to content

Instantly share code, notes, and snippets.

@henryw374
Created May 18, 2018 08:34
Show Gist options
  • Select an option

  • Save henryw374/75b68fe4bd00ea0ba15ffa3f054ac5b4 to your computer and use it in GitHub Desktop.

Select an option

Save henryw374/75b68fe4bd00ea0ba15ffa3f054ac5b4 to your computer and use it in GitHub Desktop.
; stack dump
(require '[clojure.stacktrace :as stck])
(defn jstack [n]
(let [threadMXBean (java.lang.management.ManagementFactory/getThreadMXBean)
info (.getThreadInfo threadMXBean (.getAllThreadIds threadMXBean) 100)]
(print
(for [threadInfo info]
(str
(newline)
(.getThreadName threadInfo)
"\n" (.getThreadState threadInfo)
"\n"
(with-out-str
(let [st (.getStackTrace threadInfo)]
(newline)
(print " at ")
(if-let [e (first st)]
(stck/print-trace-element e)
(print "[empty stack trace]"))
(newline)
(doseq [e (if (nil? n)
(rest st)
(take (dec n) (rest st)))]
(print " ")
(stck/print-trace-element e)
(newline)))))))))
;datomic
(d/q '[:find ?x
:where
[?x ]
]
db)
; create test datomic
(def conn (do
(def url "datomic:mem://test")
(d/delete-database url)
(d/create-database url)
(d/connect url)))
; show the month
(require '[joda-time :as j])
(defn mth
([] (apply mth (-> (j/date-time)
j/as-map
((juxt :year :monthOfYear)))))
([m] (mth (-> (j/date-time)
j/as-map
:year ) m))
([y m]
(let [today (j/local-date)
start (j/date-time y m)
period (j/interval {:start start :period (j/months 1)})
days (->> start
(iterate #(j/plus % (j/days 1)))
(take-while #(j/contains? period %)))
week-count (atom 1)]
(->>
(map #(vector
%
(if (j/monday? %)
(swap! week-count inc)
@week-count)) days)
(group-by second)
vals
(map (fn [x] (into {} (map (juxt
#(.getAsText (j/property % :dayOfWeek))
#(let [dm (.get (j/property % :dayOfMonth))]
(if (= today (j/local-date %))
(format "*%d*" dm)
dm))) (map first x)))))
;(p/map-vals count)
(clojure.pprint/print-table [ "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday"])))))
(mth $go$)
; what's going on
(.getName (java.lang.management.ManagementFactory/getRuntimeMXBean))
(-> (java.lang.management.ManagementFactory/getMemoryMXBean)
.getHeapMemoryUsage
.getUsed
(/ 1000 1000)
long)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment