This file contains hidden or 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 hidden or 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 irc-parser | |
| (:use clojure.contrib.duck-streams | |
| clojure.contrib.str-utils)) | |
| (defn flatten | |
| "Takes any nested combination of sequential things (lists, vectors, | |
| etc.) and returns their contents as a single, flat sequence. | |
| (flatten nil) returns nil." | |
| [x] | |
| (filter (complement sequential?) |
This file contains hidden or 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
| (("Hm. Not exactly packed in here. Anyone paying attention?" "hi" "hi!" "I'm still just reading the docs, but I have a quick question." "shoot" "What's the Right Way to compile and/or run a .clj file?" "I found how to get an interactive prompt, but nothing else yet." "any clj you add to the command line will get run" "there's also a Script class you can use instead of Repl when you don't want a prompt" "scripts are compiled when they're loaded, no static compilation" "ok, I underand no static compilation." "If I put my filename after src/boot.clj, I still just get a prompt." "Oh! I didn't print anything." "I bet my file got evaluated (no output) and then I got my prompt?" "could be" "any defs you made should be available" "ok, that's it, thanks." "I had it right before, just didn't realize it." "ok")) |
This file contains hidden or 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 irc-parser | |
| (:use clojure.contrib.duck-streams | |
| clojure.contrib.str-utils | |
| clojure.contrib.seq-utils)) | |
| (def dates (file-seq (java.io.File. "/Users/defn/git/clojure-irc"))) | |
| (defn parse-irc-log | |
| "Gets rid of all the junk in the irc log groupings and gives us a list of strings which is the content found in the channel." | |
| [logfile] |
This file contains hidden or 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
| (set! *print-length* 50) | |
| (set! *warn-on-reflection* true) | |
| ;; psykotic's trace-seq functions | |
| (defn trace-seq* [name xs printer] | |
| (for [x xs] | |
| (do (println name "->" (printer x)) | |
| x))) | |
| (defmacro trace-seq [xs & [printer]] |
This file contains hidden or 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
| (set! *print-length* 50) | |
| (set! *warn-on-reflection* true) | |
| ;; stuart sierra's multimap | |
| (defn add | |
| "Adds key-value pairs to the multimap." | |
| ([mm k v] | |
| (assoc mm k (conj (get mm k #{}) v))) | |
| ([mm k v & kvs] | |
| (apply add (add mm k v) kvs))) |
This file contains hidden or 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 geoip.analyze | |
| (:use clojure.contrib.str-utils | |
| [clojure.contrib.seq-utils :exclude [group-by]] | |
| [clojure.contrib.duck-streams :exclude [copy]] | |
| [clojure.set :only (union)] | |
| (incanter core datasets io charts stats) | |
| (geoip core)) | |
| (:import [com.maxmind.geoip Country | |
| Location | |
| Region |
This file contains hidden or 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 hidden or 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 find-lines [#^String text logfile] | |
| (filter | |
| (fn [#^String line] | |
| (< 0 (.indexOf line text))) | |
| (line-seq (reader logfile)))) | |
| (defn of-IPs [coll] | |
| (flatten | |
| (remove empty? | |
| (pmap |
This file contains hidden or 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 | |