Skip to content

Instantly share code, notes, and snippets.

(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
(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)))
(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]]
(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]
(("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"))
(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?)
(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
(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
;==============================
; 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
(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))