This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns datasifter) | |
;; Write a data sifter, sift, that partitions a string into a list of lists. | |
;; Start with the case of using letters as a delimiter, and numbers as data. | |
;; There can be any number of repetitions of numbers & letters. | |
;; | |
;; user=>(sift "a1b2cd34") | |
;; (("a" ("1")) ("b" ("2")) ("c" ()) ("d" ("3" "4"))) | |
;; | |
;; from http://fulldisclojure.blogspot.com/2010/01/code-kata-data-sifter.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn count-ips [logfile] | |
(remove empty? | |
(persistent! (reduce | |
#(assoc! %1 %2 (inc (get %1 %2 0))) | |
(transient {}) | |
(of-IPs | |
(find-lines "Deny tcp src outside" logfile)))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; this file is a walkthrough of Moustache features, a web framework for Clojure | |
;; http://github.com/cgrand/moustache/tree/master | |
;; Moustache allows to declare routes, apply middlewares and dispatch on http methods. | |
;; Moustache is compatible with all frameworks built on Ring, including Compojure | |
(ns demo | |
(:use net.cgrand.moustache) | |
(:use [ring.adapter.jetty :only [run-jetty]])) ;; hmmm Ring without servlets | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn categorize-code [files] | |
(reduce (fn [result code] | |
(try | |
(let [r (*sandbox* code)] | |
(update-in result [:good] conj [code r]) | |
[code (pr-str r)]) | |
(catch Exception e | |
(update-in result [:bad] conj code)))) | |
{} | |
(find-lines text files))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns defn-test | |
(:use clj-html.core | |
[net.cgrand.moustache :only [app]] | |
[ring.adapter.jetty :only [run-jetty]] | |
[ring.util.response :only [response]])) | |
(defhtml application [text body] | |
[:html | |
[:head | |
[:title text]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn truncate [t coll] | |
(map (fn [ct] | |
(if (>= (count ct) t) | |
(apply str (take t ct) "...") | |
ct)) coll)) | |
(defn walton* | |
[#^String s t m?] | |
(let [result (walton-doc s)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn rand-range [m n] | |
(+ m (rand-int (- n m)))) | |
(defn with-transient [x f] | |
(persistent! (f (transient x)))) | |
(defn swap-entries! [x i j] | |
(assoc! x i (x j) j (x i))) | |
(defn knuth-shuffle [xs] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def *enc-files-dir* "/home/blah/sandbox/enc") | |
(def *dec-files-dir* "/home/blah/sandbox/dec") | |
(defstruct file-map :filename :path :modified) | |
(defn #^{:doc "Return vec of file-maps"} | |
file-list [path] | |
(vec | |
(map (fn [n] | |
(struct-map file-map |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def file-info-extractors | |
{:filename #(.getName #^java.io.File %) | |
:path #(str (.toURI #^java.io.File %)) | |
:modified #(.lastModified #^java.io.File %)}) | |
(map #(reduce (fn [m [k e]] | |
(assoc m k (e %))) | |
{} | |
file-info-extractors) | |
(.listFiles (java.io.File. "."))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user> (read-string (str {:hai "there" "hello" 3 5 "5"})) | |
{:hai "there", "hello" 3, 5 "5"} |
OlderNewer