Skip to content

Instantly share code, notes, and snippets.

Avatar

Falko Riemenschneider friemen

View GitHub Profile
View parser-combinators.clj
;; parser combinators
(defn pred->parser
[pred]
(fn [[x & remaining :as input]]
(if (pred x)
[x remaining]
[::invalid input])))
(defn alt
View walktree.clj
;; walk tree-ish vector with Zippers in recursive fashion
(defn walktree
[t]
(letfn [(inner [loc numbers]
(let [node (z/node loc)
numbers (conj numbers (if (sequential? node) (first node) node))
loc (z/edit loc #(if (number? %)
(inc %)
(into [(inc (first %))] (rest %))))]
View gist:b2daf61c3d18a8d76184
user> (def data {:x 110 ::old {:x 100}})
#'user/data
user> (update-in data [::old] merge {:x 110 :z 5})
{:user/old {:z 5, :x 110}, :x 110}
user> (-> data
(update-in [::old] merge {:x 110 :z 5})
(merge {:x 200}))
{:user/old {:z 5, :x 110}, :x 200}
user> (defn update-keep-old
[m k v]
@friemen
friemen / om-tut.core.md
Last active Aug 29, 2015
Om for boring enterprise-style UIs
@friemen
friemen / servint-core.clj
Last active Aug 29, 2015
Web Service Integration based on core.async
View servint-core.clj
(ns servint.core
(:require [org.httpkit.server :as server]
[org.httpkit.client :as client]
[clojure.core.async :as async :refer [go >! <!]]
[compojure.core :refer [defroutes GET]]
[compojure.route :as route]
[compojure.handler :as handler]))
;; A complete webapp that demonstrates how to asynchronously
;; query web services
@friemen
friemen / decision_table.clj
Created Oct 5, 2014
Simple decision table implementation
View decision_table.clj
(ns snippets.decision-table)
;; a naive decision table implementation
(defn decision-table
[predicates actions & values]
{:preds predicates
:actions actions
:rows (partition-all (+ (count predicates) (count actions)) values)})
@friemen
friemen / mapping.clj
Last active Aug 29, 2015
Data transformation
View mapping.clj
(ns snippets.mapping
(:require [clojure.string :as s]))
(defn as-vector
"Returns a vector from x
42 -> [42]
'(1 2 3) -> [1 2 3]
[:foo :bar] -> [:foo :bar]"
[x]
@friemen
friemen / core.clj
Last active Aug 29, 2015
How to access relational DBs
View core.clj
(ns dbgists.core
"Demonstrates working with a DB connection."
(:require [clojure.java.jdbc :as jdbc])
(:import [com.jolbox.bonecp BoneCPDataSource]))
;; to start H2 DB
#_ (do (require '[dbgists.h2 :as h2])
(h2/start-db))
@friemen
friemen / profiles.clj
Last active Apr 3, 2022
My Leiningen profiles.clj
View profiles.clj
;; put this into profiles.clj in ~/.lein folder
{:user {:jvm-opts ^:replace ["-Xmx6G" "-XX:-OmitStackTraceInFastThrow"]
:repl-options {:timeout 180000}
:plugins [[cider/cider-nrepl "0.28.3"]
[refactor-nrepl "3.5.2"]
[lein-ancient "1.0.0-RC3"]
[jonase/eastwood "0.3.14"]
[lein-try "0.4.3"]
[lein-cloverage "1.0.13"]]
:middleware [cider-nrepl.plugin/middleware
@friemen
friemen / helloweb_core.clj
Last active Aug 29, 2015
Starting with a minimalistic webapp.
View helloweb_core.clj
(ns helloweb.core
(:require [org.httpkit.server :as httpkit]
[compojure.handler :as handler]
[ring.util.response :refer [redirect response]]
[ring.util.codec :refer [url-encode]]
[hiccup.page :refer [html5]]
[hiccup.form :as f]
[compojure.core :refer [defroutes GET POST]]
[compojure.route :as route]))