Skip to content

Instantly share code, notes, and snippets.

View tolitius's full-sized avatar

Anatoly tolitius

View GitHub Profile
@tolitius
tolitius / edn-to-gregor.clj
Last active July 28, 2017 09:23
edn to gregor (kafka) conf
(require '[clojure.string :as s]
'[gregor.core :as gregor])
(defn to-prop [k]
(-> k name (s/replace #"-" ".")))
(defn to-props
"ranames keys by converting them to strings and substituting dashes with periods
only does top level keys"
[conf]
@tolitius
tolitius / functions-vs-components.md
Last active August 9, 2016 02:46
Meetup @ Software GR

abstract

Clojure is powerful, simple and fun. Depending on how the application state is managed, these 3 superpowers can either stay, go somewhat, or go completely. Apps we build for clients are quite different from tools and libraries on github; they are full of state. While there are frameworks that allow you to join the "application context party", this talk will take a very different approach to manage and reload Clojure and ClojureScript state with the help of a tiny library called "mount".

bio

@tolitius
tolitius / undefaulting-prefix.java
Created July 7, 2016 13:34
log4j 2.0: changing DEFAULT_PREFIX
// Changing "DEFAULT_PREFIX": https://logging.apache.org/log4j/2.0/log4j-core/apidocs/src-html/org/apache/logging/log4j/core/config/ConfigurationFactory.html#line.108
Field prefix = ConfigurationFactory.class.getField( "DEFAULT_PREFIX" )
prefix.setAccessible( true );
Field mods = Field.class.getDeclaredField( "modifiers" );
mods.setAccessible( true );
mods.setInt( prefix, prefix.getModifiers() & ~Modifier.FINAL );
field.set( null, "logger-config" );
@tolitius
tolitius / dont-stop-me-now.clj
Last active June 16, 2016 01:30
stoppable go-loop with channel internal exception handling
(defn throw-err [e]
(when (instance? Throwable e)
(throw e))
e)
(defn listen [f ch]
(let [running? (atom true)
stop-ch (chan)]
(go-loop []
(when @running?
@tolitius
tolitius / 1. kafka-thing.clj
Created April 30, 2016 21:24
mount: accessing states within jars
;; [tolitius:/tmp/ido]$ cat src/ido/core.clj
(ns ido.core
(:require [mount.core :refer [defstate]]))
(defstate kafka :start 42
:stop 0)
;; [tolitius:/tmp/ido]$
;; [tolitius:/tmp/ido]$ lein install
;; Created /private/tmp/ido/target/ido-0.1.0-SNAPSHOT.jar
@tolitius
tolitius / derefable-state.clj
Last active April 5, 2016 20:06
mount: catching not started
(defn deref-state [name]
(let [{:keys [status inst] :as state} (@meta-state name)]
(when-not (:started status)
(up name state (atom #{})))
@inst))
(defn throw-not-started [name]
(throw-runtime (str "can't use \"" name "\" state, since it was not started. "
"this would usually happen if you forget to start it explicitly "
"or to \":require\" this state or its namespace, "
@tolitius
tolitius / 1. uber-boot.clj
Last active February 5, 2016 17:01
ubermain + push
(deftask build []
(comp
(pom) ;; <<< names the file correctly + no need for --file in "(ubermain)" or "(push)"
(ubermain)
(sift :include #{#"stream-on.*.jar$"})
(target)))
(deftask deploy-snapshot []
(comp
(build)
(defn connect [db-spec]
(jdbc/get-connection db-spec))
(defn disconnect [conn]
(.close conn))

Mystique Experiment

Why

Playing around with a "system" concept, where a simple view of all the states can be created by (mount/system), and used.

This could probably be used for testing, although a simple :require does not seem all that frightening in tests.

Mutable, Whaaa!?