Skip to content

Instantly share code, notes, and snippets.

Avatar

Hugo Duncan hugoduncan

View GitHub Profile
View support_test.clj
(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 Apr 10, 2014
add profiles in leiningen plugin
View plugin.clj
(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 Apr 9, 2014
pallet use-async api example
View plan.clj
(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 Jan 25, 2014
Criterium - reliable micro-benchmarks
View gist:8611549

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 Jan 25, 2014
Scaling the Infrastructure Continuum
View gist:8611473

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 Jan 12, 2014
An attempt to create a function that process an external representation of different data types
View Test.hs
{-# 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 Aug 30, 2013
Using JDK Watch Service
View gist:6393438
(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 Dec 11, 2015
Examine failed test using ediff to compare actual and expected results
View gist:4662037
(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 Dec 8, 2012
Macros to call a function passed as an argument, where the function may be a macro
View gist:4241814
(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)]
View gist:4169930
(defmacro as
"Binds name to the result of each of the forms. Within each form the previous
binding is available. Returns the final binding."
[name & forms]
`(let [~@(interleave (repeat name) forms)]
~name))
;; (as a
;; 1
;; (+ a 2))
You can’t perform that action at this time.