Skip to content

Instantly share code, notes, and snippets.

View xtang's full-sized avatar

xiaomin tang xtang

View GitHub Profile
@xtang
xtang / gist:3952180
Created October 25, 2012 11:54
Clojure: Iterate over map
(doseq [[k v] db] (prn k v))
@xtang
xtang / digest.clj
Created August 24, 2012 04:32 — forked from eliasson/digest.clj
Clojure md5 digest
(defn md5-sum
"Compute the hex MD5 sum of a string."
[#^String input]
(let [alg (doto (MessageDigest/getInstance "MD5")
(.update (.getBytes input)))
hash (.toString (new BigInteger 1 (.digest alg)) 16)
length (.length hash)]
(if (> 32 length)
;; 0x065 => 65, leading zero is dropped by BigInteger
(apply str (concat (repeat (- 32 length) \0) hash))