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 s {:P1 {:queen [{:rate [1.0 0.0]}] | |
:king [{:rate [1.0 0.0] :strate [1.4 0.0]}]} | |
:P2 {:double [] | |
:king [{:rate [1.0 0.0] :strate [1.4 0.0]} {:rate [1.0 0.0]}]} | |
:P3 {:double []}}) | |
(into {} (for [[pc rooms] s | |
[rt rates] rooms | |
r rates | |
:let [st (:strate r)] |
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 field+ [n fields & forms] | |
(let [f (mapv keyword fields) | |
args {:keys fields :as '$doc}] | |
`(hash-map ~n {:fields ~f | |
:fn (let [~'$fields ~f] | |
(fn [~args] ~@forms))}))) | |
(defmacro defmodel [name & forms] | |
`(def ~name (merge {} ~@forms))) |
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
(:import [java.util UUID]) | |
(defn uuid->long [uuid] | |
(if (string? uuid) | |
(try (when-let [x (UUID/fromString uuid)] (uuid->long x)) | |
(catch Exception e nil)) | |
(bit-xor (.getLeastSignificantBits uuid) (.getMostSignificantBits uuid)))) |
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 redefine [binding-map func] | |
(let [old-vals (zipmap (keys binding-map) | |
(map #(.getRawRoot ^clojure.lang.Var %) (keys binding-map))) | |
hits (zipmap (keys binding-map) | |
(map (fn [_] (atom 0)) (keys binding-map))) | |
wrappers (zipmap (keys binding-map) | |
(map #(fn [& args] | |
(let [[f limit] (get binding-map %) | |
h (get hits %) | |
old (get old-vals %)] |
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
;; Validation and transformation handling of input maps. | |
;; Provides input validation, transform, and output validation capabilities | |
;; Allows input values to be marked as required or not by setting required error message | |
(letfn [(check! [value fun-msg-pairs] | |
(when (seq fun-msg-pairs) | |
(doall (for [[f m] (partition 2 fun-msg-pairs)] | |
(when-not (f value) (throw (Exception. 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
#!/bin/bash | |
#=============================================================================== | |
# | |
# FILE: getgeo.sh | |
# | |
# USAGE: ./getgeo.sh | |
# | |
# DESCRIPTION: run the script so that the geodata will be downloaded and inserted into your | |
# database | |
# |
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
;; a function that provides the ability to filter a collection using multiple predicate functions, *lazily*. | |
;; The predicate functions must accept 2 args: | |
;; - the first arg is the accumulating collection (think "reduce"). | |
;; - the second arg is the current item in the collection. | |
;; The return value is a reduced version of the input | |
;; | |
(defn filters [res items & fns] | |
(last (reductions | |
(fn [r i] | |
(if (every? #(% r i) fns) (conj r i) r)) |
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
Could not decrypt credentials from /Users/mmitchell/.lein/credentials.clj.gpg | |
gpg: can't query passphrase in batch mode | |
gpg: decryption failed: secret key not available |
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
foobar:apij mmitchell$ gpg --version | |
gpg (GnuPG) 1.4.12 | |
Copyright (C) 2012 Free Software Foundation, Inc. | |
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> | |
This is free software: you are free to change and redistribute it. | |
There is NO WARRANTY, to the extent permitted by law. | |
foobar:apij mmitchell$ gpg --default-recipient-self -e ~/.lein/credentials.clj | |
You did not specify a user ID. (you may use "-r") |
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
;; [org.clojure/math.combinatorics "0.0.3"] | |
(ns wordhash | |
(:require [clojure.math.combinatorics :as comb] | |
[clojure.string :as string])) | |
(defn words->code [words n] | |
(apply str | |
(take n (keep identity | |
(map (fn [[x y]] |