Skip to content

Instantly share code, notes, and snippets.

(ns example
(:use crane.compute)
(:use clojure.contrib.pprint)
(:import org.jclouds.compute.domain.OsFamily)
(:import org.jclouds.compute.options.TemplateOptions)
(:import org.jclouds.logging.log4j.config.Log4JLoggingModule)
(:import org.jclouds.ssh.jsch.config.JschSshClientModule)
(:import org.jclouds.enterprise.config.EnterpriseConfigurationModule))
(defn load-resource-as-byte-array
(defmacro with-line-number
"Record the source line number"
[& body]
`(do (defvar- ln# nil)
(binding [*script-line* (:line (meta (var ln#)))
*script-file* (:file (meta (var ln#)))]
~@body)))
(defscript jre-lib-security [])
(defimpl jre-lib-security :default []
(str @(update-java-alternatives -l "|" cut "-d ' '" -f 3 "|" head -1)
"/jre/lib/security/"))
(defn security-file
"Installs JCE policy jars (string paths, please) in the remote
JAVA_HOME's lib/security directory, enabling the use of \"unlimited strength\"
crypto implementations. Options are as for remote-file."
[filename & options]
@hugoduncan
hugoduncan / gist:374112
Created April 21, 2010 17:09
runtime string interpolation
(defmacro capture-values
"Capture the values of the specified symbols in a symbol->value map."
[& values]
(into {} (map (fn [s] [ `'~s s]) values)))
(defn <<!
"Interpolate a string given a map of symbol->value"
[f value-map]
(apply str
(map (fn [x] (if (symbol? x)
@hugoduncan
hugoduncan / gist:374473
Created April 21, 2010 22:15
Deploy a warfile to tomcat
;; Example for deploying a war file
(ns tomcat-deploy
(:require
[pallet.crate.tomcat :as tomcat]
[pallet.core :as core]))
(defn deploy-my-file
[]
(tomcat/deploy-local-file "path to warfile" "appname"))
(ns myns.plugin
(:import
[maven.clojure.annotations
Goal RequiresDependencyResolution Parameter]
org.apache.maven.plugin.Mojo))
(deftype
#^{Goal "mygoal"
RequiresDependencyResolution "compile"}
Plugin
(ns repro.repro)
;; define a macro and a function that uses it
(defmacro my-macro
[]
`(println "a"))
(defn do-macro
[]
(my-macro))
(ns pallet.ssh-test
(:import
[org.jclouds.ssh SshClient ExecResponse]
org.jclouds.predicates.SocketOpen
org.jclouds.net.IPSocket
com.google.inject.Module))
;; define an instance or implementation of the following interfaces:
(defn maybe-invoke [f & args]
@hugoduncan
hugoduncan / gist:570249
Created September 8, 2010 15:00
thread-local values
(defmacro thread-local
"Create a thread local, initialised by body. The value can be obtained by
dereferncing the the thread-local with deref/@."
[& body]
`(proxy [java.lang.ThreadLocal clojure.lang.IDeref] []
(~'initialValue
[] ~@body)
(~'deref
[] (.get ~'this))))
;;; org-babel-clojure.el --- org-babel functions for clojure evaluation
;; Copyright (C) 2009 Joel Boehland
;; Author: Joel Boehland
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
;; Version: 0.01
;;; License: