Browse files

update to work with latest 1.2 bits:

  - new seq fns
  - new json keywords
  - duck-punched compojure until it gets updated
  • Loading branch information...
1 parent 843b39d commit 9abdb9c316ed93aa3138f67f23ead9fc01abe625 @stuarthalloway stuarthalloway committed Apr 30, 2010
Showing with 11 additions and 9 deletions.
  1. +5 −5 project.clj
  2. +2 −2 src/labs/unified_update_model.clj
  3. +4 −2 src/solutions/fight.clj
View
10 project.clj
@@ -2,11 +2,11 @@
:description "Clojure exercises, with integrated repl and webapp"
:dependencies [
[org.clojure/clojure
- "1.2.0-master-20100430.130229-58"]
+ "1.2.0-master-20100430.160229-59"]
[org.clojure/clojure-contrib
- "1.2.0-20100430.130503-89"]
- [compojure
- "0.3.2"]
+ "1.2.0-20100430.160503-90"]
+ [org.clojars.stuarthalloway/compojure
+ "0.3.3"]
[postgresql
"8.4-701.jdbc4"]
[log4j
@@ -20,7 +20,7 @@
[jline
"0.9.94"]
[circumspec
- "0.0.11"]]
+ "0.0.12"]]
:dev-dependencies [[autodoc "0.7.0"]
[swank-clojure "1.1.0"]]
:repositories {"clojure-releases" "http://build.clojure.org/releases"
View
4 src/labs/unified_update_model.clj
@@ -1,6 +1,6 @@
(ns labs.unified-update-model
(:use labrepl.util
- [clojure.contrib.json.read :only (read-json)]
+ [clojure.contrib.json :only (read-json)]
[clojure.http.client :only (request url-encode)])
(:require [solutions.atom-cache :as ac]
[solutions.ref-cache :as rc]
@@ -104,7 +104,7 @@
[[:h3 "Futures"]
[:p "A future represents work to be done off the current thread. To see futures in action, let's create something slow: a program that compares the estimated google results for two search terms. You will need to include the following namespaces:"
(code "(:use [clojure.http.client :only (request url-encode)]
- [clojure.contrib.json.read :only (read-json)])")]
+ [clojure.contrib.json :only (read-json)])")]
[:ol
[:li "The " (c request) " function takes a URL string and returns a map of response data. Try it a the REPL to see how it works."]
[:li "To get google search results, you will need the following URL prefix:"
View
6 src/solutions/fight.clj
@@ -1,15 +1,17 @@
(ns solutions.fight
(:use [clojure.http.client :only (request url-encode)]
- [clojure.contrib.json.read :only (read-json)]))
+ [clojure.contrib.json :only (read-json)]))
(def google-search-base
"http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=")
+(use 'clojure.contrib.pprint)
+
(defn estimated-hits-for
[term]
(let [http-response (request (str google-search-base (url-encode term)))
json-response (read-json (apply str (:body-seq http-response)))]
- (Long/parseLong (get-in json-response ["responseData" "cursor" "estimatedResultCount"]))))
+ (Long/parseLong (get-in json-response [:responseData :cursor :estimatedResultCount]))))
(defn fight
[term1 term2]

0 comments on commit 9abdb9c

Please sign in to comment.