Skip to content

Instantly share code, notes, and snippets.

View danlentz's full-sized avatar

Dan Lentz danlentz

View GitHub Profile
;;; XML parsing and clojure.zip
;;; There's got to be a cleaner way to do this.
;;; I have code like this:
(defn jdks-loc [xml-zipper]
(zip/down
(first
(filter #(let [n (zip/node %)]
(ns resource
"Automatic resource cleanup."
(:import (java.lang.ref ReferenceQueue PhantomReference)))
(def ^:private queue (ReferenceQueue.))
(def ^:private cleanup-fns {})
(defn resource
"Returns a reference to x. At some point after the reference is
@danlentz
danlentz / better.clj
Created February 18, 2014 06:29 — forked from pingles/better.clj
(defn subscriber-seq
[ch qname]
(let [[message-seq put] (pipe)]
(letfn [(message-handler [ch msg-meta payload])
(put {:ch ch :msg-meta msg-meta :payload payload})]
(lc/subscribe ch qname message-handler :auto-ack true))
message-seq))
(defn payload-str
[x]
@danlentz
danlentz / pipe.clj
Last active August 29, 2015 13:56 — forked from pingles/pipe.clj
(let [[message-seq put] (pipe)]
(letfn [(message-handler [ch msg-meta payload])
(put {:ch ch :msg-meta msg-meta :payload payload})]
(lc/subscribe ch qname message-handler :auto-ack true))
message-seq)
(let [[message-seq put] (pipe)]
(letfn [(message-handler [ch msg-meta payload]
(put {:ch ch :msg-meta msg-meta :payload payload}))]
(lc/subscribe ch qname message-handler :auto-ack true))
(defprotocol ToClojure
(to-clojure [x]))
(extend-protocol ToClojure
List (to-clojure [xs] (map to-clojure xs))
RecommendedItem (to-clojure [x] {:item (.getItemID x)
:value (.getValue x)}))
(def conv-table (sorted-map 1 :I
4 :IV
5 :V
9 :IX
10 :X
40 :XL
50 :L
90 :XC
100 :C
400 :CD
(defn maybe-word
[s]
(if (= "" s) [] [s]))
(defprotocol WordState
(append-chunk [this chunk] "Append a chunk to current word state")
(append-segment [this segment] "Append a segment to current word state")
(to-word-list [this] "Returns the state as a list of words"))
@danlentz
danlentz / net.cljs
Created December 7, 2013 06:03 — forked from darkone23/net.cljs
(ns example.net
(:require [goog.net.WebSocket]
[goog.events :refer (listen)]
[cljs.core.async :as async :refer (chan <! >! put! close)]
[cljs.core.async.impl.protocols :as proto])
(:require-macros [cljs.core.async.macros :refer (go)]))
(defn ws
"WebSocket as a core.async channel
returns a channel which delivers the ws chan then closes"
(ns parse.core
(:require [instaparse.core :as insta]))
(def parser
(insta/parser
"sexp = lparen operation rparen
<lparen> = <'('>
<rparen> = <')'>
operation = operator + args
operator = '+'
  • workflow

start by opening up PSQL

$ heroku pg:psql -a isis-db

what tables have we got?

\d

let's get a little more detail

\d+