Skip to content

Instantly share code, notes, and snippets.

View ztellman's full-sized avatar
💭
boiling the ocean

Zach Tellman ztellman

💭
boiling the ocean
View GitHub Profile
(ns draw-order (:use [penumbra.opengl] [penumbra.window]))
(defn- init [state]
(enable :depth-test)
(ortho-view 0 0 640 480 -1 1)
(scale 1 1 -1)
state)
(defn draw-square [x y w h]
(draw-quads
(ns scratchpad
(:use [aleph.core :only (siphon wrap-channel)]
[aleph.tcp :only (start-tcp-server)]
[aleph.formats :only (channel-buffer->string)]))
(defn echo-handler [channel connection-info]
(siphon (wrap-channel channel #(str "Response : " (channel-buffer->string %))) channel))
;; Returns function to stop the server
(def server (start-tcp-server echo-handler {:port 8080}))
(ns dining-service
(:use aleph.core)
(:use aleph.http)
(:use net.cgrand.moustache)
)
(defn report-handler [response-channel request]
(enqueue response-channel
{:status 200
:headers {"content-type" "text/plain"}
@ztellman
ztellman / simple.clj
Created December 26, 2010 19:13 — forked from zoka/simple.clj
;;
(ns clojfix.simple)
(use 'gloss.core 'gloss.io)
(import
[java.nio
ByteBuffer])
@ztellman
ztellman / nbt.clj
Created January 1, 2011 21:42 — forked from pepijndevos/nbt.clj
(ns test
(:use [gloss core io]))
(defcodec tag (enum :byte :end :byte :int16 :int32 :int64 :float32 :float64 :bytes :string :list :compound))
(defcodec tstring (finite-frame :int16 (string :utf-8)))
(defcodec tbytes (repeated :byte))
(declare tcompound)
(declare tlist)
(defn handler [ch _] (receive-all ch print) (enqueue ch "hi"))
(defn test-harness []
(let [[a b] (channel-pair)]
(handler b nil) ;; give handler one side of the channel pair
(enqueue a 1 2 3) ;; these will be received by 'b', and the handler will print out '123'
(println (channel-seq a)))) ;; will print '["hi"]'
(defn handler [chi cho]
(let [parse (fn-match ([["GETT" ?gid ?uid]]
(if-let [v ((data gid) uid)]
(str v)
(str "ERROR_" gid "_" uid)))
([["STOP_SESSION"]] (close chi))
([["STOP"]] (System/exit 0)))]
#_ (receive-all chi #(enqueue cho (str "You said: " % "\r\n")))
(siphon (map* #(parse (re-seq #"\S+" %)) chi) cho)))
@ztellman
ztellman / gist:1563018
Created January 5, 2012 00:21 — forked from joshrotenberg/gist:1563014
request
(compile-frame
(ordered-map
:req (string :utf-8 :length 4)
:type :int32
:data (string :utf-8 :prefix :int32))
(fn [x] (update-in x [:data] #(->> % (interpose "\0") (apply str))))
(fn [x] (update-in x [:data] #(seq (.split ^String % "\0")))))
(defn retrieve-json
"retrieve json content"
[url]
(run-pipeline
(http-request {:method :get, :url url, :auto-transform true}))
:body
println))
@ztellman
ztellman / gist:2015256
Created March 11, 2012 06:15 — forked from bmmoore/gist:2015208
trying to make a manyTill for gloss
(def empty-frame (compile-frame []))
(defn repeated-until [element done]
(let [element* (compile-frame element (fn [v] (if (nil? v) done v)) (fn [v] (if (= v done) nil v)))
self (promise)
impl (header element* (fn [elt] (if (nil? elt) empty-frame (compile-frame @self rest (partial cons elt)))) first)]
(deliver self impl)
impl))