Skip to content

Instantly share code, notes, and snippets.

View ejackson's full-sized avatar

Edmund Jackson ejackson

  • UnityAI
  • Nashville, TN
View GitHub Profile
(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)))
(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.
(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
(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
(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))
(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)))
(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
;;------------------------------------------------------------------------------
(declare *connection*)
(defmacro with-redis
([host func]
`(binding [*connection* (Jedis. ~host)]
(try
(~@func)
(finally
(.disconnect *connection*))))))
@ejackson
ejackson / gist:911384
Created April 9, 2011 13:04
binding over map function
(defn it-works []
(binding [*connection* "hello, world"]
(prn *connection*)))
(defn it-works-not []
(binding [*connection* "hello, world"]
(map
(fn [_] (prn user/*connection*))
[1 2])))
@ejackson
ejackson / gist:911386
Created April 9, 2011 13:08
binding over map function
(declare *connection*)
(defn it-works []
(binding [*connection* "hello, world"]
(prn *connection*)))
(defn it-works-now []
(binding [*connection* "hello, world"]
(map
(bound-fn [_] (prn *connection*))