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
| (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
| (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
| (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
| (("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)) | |
| (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
| (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
| (defn serve-file | |
| "Attempts to serve up a static file from a directory, which defaults to | |
| './public'. Nil is returned if the file does not exist. If the file is a | |
| directory, the function looks for a file in the directory called 'index.*'." | |
| ([path] | |
| (serve-file "public" path)) | |
| ([root path] | |
| (let [filepath (File. root path)] | |
| (if (safe-path? root path) | |
| (cond |
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
| ;============================== | |
| ; Communicate with the server | |
| ;============================== | |
| (defn get-doc [doc] | |
| (str (sh *markdown-command* (str *core-docs* doc) "-x" "codehilite") | |
| (if (examples-which-exist doc) | |
| (sh *markdown-command* (str *examples-dir* doc) "-x" "codehilite")))) | |
| ;============================== | |
| ; Layout |
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 print-markdown-doc | |
| "This is a modified version of print-doc which outputs the documentation in markdown format." | |
| [v] | |
| [(str "###" (:name (meta v)) "###\n") | |
| (str "> *" (ns-name (:ns (meta v))) "/" (:name (meta v)) "*") | |
| (str "> ") | |
| (str "> :::clojure") | |
| (str "> " (:arglists (meta v)) "") | |
| (str "> ") | |
| (when (:macro (meta v)) |