Skip to content

Instantly share code, notes, and snippets.

$ lein2 modules test
------------------------------------------------------------------------
Module build order:
pallet-test-env-parent
lein-test-env
pallet-test-env
------------------------------------------------------------------------
Building pallet-test-env-parent 0.1.2-SNAPSHOT (default)
------------------------------------------------------------------------
Using JLine for console I/O; install rlwrap for optimum experience.
(ns pallet.crate.maven.support-test
(:require
[clojure.test :refer :all]
[pallet.actions :refer [exec-checked-script exec-script* minimal-packages
package-manager]]
[pallet.api :refer [converge group-spec plan-fn]]
[pallet.build-actions :refer [build-actions build-session]]
[pallet.core.api :refer [phase-errors]]
[pallet.core.session :refer [with-session]]
[pallet.crate :refer [is-64bit?]]
@hugoduncan
hugoduncan / plugin.clj
Created April 10, 2014 12:31
add profiles in leiningen plugin
(ns lein-test-env.plugin)
(def profiles
{:aws {:pallet/test-env {}
:dependencies '[[com.palletops/pallet-aws "0.2.0"]
[ch.qos.logback/logback-classic "1.1.1"]
[org.slf4j/jcl-over-slf4j "1.7.6"]]}})
(defn middleware
"Middleware to add test-env profiles"
@hugoduncan
hugoduncan / plan.clj
Created April 9, 2014 18:34
pallet use-async api example
(ns pallet.api-examples.plan
"Examples of pallet's plan api"
(:refer-clojure :exclude [sync])
(:require
[pallet.actions :refer [exec-script*]]
[pallet.core.executor.ssh :refer [ssh-executor]]
[pallet.plan :refer [execute-plan execute-plans plan-fn]]
[pallet.session :as session :refer [set-user]]
[pallet.user :refer [default-user]]
[pallet.utils.async :refer [sync]]))
@hugoduncan
hugoduncan / gist:8611549
Created January 25, 2014 03:48
Criterium - reliable micro-benchmarks

Criterium - reliable micro-benchmarks

abstract

We’ve all timed a clojure function using clojure’s `time` macro, and then wondered why we don’t get stable results. We’ve seen Rich show off order of magnitude speed differences in new versions of clojure using the time macro. But what happens when you want reliable benchmarks, that can track small changes in timings? `time` falls short.

@hugoduncan
hugoduncan / gist:8611473
Created January 25, 2014 03:38
Scaling the Infrastructure Continuum

Scaling the Infrastructure Continuum

The choices of infrastructure is ever increasing - dedicated servers, VPS, cloud images, virtualisation and containers.

Each of these choices has advantages that suit a particular use case. A single application, when viewed from the development and operation perspective has many use cases however. Local virtualisation makes good sense for development. Ephemeral cloud nodes fit well for testing. Dedicated hardware is good choice for production in constant load environments. An image based solution is great

@hugoduncan
hugoduncan / Test.hs
Created January 12, 2014 15:25
An attempt to create a function that process an external representation of different data types
{-# LANGUAGE ScopedTypeVariables #-}
module Test () where
-- a type class to specify parsing and encoding of a type
-- (in reality I'm using hedn, which is similar to aeson)
class T a where
f :: String -> a
g :: a -> String
@hugoduncan
hugoduncan / gist:6393438
Created August 30, 2013 19:30
Using JDK Watch Service
(ns com.palletops.brick-server.fs-watch
"Watch a filesystem path"
(:require
[clojure.java.io :refer [file]]
[clojure.set :refer [map-invert]]
[clojure.tools.logging :refer [debugf]]
[clojure.string :refer [join]])
(:import
[java.nio.file
ClosedWatchServiceException FileSystems Path StandardWatchEventKinds
@hugoduncan
hugoduncan / gist:4662037
Last active December 11, 2015 21:19
Examine failed test using ediff to compare actual and expected results
(defvar clojure-test-ediff-buffers nil)
(defun clojure-test-ediff-cleanup ()
"A function for ediff-cleanup-hook, to cleanup the temporary ediff buffers"
(mapc #'kill-buffer clojure-test-ediff-buffers))
(defconst re1
"Expected \\(?:.\\|\n\\)*, got (not ([^ ]+ \\(\"\\(?:.\\|\n\\)+\"\\) \\(\"\\(?:.\\|\n\\)+\"\\)))"
"Match predicate on strings test")
(defconst re2
"Expected \\(?:.\\|\n\\)*, got (not ([^ ]+ \\(\\(?:.\\|\n\\)+\\) \\(\\(?:.\\|\n\\)+\\)))"
@hugoduncan
hugoduncan / gist:4241814
Created December 8, 2012 20:37
Macros to call a function passed as an argument, where the function may be a macro
(defmacro mfn*
[[argv] body & args]
(let [[argv] args]
body))
(defmacro mfn
"An macro form which looks like an anonymous function, and can be used to
inline a function call "
[args body & arg-vals]
`(let [~args ~(vec arg-vals)]