Skip to content

Instantly share code, notes, and snippets.

@tcoupland
tcoupland / WhoNeedsVisitor.groovy
Created November 11, 2010 21:40
WhoNeedsVisitor
SpaceShip ship = new BigSpaceShip();
LauncherSystem launcher = new LauncherSystem();
launcher.launch(ship);
class LauncherSystem{
public void launch(SpaceShip ship){
Launcher launcher = new Launcher();
launcher.launch(ship);
}
public class NeedVistorPattern {
public static void main(String[] args){
SpaceShip ship = new BigSpaceShip();
SpaceShipLauncher launcher = new SpaceShipLauncher();
launcher.launch(ship);
}
private static class SpaceShipLauncher{
@tcoupland
tcoupland / compujureHandler1.clj
Created April 28, 2012 10:53
Simple compojure handler
(ns compojur-learning.core
(:use compojure.core))
(defroutes handler
(GET "/" [] (println "middle") {:status 200}))
(def app (-> handler))
@tcoupland
tcoupland / compojureHandler2.clj
Created April 28, 2012 11:02
Simple compojure handler with logging middleware
(ns compojur-learning.core
(:use compojure.core))
(defroutes handler
(GET "/" [] (println "middle") {:status 200}))
(defn logging [chain] (fn [req] (
(println "before")
(chain req)
(println "after"))))
@tcoupland
tcoupland / gist:2518012
Created April 28, 2012 11:05
Simple compojure handler with logging middleware stacktrace
before
Exception: java.lang.NullPointerException: null
core.clj:10 compojur-learning.core/logging[fn]
Var.java:401 clojure.lang.Var.invoke
@tcoupland
tcoupland / compojureHandler4.clj
Created April 28, 2012 11:36
Simple compojure handler before msg only
(defn logging [chain] (fn [req]
(println "before")
(chain req)))
@tcoupland
tcoupland / compojureHandler5.clj
Created April 28, 2012 11:40
Simple compojure handler try finally
(defn logging [chain] (fn [req]
(println "before")
(try (chain req) (finally (println "after")))
))
@tcoupland
tcoupland / dijkstra-core.clj
Created May 29, 2012 22:13
Brisfunctional dojo code implementing dijkstra's algorithm 29-05-2012
(ns dijkstra.core)
(def edges {:A {:F 14 :C 9 :B 7}
:B {:A 7 :C 10 :D 15}
:C {:A 9 :B 10 :D 11 :F 2}
:D {:B 15 :C 11 :E 6}
:E {:D 6 :F 9}
:F {:A 14 :C 2 :E 9}})
(def inf Integer/MAX_VALUE)
@tcoupland
tcoupland / QuickSort_codeGolf.clj
Created June 13, 2012 16:39
Quicksort in Code Golf
(defn f [s p v] (filter #(s % p) v))
(defn s [w]
(if-let [p (first w)]
(if-let [v (rest w)]
(concat (s (f < p v)) [p] (s (f >= p v)))
p)
()
))
@tcoupland
tcoupland / bots.clj
Last active December 19, 2015 00:19 — forked from cgrand/bots.clj
;; tc
(ns tron.bots
(:require [tron.core :as tron]))
;;bot func: tc
(defn empty-look
"A mock look function which just checks for the arena
boundaries."