This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns winston.hooks) | |
(defn call-hooks [hooks args] | |
(doseq [h @hooks] | |
(apply (second h) args))) | |
(defmacro defhook | |
"defines an empty function, used to attach hooks to. All attached hooks must have the same signature" | |
[name signature] | |
`(let [hooks# (atom [])] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(let [pairs (for [i myseq | |
j myseq]] | |
(loop [pairs pairs] | |
(let [[a b] (first pairs) | |
(if (pred a b) | |
(recur (remove #(= %2 b) pairs)) | |
(recur (rest pairs)))) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(with-ns 'clojure.core | |
(defn require-short [ns] | |
(let [[whole base name] (re-find #"(.+)\.(.+)" (str ns))] | |
(require [(symbol whole) :as (symbol name)] :verbose)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn update-in-many | |
"like update-in, but can call f on multiple values. If keyseq contains :*, will recurse on every item in the 'current' value. Returns the updated structure" | |
[ds [k & ks] f & args] | |
(if (= k :*) | |
(if ks | |
(map-same (fn [x] (apply update-in-many x ks f args)) ds) | |
(map-same f ds)) | |
(if ks | |
(assoc ds k (apply update-in-many (get ds k) ks f args)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns winston.s3 | |
(:require [org.jclouds.blobstore :as blob])) | |
(def account [{:service :s3 :account redacted :key redacted}]) | |
(def blobstore (blob/blobstore "s3" (:account account) (:key account))) | |
user=> (require 'winston.s3) | |
java.lang.RuntimeException: error instantiating org.jclouds.aws.s3.S3ContextBuilder (s3.clj:6) | |
user=> (.printStackTrace *e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn map-same | |
"like map, but returns a collection of the same type as the first input collection" | |
[f & colls] | |
(let [first-coll (first colls)] | |
(if (list? first-coll) | |
(list* (apply map f colls)) | |
(into (empty first-coll) (apply map f colls))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro decompose-defn-args | |
"interprets args the way defn would, returns a map that can be consumed by defn-map" | |
[& args] | |
`(letfn [(parse-name# [args#] | |
(println "parse-name: args=" args#) | |
(assert (symbol? (first args#))) | |
[(first args#) (rest args#)]) | |
(parse-doc-string# [args#] | |
(if (string? (first args#)) | |
[(first args#) (rest args#)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro splice-test [] | |
(let [foo (gensym)] | |
`(let [~foo (list 1 2 3)] | |
(println ~@foo)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro my-macro [args] | |
`(let [args# ~args ;; to evaluate | |
result (foo args#)] | |
(defn ~@result))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; routes.clj | |
(ns winston.ui.routes | |
(:use [clojure.contrib.except :only (throwf)]) | |
(:require [clojure.contrib.string :as str]))) | |
(defn path-for* [routefn route-args] | |
{:pre [routefn]} | |
(let [path (-> routefn meta ::http-path)] | |
(when (not path) |
OlderNewer