View orig.clj
(defn future-live-update2 | |
"Will terminate in when @gate goes false." | |
[gate-ref my-function] | |
(my-function) | |
(and @gate-ref (recur gate-ref my-function))) |
View gist:321938
(ns | |
#^{:doc "This is allows us to create Decoratable collection. | |
The idea is that the we a state map and add a key :decs which points to | |
a set of keys. Each of which is associated with a Decoration. We then | |
define a recursive mutifunction that grabs this :decs set and processes | |
each in turn (order is described later). | |
There are three types of decoration function. Centre is the main function, in | |
respect to which are defined pre and post functions that occur before and | |
after centre is called, respectively. |
View cs2.clj
(ns | |
#^{:doc "New definitions for a timeseries type"} | |
esjtools.ts | |
(:use clojure.test) | |
(:import (clojure.lang PersistentTreeSet))) | |
;;---------------------------------------------------------------------------- | |
(defprotocol Trim | |
"Trim a timeseries. There are performance advantages to having older+newer |
View ts.clj
(ns | |
#^{:doc "New definitions for a timeseries type"} | |
ts | |
(:use clojure.test) | |
(:import (clojure.lang PersistentTreeSet) | |
(java.io Writer))) | |
;;---------------------------------------------------------------------------- | |
(defprotocol Trim | |
"Trim a timeseries. There are performance advantages to having older+newer |
View gist:466790
(defn create-ts [dataset cons-method] | |
(reify | |
Object | |
(equals [this o] | |
(or (identical? this o) | |
(and (.isInstance name o) | |
(= dataset (. o dataset))))) | |
(hashCode [this] | |
(hash dataset)) |
View gist:837299
(defn pluralize | |
"Turn a string to plural" | |
[x] | |
(if (= (last (name x)) \y) | |
(apply str (concat (drop-last (name x)) [\i \e \s])) | |
(str (name x) "s"))) | |
(defn table [t] | |
(cql/table db (pluralize t))) |
View accouting.core.clj
(ns accounting.database | |
(:require [clojureql.core :as cql] | |
[relational-model.core :as rel])) | |
(def db {:classname "com.mysql.jdbc.Driver" | |
:subprotocol "mysql" | |
:subname "//localhost:3306/accounting" | |
:user "root" | |
:password "" | |
:auto-commit true |
View redis.clj
;;------------------------------------------------------------------------------ | |
(declare *connection*) | |
(defmacro with-redis | |
([host func] | |
`(binding [*connection* (Jedis. ~host)] | |
(try | |
(~@func) | |
(finally | |
(.disconnect *connection*)))))) |
View gist:911384
(defn it-works [] | |
(binding [*connection* "hello, world"] | |
(prn *connection*))) | |
(defn it-works-not [] | |
(binding [*connection* "hello, world"] | |
(map | |
(fn [_] (prn user/*connection*)) | |
[1 2]))) |
View gist:911386
(declare *connection*) | |
(defn it-works [] | |
(binding [*connection* "hello, world"] | |
(prn *connection*))) | |
(defn it-works-now [] | |
(binding [*connection* "hello, world"] | |
(map | |
(bound-fn [_] (prn *connection*)) |
OlderNewer