Skip to content

Instantly share code, notes, and snippets.

View tolitius's full-sized avatar

Anatoly tolitius

View GitHub Profile
@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 / 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 / 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 / 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 / 0. multiple-kafka-consumer-threads.md
Last active April 8, 2023 17:36
event listener with multiple kafka consumer threads

starting multiple kafka consumer threads

  • Example below is based on gregor, but it could use other Kafka bindings.
  • Long CamelCased things come from Java
  • defstate comes from mount
@tolitius
tolitius / 1. cchange.clj
Last active November 1, 2016 18:25
restart on zoo / consul / etc .. config changes
(ns cchange
(:require [mount.core :as mount]))
(defprotocol ChangeListener
(add-watcher [this ks watcher])
(on-change [this k]))
(deftype RestartListener [watchers]
ChangeListener

repl time

$ boot repl

boot.user=> (require :reload '[pipeline :refer [engine]]
                             '[mount.core :as mount])
"|| mounting... #'pipeline/engine"

starting it

@tolitius
tolitius / spec-workshop-feedback.md
Last active April 8, 2018 19:51
clojure conj 2016: clojure.spec workshop feedback

While I have not used spec for work before, I followed the hype for several months, and really like the idea.

Overall this workshop, while was the first one of its kind, really "moved" me to actually apply spec to my current Clojure work. In both areas: open source and products for customers.

I believe a "needs improvement" feedback is the most useful one, so don't take it as something I did not like, but rather something others can benefit from in the future attending this workshop.

All that follows is definitely connected to the way I learn things, perceive and digest the information.

@tolitius
tolitius / 1. pcheck.clj
Last active December 12, 2016 17:33
rules via lua's pcall
(defn pcall [f & args]
(try [true (apply f args)]
(catch Exception e
[false e])))
(defn matched? [[status value]]
(if status
(when (and value
(not= value :nginx-null))
value)
@tolitius
tolitius / with-mount.md
Created December 29, 2016 04:47
starting / stopping an http server

this is the snippet that manages the http server lifecycle:

(defstate web-server :start (start-www config)
                     :stop (.stop web-server))

Trying it