This gist is a collection of my rough notes from Strange Loop 2012.
(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" |
;; | |
;; 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 |
; Invoke a macro like a function - if you dare. | |
; ______ | |
; .-" "-. | |
; / \ | |
; _ | | _ | |
; ( \ |, .-. .-. ,| / ) | |
; > "=._ | )(__/ \__)( | _.=" < | |
; (_/"=._"=._ |/ /\ \| _.="_.="\_) | |
; "=._ (_ ^^ _)"_.=" | |
; "=\__|IIIIII|__/=" |
(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 [] |
# 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. |
(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 |
;; 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))))) |
(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)))) |
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):