Skip to content

Instantly share code, notes, and snippets.

@hugoduncan
hugoduncan / gist:1998319
Created March 8, 2012 03:07
multi-version dispatched functions
(ns version-dispatch.dispatch-test
(:use
clojure.test
version-dispatch.dispatch))
(def os-hierarchy
(-> (make-hierarchy)
(derive :linux :os)
;; base distibutions
@hugoduncan
hugoduncan / gist:1994274
Created March 7, 2012 16:42
new pallet first steps

Zero to running in five minutes with lein.

Install leiningen

The first thing we need is leiningen, a build tool for clojure. You can downlaod this with your web browser, curl or wget or your favourite download tool. Here we show using curl.

bash$ curl -O http://github.com/technomancy/leiningen/raw/stable/bin/lein
@hugoduncan
hugoduncan / gist:1966770
Created March 3, 2012 15:45
slingshot test helpers
(ns pallet.common.slingshot-test-util
(:use clojure.test))
(defn slingshot-exception-class
"Return the best guess at a slingshot exception class."
[]
(try
(Class/forName "slingshot.Stone")
(catch Exception _
(let [ei (Class/forName "slingshot.ExceptionInfo")]
@hugoduncan
hugoduncan / gist:1961474
Created March 2, 2012 21:16
paredit with {}
(when (and (featurep 'paredit) paredit-mode (>= paredit-version 21))
(define-key clojure-mode-map "{" 'paredit-open-curly)
(define-key clojure-mode-map "}" 'paredit-close-curly))
@hugoduncan
hugoduncan / gist:1934037
Last active October 1, 2015 05:58
.emacs fragment for slime setup with ritz
;;;; slime setup
;;; Setup the hooks for loading customisations
;; one-off slime configuration
(add-hook 'slime-load-hook 'my-slime-setup)
;; per slime connection
(add-hook 'slime-connected-hook 'my-slime-connection-setup)
(add-hook 'slime-clj-connected-hook 'my-slime-clj-connection-setup)
;; per buffer
@hugoduncan
hugoduncan / gist:1919487
Created February 26, 2012 22:58
outline for with-ssh-tunnel
(action/def-clj-action post-to-port
[session port]
;; forward port remote port `port` to local port `local-port`
(execute/with-ssh-tunnel session {local-port port}
(let [endpoint (format "http://localhost:%s%s" local-port url-path)]
(comment do something here)
session)))
@hugoduncan
hugoduncan / gist:1912528
Created February 26, 2012 03:18
composing group and server specs
(def s1 (pallet.core/server-spec :phases {:fred (fn [x] (+ x 1))}))
#'user/s1
(def s2 (pallet.core/server-spec :extends [s1] :phases {:fred (fn [x] (+ x 2))}))
#'user/s2
((-> s2 :phases :fred) 0)
3
(def g (pallet.core/group-spec "g" :extends [s2] :phases {:fred (fn [x] (+ x 4))}))
#'user/g
((-> g :phases :fred) 0)
7
#! /usr/bin/env bash
# Script to build the pallet-1.3 branch
git checkout pallet-1.3
git reset --hard clojure-1.3.0
git merge 1.3-001/update-pom
git merge 1.3-860/add-disable-locals-clearing
git merge 1.3-103/incorrect-error-with-if-let
git merge 1.3-196/fix-docstring-for-file-refs
(defproject lein-ritz "0.1.0-SNAPSHOT"
:description "Lein plugin for launching a ritz server"
:dev-dependencies [[org.clojure/clojure "1.3.0-lc"]])
@hugoduncan
hugoduncan / gist:1870288
Created February 20, 2012 17:51
~/.lein/profiles.clj
{:1.2 {:dependencies [[org.clojure/clojure "1.2.1"]]}
:1.4 {:dependencies [[org.clojure/clojure "1.4.0-beta1"]]}}