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 pretty-xml | |
(:import (java.io ByteArrayInputStream StringWriter) | |
(javax.xml.parsers DocumentBuilderFactory) | |
(javax.xml.transform TransformerFactory OutputKeys) | |
(javax.xml.transform.dom DOMSource) | |
(javax.xml.transform.stream StreamResult) | |
(javax.xml.xpath XPathFactory XPathConstants) | |
(org.w3c.dom Document NodeList Node) | |
(org.xml.sax InputSource)) |
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 bowling) | |
(def empty-state | |
{:frames [] | |
:current-frame [] | |
:score 0 | |
:strike-counter 0 | |
:spare-counter 0}) | |
(defn dec-zero [n] |
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 gql-ns | |
(:require | |
[clojure.string :as str])) | |
(defn valid-gql-key? | |
"Checks that a key has at most a single namespace separator." | |
[k] | |
(-> (name k) | |
(str/replace #"^__" "") | |
(str/replace #"__$" "") |
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 macro for debugging stuff that happens inside a let | |
;; just change let to lets and all the bindings will be defined | |
;; as globals instead of locals and the body will be ignored. | |
(require '[madstap.comfy :refer [defs]]) | |
(require '[integrant.core :as ig]) | |
(defmacro lets | |
{:style/indent 1} | |
[bindings & _body] | |
`(do ~@(map (fn [[b exp]] `(madstap.comfy/defs ~b ~exp)) (partition 2 bindings)))) |
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
;; error in process sentinel: nrepl-server-sentinel: Could not start nREPL server: Retrieving refactor-nrepl/refactor-nrepl/2.4.0-SNAPSHOT/refactor-nrepl-2.4.0-20180410.152833-6.jar from clojars | |
;; Could not transfer artifact refactor-nrepl:refactor-nrepl:jar:2.4.0-20180410.152833-6 from/to clojars (https://repo.clojars.org/): GET request of: refactor-nrepl/refactor-nrepl/2.4.0-SNAPSHOT/refactor-nrepl-2.4.0-20180410.152833-6.jar from clojars failed | |
;; This could be due to a typo in :dependencies, file system permissions, or network issues. | |
;; If you are behind a proxy, try setting the 'http_proxy' environment variable. | |
;; Bozhidar: | |
;; Seems like some problem related to fetching the dep. | |
;; I guess you can just disable `clj-refactor`’s injection of dependencies. | |
(setq cljr-inject-dependencies-at-jack-in nil) |
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 bank.account | |
(:require | |
[clojure.spec.alpha :as s])) | |
(s/def ::fname string?) | |
(s/def ::lname string?) | |
(s/def ::cents integer?) | |
;; It's currently valid to have a negative balance. | |
;; Could alternatively do something like (s/and ::cents (complement neg?)) |
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 car | |
"The sixties are back!" | |
(:require | |
[clojure.math.combinatorics :as combo])) | |
(defn ad-combos [n] | |
(distinct | |
(mapcat (fn [i] | |
(combo/selections '[a d] i)) | |
(range 1 (inc n))))) |
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
;; Reducing function: | |
;; A function that takes an accumulator and an item and returns a new accumulator. | |
;; Like the function you would pass to reduce. | |
;; Transducer: | |
;; A function that takes a reducing function and | |
;; returns a new reducing function. | |
;; Slightly simplified, this is the meat of map with arity one. |
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 when-letp | |
{:style/indent 2} | |
[pred bindings & body] | |
(if (empty? bindings) | |
`(do ~@body) | |
(let [[[binding expr] more] (split-at 2 bindings)] | |
`(let [temp# ~expr | |
pred# ~pred] | |
(when (pred# temp#) | |
(let [~binding temp#] |
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 foo.bool-diff | |
"Have you ever wondered \"Can I write this boolean expression like that instead?\" | |
Well, I have. So I wrote this to verify whether I'm right. | |
Say I've got the expression: | |
(and (not (foo? x)) | |
(not (bar? y))) | |
I might think \"Isn't that the same as negating an or?\" |
NewerOlder