rlm@0: (ns coderloop.utils rlm@0: (:use [clojure.contrib rlm@0: [shell-out :only [sh]] rlm@0: [duck-streams :only [file-str read-lines copy]]]) rlm@0: (:use [clojure [string :only [trim blank? split]]])) rlm@0: rlm@0: rlm@0: rlm@0: rlm@0: rlm@0: rlm@0: (defn read-integer [file] rlm@0: (Integer/parseInt rlm@0: (trim (slurp (file-str file))))) rlm@0: rlm@0: (defn read-big-integer [file] rlm@0: (java.math.BigInteger. rlm@0: (trim (slurp (file-str file))))) rlm@0: rlm@0: rlm@0: (defn read-integer-line [#^java.lang.string s] rlm@0: (map #(Integer/parseInt %) rlm@0: (filter (comp not blank?) rlm@0: (split s #"\W")))) rlm@0: rlm@0: rlm@0: rlm@0: (defn read-integers rlm@0: "returns a lazy sequence of integers read from the file. rlm@0: Integers are delimited by any sort of whitespace" rlm@0: [#^java.io.File file] rlm@0: (mapcat read-integer-line rlm@0: (filter (comp not blank?) rlm@0: (read-lines (file-str file))))) rlm@0: rlm@0: rlm@0: (defn trans-print [x] rlm@0: (println x ) rlm@0: x) rlm@0: rlm@0: rlm@0: (defn md5 rlm@0: "given a string, compute the md5 checksum" rlm@0: [s] rlm@0: (let [t (java.io.File/createTempFile "zzz" "zzz")] rlm@0: (copy s t) rlm@0: (.deleteOnExit t) rlm@0: (sh "md5sum" (.getCanonicalPath t)))) rlm@0: rlm@0: rlm@0: (defn digits [n] rlm@0: (map #(Integer/parseInt (str %)) (seq (str n))))