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
> runMain ammonite.repl.Repl | |
[info] Running ammonite.repl.Repl | |
Loading Ammonite Repl... | |
@ load.ivy("com.chuusai" %% "shapeless" % "2.1.0") | |
@ import shapeless._ | |
import shapeless._ | |
@ 1 :: "lol" :: List(1, 2, 3) :: HNil |
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
©2012 Viktor Klang | |
object Actor { | |
import java.util.concurrent.{ConcurrentLinkedQueue, Executor} | |
import java.util.concurrent.atomic.{AtomicBoolean} | |
type Behavior = Any => Effect | |
sealed trait Effect { def getOrElse(old: Behavior): Behavior } | |
case object Stay extends Effect { def getOrElse(old: Behavior): Behavior = old } | |
case class Become(like: Behavior) extends Effect { def getOrElse(old: Behavior): Behavior = like } |
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 sig [x] | |
(:sig (meta (resolve x)))) | |
(defmulti type-of (comp type first list)) | |
(defmethod type-of :function [thing & _] (sig thing)) | |
(defmethod type-of java.util.List [expr & a] | |
(conj (map #(type-of % (first a)) (rest expr)) |
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) |
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
user=> (defn audit-ns [ns] | |
(let [publics (ns-publics ns)] | |
(map key (remove #(let [m (-> % val meta)] (or (:doc m) (:added m))) publics)))) | |
#'user/audit-ns | |
user=> (audit-ns (find-ns 'clojure.core)) | |
(chunked-seq? find-protocol-impl chunk-buffer find-protocol-method EMPTY-NODE await1 -reset-methods *allow-unresolved-vars* proxy-call-with-super | |
munge print-doc *math-context* with-loading-context unquote-splicing chunk-cons chunk-append destructure -cache-protocol-fn print-dup | |
*use-context-classloader* proxy-name print-ctor chunk-rest method-sig print-method hash-combine chunk definterface unquote primitives-classnames | |
rational? chunk-first *source-path* *assert* print-special-doc chunk-next print-simple) |
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
(defn assoc-autoinc [m k] | |
(if (get m k) | |
m | |
(let [v (inc (:last-value (meta m) -1))] | |
(with-meta | |
(assoc m k v) | |
(assoc (meta m) :last-value v))))) | |
(defn get-or-autoinc! [m k] | |
(if-let [v (get @m k)] |
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
(def m (ref {})) | |
(defn str-to-int [m s] | |
(or (@m s) | |
(dosync | |
(alter m assoc s (count @m)) | |
(@m s)))) |
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 process-args [m] | |
(mapcat (fn [[flag value]] [(format "--%s" (name flag)) value]) m)) | |
(defn growl [m] | |
(-> (Runtime/getRuntime) | |
(.exec | |
(into-array | |
String | |
(cons "/usr/local/bin/growlnotify" (process-args m)))))) |
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 ->r | |
"The proposed Rohner arrow" | |
([x] x) | |
([x form] (if (seq? form) | |
(with-meta (replace {'_ x} form) (meta form)) | |
(list form x))) | |
([x form & more] `(->r (->r ~x ~form) ~@more))) | |
(use 'clojure.walk) |
NewerOlder