Skip to content

Instantly share code, notes, and snippets.

@kelseyq
Last active August 29, 2015 14:00
Show Gist options
  • Save kelseyq/51dce2e997b393f469b5 to your computer and use it in GitHub Desktop.
Save kelseyq/51dce2e997b393f469b5 to your computer and use it in GitHub Desktop.
clojure newb code
(defn intOrZero
[theString]
(try (Integer/parseInt (clojure.string/trim theString))
(catch Exception e 0)))
(defn -main
[]
(let [expected (atom 0)
cnt (atom 0)
tweet (atom "")]
(defn updateWithChunk
[newText]
(do
(swap! cnt #(+ (count (byte-array (map byte newText))) %)) ;update count of bytes
(swap! tweet #(str % newText)) ;update current message)
))
(statuses-filter :params {:track "giants", :delimited "length"}
:oauth-creds my-creds
:callbacks (SyncStreamingCallback. (fn [_resp payload]
(let [bodyString (.toString payload)]
(do
(if (== @expected 0)
(let [splitBody (clojure.string/split bodyString #"\n" 2)]
(do
(reset! expected (intOrZero (get splitBody 0)));update the expected # of bytes
(updateWithChunk (get splitBody (dec (count splitBody))))
))
(updateWithChunk bodyString)
)
(if (>= @cnt @expected)
(do
(println (extractTweetInfo (readJson @tweet)))
(reset! expected 0)
(reset! cnt 0)
(reset! tweet "")
)
()
)
)))
(comp println response-return-everything)
exception-print))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment