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 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"}]))
(defn chain
"Composes functions, left to right, over the value `x`, returning a promise containing
the result. When composing, either `x` or the returned values may be values which can
be converted to a promise, causing the composition to be paused.
The returned promise will only be realized once all functions have been applied and their
return values realized.
(chain 1 inc #(future (inc %) => 3
@(chain (future 1) inc inc) => 3
> (println (disassemble (fn [x y] (+ x y))))
// Compiled from form-init6926380131348672798.clj (version 1.5 : 49.0, super bit)
public final class s3_journal$eval7007$fn__7008 extends clojure.lang.AFunction {
// Field descriptor #7 Lclojure/lang/Var;
public static final clojure.lang.Var const__0;
// Method descriptor #9 ()V
// Stack: 2, Locals: 0
public static {};
(defn persistent-socket
"Returns a channel, and a callback to be passed into a persistent-connection function"
(let [in (channel)
out (channel)
socket (splice out in)]
[socket
(fn [connection]
(connect out socket false true)
(connect socket in true false))))
@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!)
(defn timeout-line-seq
"Takes a reader, and returns a line-seq that can time out on reading the next line."
[^Reader reader timeout]
(let [q (LinkedBlockingQueue. 10)
q-seq (fn this []
(lazy-seq
(if-let [l (.poll q timeout TimeUnit/MILLISECONDS)]
(when-not (= ::end l)
(cons l (this)))
(do
(def gen-recursive
(gen/one-of
[(gen/return :a)
(gen/tuple (gen/return :b) gen-recursive)]))
(gen/sample gen-recursive) ;; NPE
(defn f []
(-> #{}
(transient)
(conj! -24)
(persistent!)
(conj 0)
(conj 0)
(conj 0)
(conj 0)
(conj 0)
@ztellman
ztellman / gist:6499083
Created September 9, 2013 17:50
Some books I'd like to include in my upcoming EuroClojure talk

Though, of course, I'm still unclear how I'm going to stitch them all together.

Seeing Like a State by James Scott

Patterns of Software by Richard Gabriel

A Thousand Plateuas by Deleuze and Guattari

Collection Fictions by JL Borges

(use 'riddley.walk 'riddley.compiler)
(defmacro symbol-macrolet [bindings & body]
`(let [~@(->> bindings
(partition 2)
(mapcat
(fn [[k v]]
[(with-meta k {::symbol-macro v}) nil])))]
~@body))