Skip to content

Instantly share code, notes, and snippets.

@hugoduncan
hugoduncan / gist:2912990
Created June 11, 2012 21:56
fedora 14 generated kickstart file
# Kickstart file automatically generated by anaconda.
#version=DEVEL
install
cdrom
lang en_US.UTF-8
keyboard us
network --onboot no --device eth0 --noipv4 --noipv6 --hostname fedora14
timezone --utc America/New_York
rootpw --iscrypted $6$00UCp3lRIthvUZAl$VbwspY.v3TrfOfZ94VIAVobElrkB.txQHKo0m9j9SDm88qDUgWbQo59OxleWZ1b8eq7aH5QCkjdJSZuTSpYqr/
@hugoduncan
hugoduncan / gist:2844691
Created May 31, 2012 16:48
Trying to parse nested lists with cgrand's parsley
;; parse nested, punctuated lists in parsley
(def nested-list-parser
(parser
:expr #{:e1 [:expr "," :e1]}
:e1 #{"e" [:e1 ";" "e"]}))
(clojure.pprint/pprint (nested-list-parser "e;e;e,e;e"))
@hugoduncan
hugoduncan / gist:2839891
Created May 31, 2012 00:41
OAuth with friend and oauthentic
(ns myapp.authenticate.oauth
"OAuth authentication"
(:require
[cheshire.core :as json]
[clj-http.client :as http]
[clojure.string :as string]
[clojure.tools.logging :as logging])
(:use
[oauthentic.core :only [build-authorization-url fetch-token]]
[ring.util.response :only [redirect]]
@hugoduncan
hugoduncan / gist:2769243
Created May 22, 2012 13:57
maven settings.xml for building pallet
<settings>
<profiles>
<profile>
<id>clojure-dev</id>
<pluginRepositories>
<pluginRepository>
<id>mulli.nu</id>
<url>http://mulli.nu/maven</url>
<layout>default</layout>
<snapshots>
@hugoduncan
hugoduncan / gist:2510826
Created April 27, 2012 17:01
ClassCastException in pomegranate
Caused by: java.lang.ClassCastException: org.apache.maven.repository.internal.MavenRepositorySystemSession cannot be cast to org.sonatype.aether.util.DefaultRepositorySystemSession
at cemerick.pomegranate.aether$repository_session.invoke(aether.clj:123)
at cemerick.pomegranate.aether$resolve_dependencies.doInvoke(aether.clj:399)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invoke(core.clj:600)
at cemerick.pomegranate$add_dependencies.doInvoke(pomegranate.clj:102)
at clojure.lang.RestFn.invoke(RestFn.java:1096)
at leiningen.core.classpath$get_dependencies.doInvoke(classpath.clj:107)
at clojure.lang.RestFn.applyTo(RestFn.java:142)
at clojure.core$apply.invoke(core.clj:604)
@hugoduncan
hugoduncan / gist:2468613
Created April 23, 2012 03:10
Test for a reachable port
(defn port-reachable?
([ip port timeout]
(let [socket (doto (java.net.Socket.)
(.setReuseAddress false)
(.setSoLinger false 1)
(.setSoTimeout timeout))]
(try
(.connect socket (java.net.InetSocketAddress. ip port))
true
(catch java.io.IOException _)
@hugoduncan
hugoduncan / gist:2003077
Created March 8, 2012 20:00
install-deb action
(action/def-bash-action install-deb
"Install a deb file. Source options are as for remote file."
[request deb-name & {:as options}]
(stevedore/do-script
(apply remote-file* request deb-name (apply concat options))
(stevedore/checked-script
(format "Install deb %s" deb-name)
(dpkg -i --skip-same-version ~deb-name))))
@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")]