Skip to content

Instantly share code, notes, and snippets.

View Kungi's full-sized avatar

Andreas Klein Kungi

  • DemandFlow GmbH
  • Germany
View GitHub Profile
(def data (zip/xml-zip
(xml/parse
(io/input-stream (io/resource "public/img/test.xml")))))
(defn edit-text [loc]
(zip/edit
loc
(fn [l] (assoc-in l [:content] [(zip-xml/text loc)]))))
@Kungi
Kungi / gist:606959e6fd2d00ada1cd
Created March 17, 2016 11:02
cljs-time null error?
clj-demgen.main> (cemerick.piggieback/cljs-repl (cljs.repl.rhino/repl-env))
To quit, type: :cljs/quit
nil
cljs.user> (require '[cljs-time.core :as date])
nil
cljs.user> (require '[cljs-time.format :as date-format])j
nil
cljs.user> (date-format/unparse (date-format/formatters :basic-date-time)
(date/today-at 12 00))
org.mozilla.javascript.EcmaError: TypeError: Cannot call method "call" of null (rhino.clj#41)
@Kungi
Kungi / fn_called.clj
Created February 29, 2016 11:17
fn-called simple mocking
(ns clj-demgen.util.fn-called
(:require [clojure.test :as t :refer [is deftest]]))
(defn fn-called? [f thunk]
(let [called (atom false)]
(with-redefs-fn {f (fn [& args]
(reset! called true))}
thunk)
@called))
@Kungi
Kungi / project.clj
Created January 28, 2016 09:19
figwheel and cider nrepl
(defproject awsome-todo "0.1.0-SNAPSHOT"
:description "FIXME: write this!"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:min-lein-version "2.5.3"
:dependencies [[org.clojure/clojure "1.7.0"]
[org.clojure/clojurescript "1.7.170"]
@Kungi
Kungi / anonymous-gist.clj
Last active December 18, 2015 19:38
add-osx-watcher
(defn add-osx-watcher [f path]
(let [watcher (WatchService/newWatchService)
w (WatchableFile. (clojure.java.io/file path))]
(.register w
watcher
(into-array WatchEvent$Kind [StandardWatchEventKind/ENTRY_CREATE
StandardWatchEventKind/ENTRY_DELETE
StandardWatchEventKind/ENTRY_MODIFY]))
(wait-for-events watcher f)))
@Kungi
Kungi / Curl
Last active November 20, 2015 09:53
curl -X POST -H "Content-type: multipart/form-data; boundary=--ABC" --data-binary @a.txt http://localhost:3000/
Transform
[{:role "SITE-ADMIN" :infocenter_id 2}
{:role "SITE-ADMIN" :infocenter_id 3}]
into
{:2 :SITE-ADMIN
:3 SITE-ADMIN}
(let [form (if (:privacy_policy ic-config)
(update-in form [:validations]
conj [:required [:privacy-policy] "Bitte Stimmen Sie der Datenschutzerklärung zu."])
form)]
(if (:opt_in ic-config)
(update-in form [:validations]
conj [:required [:opt-in] "Bitte stimmen Sie dem Opt-In zu."])
form))
(if foo-2
(update-in (if foo-1
(update-in coll conj foo1-related)
coll)
conj foo2-related))
@Kungi
Kungi / gist:9bb1cdb88df9ea889300
Created February 18, 2015 19:22
wrap-strip-context-path
(defn wrap-strip-context-path
"Strip context-path from all routes"
[handler]
(fn [in-req]
(cond (empty? @config/context-paths)
(handler in-req)
:else
(let [context (first (filter (complement nil?)
(map #(re-find (re-pattern %)
(:uri in-req))