Skip to content

Instantly share code, notes, and snippets.

View daveray's full-sized avatar

Dave Ray daveray

View GitHub Profile
@laurentpetit
laurentpetit / nrepl_events.clj
Created December 19, 2013 14:26
Adds 2 launch event listeners that spit the created nrepl server port into ~/.nrepl and <project-dir>/.nrepl files
(ns nrepl-events
(:require [ccw.core.launch :as l]
[clojure.java.io :as io]
[ccw.eclipse :as e]))
(defn spit-globally
"global ~/.nrepl file"
[{:keys [event-type port project]}]
(when (= :creation event-type)
(spit (io/file (java.lang.System/getProperty "user.home") ".nrepl")
@aphyr
aphyr / -log
Last active December 22, 2015 02:19
In http://www.datastax.com/dev/blog/row-level-isolation and
http://www.datastax.com/dev/blog/atomic-batches-in-cassandra-1-2, Datastax
asserts that batch updates to multiple cells in a single row are
guaranteed to be isolated from concurrent batches:
"Cassandra 1.1 guarantees that if you update both the login and password in the
same update (for the same row key) then no concurrent read may see only a
partial update."
"...the guarantee is that the new login cannot be persisted without the new
@benjchristensen
benjchristensen / DATA-CONTRACTS.md
Last active December 20, 2015 02:29
Consumer Driven Contracts: notes, links, quotes and thoughts

Problem Statement

A service layer (Java API in this case) is backed by dozens of services (over the network in an SOA) and used by dozens of clients, each using different subsets of the overall API. In our case all client interaction happens within a single JVM so we can know which clients are accessing what services, fields and keys (versus a RESTful API over HTTP where this would be unknown).

Principally the API is functionality focused rather than system focused. A client should request data to serve a given use case and not need to concern themselves with the underlying implementation details of what backend system the data is coming from.

Today this is achieved through static typing and Java object modeling. Types from underlying services are decoupled from clients so that backend systems can change their implementations without impacting clients.

This means (assuming Java language environment):

@mtnygard
mtnygard / query.clj
Created February 8, 2013 22:19
Use Datomic queries as a source for RxJava pipes.
(ns rxjava-datomic.query
(:require [datomic.api :as d])
(:use [clojure.repl :only [pst]])
(:import [rx Observable]
datomic.Peer))
(defn query [qry & inputs]
(Observable/toObservable
(Peer/q qry (object-array inputs))))
@jasonrudolph
jasonrudolph / 00-about.md
Created September 21, 2012 18:42
Rough Notes from Strange Loop 2012
@Chouser
Chouser / gist:3687532
Created September 9, 2012 21:52
Lazy seq as event subscription mechanism
;; Here is a spike of a lightweight in-process pubsub mechanism that allows pure ;; functional consumers, both blocking and asynchronous.
;; This defines the event stream, in this case just a series of numbers,
;; a new one produced each second
(defn timer []
(lazy-seq
(do
(Thread/sleep 1000)
(cons (System/nanoTime) (timer)))))
@hiredman
hiredman / scratch.clj
Created August 9, 2012 20:01
pomegranate-injector.clj
(let [pom-uber-jar
(str "http://thelibraryofcongress.s3.amazonaws.com/"
"pomegranate-0.0.13-SNAPSHOT-jar-with-dependencies.jar")
cl (java.net.URLClassLoader. (into-array [(java.net.URL. pom-uber-jar)]))
cx (.getContextClassLoader (Thread/currentThread))]
(push-thread-bindings {clojure.lang.Compiler/LOADER cl})
(.setContextClassLoader (Thread/currentThread) cl)
(try
(require '[cemerick.pomegranate :as pom])
(finally
@Johnicholas
Johnicholas / shift-reset.soar
Created April 7, 2012 19:08
Delimited Continuations in Lambda Calculus in Soar
# This is a lambda-calculus interpreter with shift and reset,
# an implementation of BRICS-RS-3-41 "An Operational Foundation for Delimited Continuations",
# by Biernacka, Biernacki, and Danvy.
#
# Mistakes, misunderstandings and terrible un-idiomatic Soar style by Johnicholas
#
#
# This is the grammar:
#
# A term can have a single outgoing ^reset leading to a reset.
@Chouser
Chouser / gmail.clj
Created March 24, 2012 18:18
Send email via gmail from Clojure
(ns foo
(:import (java.util Properties)
javax.mail.internet.MimeMessage
(javax.mail.internet MimeMessage InternetAddress)
(javax.mail Session Transport Authenticator
PasswordAuthentication Message$RecipientType)))
(defn send-gmail [{:keys [from to subject text user password]}]
(let [auth (proxy [Authenticator] []
(getPasswordAuthentication []
@alandipert
alandipert / macrofn.clj
Created March 15, 2012 19:44
invoke a macro like a function
; Invoke a macro like a function - if you dare.
; ______
; .-" "-.
; / \
; _ | | _
; ( \ |, .-. .-. ,| / )
; > "=._ | )(__/ \__)( | _.=" <
; (_/"=._"=._ |/ /\ \| _.="_.="\_)
; "=._ (_ ^^ _)"_.="
; "=\__|IIIIII|__/="