Skip to content

Instantly share code, notes, and snippets.

@mping
mping / lazy_channel.clj
Created November 27, 2020 13:15
lazy channel
(require '[clojure.core.async :as a])
(defn pull-seq
"Returns a (blocking!) lazy sequence read from a channel."
[c]
(lazy-seq
(a/>!! c :ready)
(when-let [v (a/<!! c)]
(cons v (pull-seq c)))))
@mping
mping / sliding_window.clj
Created November 19, 2020 13:36
Sliding window example
(defn- new-window [counter prev ts]
(assoc counter :curr 0 :prev prev :last-ts ts))
(defn- increase-count [counter val ts]
(assoc counter :curr val :last-ts ts))
(defn- inc! [counter]
(swap! counter
(fn [{:keys [prev curr last-ts window-ms window-allow] :as atm}]
@mping
mping / defmulti.clj
Last active May 25, 2020 09:11
Clojure hierarchy with multimethods
(defn dispatch-fn [o]
(println (vals (select-keys o [:type :entity])))
[(or (get o :type) ::any)
(or (get o :entity) ::any)])
(def hiera (atom (-> (make-hierarchy)
(derive :string ::any)
(derive :object ::any))))

Kubernetes the Exoscale way

Prerequisites

  • exo CLI
  • cs
  • jq

Creating the infrastructure

Private network

@mping
mping / columns.md
Last active February 14, 2020 10:54
Markdown columns side by side

Document Title

The usual Markdown Cheatsheet does not cover some of the more advanced Markdown tricks, but here is one. You can include verbatim HTML in your Markdown document. This is particularly useful for tables. Check this out:

Version 1Version 2
@mping
mping / test.js
Last active May 13, 2019 21:25
geojson > svg through d3
const json = {
"routes": [{
"legs": [{
"summary": "Avenida Infante Dom Henrique, Autoestrada do Norte",
"weight": 11481.1,
"duration": 10976.2,
"steps": [{
"intersections": [{
"out": 0,
"entry": [true],
@mping
mping / capslock_ijkl_fn.json
Last active January 18, 2019 13:27
karabiner://karabiner/assets/complex_modifications/import?url=file:/Users/mping/Devel/workspace/capslock_ijkl_fn.json
{
"title": "Caps Lock (Fn) + IJKL",
"rules": [
{ "description": "Caps Lock to fn",
"manipulators": [{"type": "basic", "from": {"key_code": "caps_lock", "modifiers": {"optional": ["any"]}}, "to": [{"key_code": "fn"}]}] },
{ "description": "Fn + I/J/K/L to Arrow Keys",
"manipulators": [{"type": "basic", "from": {"key_code": "i", "modifiers": {"mandatory": ["fn"], "optional": ["any"]}}, "to": [{"key_code": "up_arrow"}] },
{"type": "basic", "from": {"key_code": "j", "modifiers": {"mandatory": ["fn"], "optional": ["any"]}}, "to": [{"key_code": "left_arrow"}]},
{"type": "basic", "from": {"key_code": "k", "modifiers": {"mandatory": ["fn"], "optional": ["any"]}}, "to": [{"key_code": "down_arrow"}]},
{"type": "basic", "from": {"key_code": "l", "modifiers": {"mandatory": ["fn"], "optional": ["any"]}}, "to": [{"key_code": "right_arrow"}]}] },
@mping
mping / partition-while.clj
Created December 10, 2018 13:43
partition-while
(defn partition-while
"Given a coll, partition the coll whenever `(f a b)` returns `false`.
Example: `(partition-when #(<= 0 (Math/abs (- %1 %2)) 1) [1 2 3 5 6 8 10 10])
returns `[[1 2 3] [5 6] [8] [10 10]]`
"
([f coll] (partition-while f coll [] []))
([f [_ & t :as c] result intermediate]
(let [[a b & _] c]
(cond
(nil? a) result
@mping
mping / CljKeyStore.clj
Created December 3, 2018 21:13
Kafka props in clojure
(ns com.heroku.sdk.CljKeyStore
"Dynamically generated class to allow creating custom key stores by directly passing the certs and keys
instead of relying on env vars"
(:gen-class
:name com.heroku.sdk.CljKeyStore
:extends com.heroku.sdk.EnvKeyStore
:methods [#^{:static true} [fromTrustWithRandomPassword [String] com.heroku.sdk.EnvKeyStore]
#^{:static true} [fromKeyAndCertWithRandomPassword [String String] com.heroku.sdk.EnvKeyStore]]
:constructors {[String String] [String String],
[String String String] [String String String]}))
@mping
mping / 00_notes.md
Created September 22, 2018 18:34 — forked from Deraen/00_notes.md
Compojure-api and Buddy
  • (:identity req) is auth backend independent way to access user data
  • login and logout implementation depends on auth backend
  • :current-user doesn't imply that authentication is required, route should also have :auth-rules if authentication is required