Skip to content

Instantly share code, notes, and snippets.

; A wrapper to access Tokyo Cabinet from clojure
(ns tokyo-cabinet
; exclude symbols we'll use in our API
(:refer-clojure :exclude [use get]))
(declare *db*)
(defn get [key] (.get *db* key))
; Using "let" here, since in my real code I use the reference later.
; You could use "doto" if you just wanted to do a bunch of database
; operations and then close the db.
(let [pref-db (HDB.)]
(.open pref-db "user-prefs.hdb" (bit-or HDB/OWRITER HDB/OCREAT))
(.put pref-db "Hello World" "Saying Hi! to the big old world out there")
(println (.get pref-db "Hello World"))
(.close pref-db))
Pattern p = new Pattern("https?://[-\w]+\.\w[-\w/]*+");
Matcher m = new Matcher(p, text);
return m.replaceAll("<a href=\"$0\">$0</a>");
(defn urlize
"A function that takes some text and creates links out of URLs
that it finds"
([text]
(.replaceAll
(re-matcher #"https?://[-\w]+\.\w[-\w/]*+" text)
"<a href=\"$0\">$0</a>")))
(defn twitter-status
([tweet]
(defn login
([params session]
(dosync
(alter session assoc :twitter-user (params :twitter-user))
(alter session assoc :twitter-password (params :twitter-password)))
(compojure.http.helpers/redirect-to (str "/" (@session :twitter-user)))))
(def *twitter-url* "http://twitter.com/statuses/public_timeline.json")
(defn twitter-status
([tweet]
(html [:p {:class "tweet"}
(html [:div {:class "tweet-text"} (get tweet "text")])
(html [:div {:class "tweet-user"} (get (get tweet "user") "name") ])])))
(GET "/:twitter-name"
(page "Your Flock"
(html [:h1 "Welcome " (route :twitter-name)]
(map twitter-status
(read-json-string (let [[status headers body]
(http-get *twitter-url*)] body))))))
(GET "/:twitter-name"
(page "Your Flock"
(html [:h1 "Welcome " (route :twitter-name)])))
(load-file "./template.clj")
(ns flockr
(:use compojure )
(:refer flockr.template))