Skip to content

Instantly share code, notes, and snippets.

@bhenry
Created September 16, 2010 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhenry/582538 to your computer and use it in GitHub Desktop.
Save bhenry/582538 to your computer and use it in GitHub Desktop.
(ns qa.deaf
(:use [clojure.contrib
[server-socket :only [create-server]]
[duck-streams :only [reader writer]]]))
(def port 6662)
(def count-BYE (ref 0))
(defn listener [input]
(cond (= input "BYE")
(cond (= 0 @count-BYE) "HI?"
(= 1 @count-BYE) "PIE?"
(= 2 @count-BYE) "BYE!")
(= input (.toUpperCase input))
(format "Not since %d" (+ 1930 (int (rand 20))))
:else
(get ["Speak up!" "What?" "Eh?!"] (int (rand 3)))))
(defn handle-client [in out]
(binding [*in* (reader in)
*out* (writer out)]
(loop [r (str (read-line))]
(println (listener r))
(dosync (if (= r "BYE")
(alter count-BYE inc)
(ref-set count-BYE 0)))
(if (< @count-BYE 3)
(recur (str (read-line)))))))
(defonce srvr (create-server port #'handle-client))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment