Skip to content

Instantly share code, notes, and snippets.

View daveray's full-sized avatar

Dave Ray daveray

View GitHub Profile
@jramb
jramb / kormatest.clj
Created December 26, 2011 14:07
Playing with Clojure Korma SQL
(ns kormatest.core
(:require [korma.core :as sql])
(:require [korma.db :as db])
(:require [clojure.contrib.sql :as jdbc]))
(def play-con
(db/mysql {:db "playground"
;; :host "localhost" ;; optional?
:port "3406" ;; normal: 3306
:user "root"
@gavq
gavq / midi
Created March 10, 2012 08:15
Clojure for General MIDI
;;
;; General MIDI defines instruments for 128 program numbers
;; http://www.midi.org/techspecs/gm1sound.php
;;
;; javax.sound.midi numbers the instruments from 0 rather than 1, so acoustic-grand-piano is 0.
;;
(def GM
{:acoustic-grand-piano 0
:bright-acoustic-piano 1
@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|__/="
@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 []
@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.
@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
@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)))))
@jasonrudolph
jasonrudolph / 00-about.md
Created September 21, 2012 18:42
Rough Notes from Strange Loop 2012
@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))))
@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):