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
| ; 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)) |
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
| ; 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)) |
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
| Pattern p = new Pattern("https?://[-\w]+\.\w[-\w/]*+"); | |
| Matcher m = new Matcher(p, text); | |
| return m.replaceAll("<a href=\"$0\">$0</a>"); |
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 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] |
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 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))))) |
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
| (def *twitter-url* "http://twitter.com/statuses/public_timeline.json") |
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 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") ])]))) |
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
| (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)))))) |
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
| (GET "/:twitter-name" | |
| (page "Your Flock" | |
| (html [:h1 "Welcome " (route :twitter-name)]))) | |
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
| (load-file "./template.clj") | |
| (ns flockr | |
| (:use compojure ) | |
| (:refer flockr.template)) |