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 com.x.aleph-test
(require [aleph.http :as http]
[manifold.deferred :as d]
[manifold.stream :as s]
[compojure.core :only [routes ANY GET PUT POST] :as compojure]
[compojure.handler :as handler]
[clj-http.client :as http-client]
))
(comment
@ztellman
ztellman / foami.clj
Last active September 22, 2017 16:05 — forked from cgrand/foami.clj
(ns foami.core
"FOreign Asynchronous Mechanism Interop"
(:require [clojure.core.async :as async]))
(defn put!
"Takes a `ch`, a `msg`, a single arg function that when passed `true` enables backpressure
and when passed `false` disables it, and a no-arg function which, when invoked, closes the
upstream source."
[ch msg backpressure! close!]
(let [status (atom :sending]
(ns inkystarter
"Intro sketch for inky.cc, fork away."
(:require [inky.sketch :as sketch]))
(sketch/page-style!
(concat
sketch/default-styles
[:body {:font-family "'Helvetica Neue', Arial, sans-serif"}
:.sketch {:padding "30px"}]))
@ztellman
ztellman / haiku.cljs
Last active January 1, 2016 06:59 — forked from zk/haiku.cljs
(ns almost.haiku
(:require [inky.sketch :as sketch]
[dommy.core :as dom]
[clojure.string :as str]
[cljs.core.async :as async
:refer [<! >! put! chan timeout]])
(:require-macros [dommy.macros :refer [sel1 node]]
[cljs.core.async.macros :refer [go]]))
(enable-console-print!)
@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))
(defn retrieve-json
"retrieve json content"
[url]
(run-pipeline
(http-request {:method :get, :url url, :auto-transform true}))
:body
println))
@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 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)))
(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"]'
@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)