Skip to content

Instantly share code, notes, and snippets.

View mccraigmccraig's full-sized avatar

mccraigmccraig of the clan mccraig mccraigmccraig

View GitHub Profile

Keybase proof

I hereby claim:

  • I am mccraigmccraig on github.
  • I am mccraigmccraig (https://keybase.io/mccraigmccraig) on keybase.
  • I have a public key whose fingerprint is 1200 ACF5 97F1 53C3 7246 5B5A 172A 5DB8 BFD8 9F3F

To claim this, I am signing this object:

@mccraigmccraig
mccraigmccraig / lastcall-method
Created June 9, 2015 09:34
last-call wins for core.async API clients
;;;;;;;;;;;;;;;;;;;;; macro
(ns clustermap.lastcall-method
(:require [clojure.tools.macro :refer [name-with-attributes]]))
(defn ^:private lastcall-method*
"defines an API method with last-call-wins semantics : returns a
channel of a single-value, the response
only responses corresponding to the the last
@mccraigmccraig
mccraigmccraig / yoyo-with-cont-m-cats.clj
Last active August 29, 2015 14:24
yoyo with cont-m
(require '[cats.core :refer :all])
(require '[cats.monad.continuation :as cont])
(defn with-something
[config]
(cont/continuation
(fn [cc]
(prn (str "setting up something: " (pr-str config)))
(let [r (cc :something)]
(prn "tearing down something")
@mccraigmccraig
mccraigmccraig / yoyo-algo-monads.clj
Last active August 29, 2015 14:24
yoyo with cont-m from algo.monads
(require '[clojure.algo.monads :refer :all])
(defn with-something
[config]
(fn [cc]
(prn (str "setting up something: " (pr-str config)))
(let [r (cc :something)]
(prn "tearing down something")
r)))
(ns clustermap.application
(:require [parenjin.application :as app]
[parenjin.job :as job]
[clustermap.config :as conf]
[clustermap.connectors :as conn]
[clomponents.control :as clomp]))
(def app-spec {:enjins {
:ping {:model :clustermap.datasets.ping.dataset/dataset}
(ns delaymap
(:require [schema.core :as s])
(:import [clojure.lang MapEntry]))
(defn ^:private deref-seq [underlying]
(when-first [[k v] underlying]
(lazy-seq (cons (MapEntry. k @v) (deref-seq (rest underlying))))))
(defprotocol IValidatable
(schema [this])
@mccraigmccraig
mccraigmccraig / gist:128577
Created June 12, 2009 11:00
clojure/java : make java private data public
(def state-field (first (filter #(= "state" (.getName %)) (seq (.getDeclaredFields (java.lang.Class/forName "clojure.lang.Agent"))))))
(.setAccessible state-field true)
(def foo (agent 1))
(.set state-field foo 5)
user=> @foo
5
@mccraigmccraig
mccraigmccraig / gist:138776
Created July 1, 2009 13:27
ruby : array structure equality
class Array
class Val
attr_reader :i
def initialize(i)
@i = i
end
def eql?(other)
other.is_a?(Val) && @i==other.i
@mccraigmccraig
mccraigmccraig / gist:139453
Created July 2, 2009 13:01
ruby : dynamically bound values
# evil Ruby dynamic variables
class DynamicValue
attr_read :default_value
def initialize(val)
@default_value = val
end
def method_missing(name, *args)
@mccraigmccraig
mccraigmccraig / common_followers
Created July 3, 2009 12:23 — forked from DRMacIver/common_followers
ruby : find twitter common followers
#!/usr/bin/env ruby
# Trivial little twitter script
# Pass it a list of names as command line arguments
# and it will return a list of all people who follow everyone in the
# list.
# A person is implicitly assumed to follow themselves, so if foo follows
# bar and bar follows foo then common_followers foo bar would include
# both foo and bar in the output, but if bar did not follow foo it
# would include neither.