Skip to content

Instantly share code, notes, and snippets.

View nikolavojicic's full-sized avatar

Nikola Vojičić nikolavojicic

View GitHub Profile
(require '[clojure.spec.alpha :as s])
; ==============================
(s/def ::foo int?)
(s/def ::bar ::foo)
(s/form ::foo) ;=> clojure.core/int?
(s/form ::bar) ;=> clojure.core/int?
@nikolavojicic
nikolavojicic / restAssuredMultipart.java
Last active April 16, 2021 08:11
RestAssured + multipart/form-data
// Nota bene: Add @JsonIgnore to MultiPart fields
public static final ObjectMapper MAPPER = new ObjectMapper()
.configure(FAIL_ON_UNKNOWN_PROPERTIES, false)
.configure(FAIL_ON_EMPTY_BEANS, false);
public static final TypeReference<Map<String, Object>>
MAP_TYPE_REF = new TypeReference<>() {};
public static Map<String, Object> toMap(Object obj) {
@nikolavojicic
nikolavojicic / core-async.md
Last active April 4, 2025 22:51
Clojure APIs
;; Vanilla
(defn is*
[results]
(assert (seq results))
(test/is
(if (some? :failure results)
(do
(println "\nFailed specs:")
(doseq [{:keys [sym failure]} results
@nikolavojicic
nikolavojicic / ->and.clj
Last active March 23, 2022 23:31
Various pure functions
(with-test
(defn ->and
[id-col id-val rec]
(if id-val
(reduce-kv
(fn [ret col val]
(if val
(-> ret
(update 0 #(str % " AND " (name col) " = ?"))
;; https://nakkaya.com/2009/11/18/unit-testing-in-clojure/
(defmacro with-private-fns [[ns fns] & tests]
"Refers private fns from ns and runs tests in context."
`(let ~(reduce #(conj %1 %2 `(ns-resolve '~ns '~%2)) [] fns)
~@tests))
(with-private-fns [org.foo.bar [fn1 fn2]]
(deftest test-fn1..)
(deftest test-fn2..))
@nikolavojicic
nikolavojicic / bulkspace.clj
Last active November 29, 2023 09:59
Various Clojure specs + generators
;; String containing bulk space(s)
(s/def ::bulk-space-string
(s/with-gen
(s/and string? #(re-find #"\t|\n|\r| +" %))
#(gen/fmap
str/join
(gen/vector
(gen/one-of
[(gen/string)
@nikolavojicic
nikolavojicic / leiningen-windows.md
Last active November 13, 2024 14:34
Installing Leiningen on Windows

Leiningen on Windows

Create folder C:\Users\USER\.lein with

  • folder bin with file lein.bat
  • folder self-installs with file leiningen-VERSION-standalone.jar
  • file profiles.clj with content: {:user {:java-cmd "C:\\Program Files\\Java\\jdk-VERSION\\bin\\java.exe"}}

Computer -> Properties -> Advanced system settings -> Environment Variables -> User variables for USER

  • Path -> Edit...
    Variable value: (append with ;) C:\Users\USER\.lein\bin
Debugger entered--Lisp error: (quit)
redisplay_internal\ \(C\ function\)()
Debugger entered--beginning evaluation of function call form:
* (normal-top-level)
Debugger entered--entering a function:
* message("Back to top level")
* normal-top-level()