Skip to content

Instantly share code, notes, and snippets.

@mikeananev
mikeananev / plan-2020-Q1.adoc
Created February 4, 2021 14:36
example asciidoc + plantuml
@startgantt
Project starts the 15th of june 2017
[Angular2 and ReactJS training] as [T1] lasts 13 days and is colored in Lavender/LightBlue
[Alerts web design] as [T2] lasts 13 days and is colored in Lavender/LightBlue and starts 3 days before [T1]'s end
[Alerts web programming] as [T3] lasts 9 days and is colored in Coral/Green and starts the 1st of july 2017
[Alerts web prototype tunning] as [T4] lasts 10 days and is colored in Coral/Green and starts 3 days before [T3]'s end
[Deploy] as [T8] lasts 4 days and starts 3 days after [T4]'s start
[Data Models] as [T5] lasts 5 days and is colored in Coral/Green and starts 2 days before [T4]'s end
@mikeananev
mikeananev / gist:ab4480e04d391621110b74ed83fedb00
Created January 26, 2021 04:53
Simple logger to stderr, including namespace, line and col:
(ns logger)
(defmacro log [& msgs]
(let [m (meta &form)]
`(binding [*out* *err*] ;; or bind to (io/writer log-file)
(println (str (ns-name *ns*) ":"
~(:line m) ":"
~(:column m))
~@msgs))))
(ns bar (:require logger))
@mikeananev
mikeananev / scratch_2.txt
Created January 24, 2021 07:54
Install graalvm on mac
# add to ~/.zshrc
export GRAALVM_HOME="/Library/Java/JavaVirtualMachines/graalvm-ce-java11-21.0.0/Contents/Home/"
# allow to execute graalvm
$ sudo xattr -r -d com.apple.quarantine /Library/Java/JavaVirtualMachines/graalvm-ce-java11-21.0.0
# install native-image tool
$ /Library/Java/JavaVirtualMachines/graalvm-ce-java11-21.0.0/Contents/Home/bin/gu install native-image
# install espresso
@mikeananev
mikeananev / gist:3bdf8e59d32775fc0df7f5398232886a
Created January 16, 2021 19:35
secured remote clojure repl via ssh
# start repl on localhost on remote machine
$ clj "-J-Dclojure.server.repl={:port 5555 :accept clojure.core.server/repl}"
# create ssh tunnel on local machine
$ ssh -L :5555:localhost:5555 remoteuser@remotehost -p 10022 -N -v
# start repl on local machine and connect to remote repl via ssh
$ clj -Sdeps '{:deps {vlaaad/remote-repl {:mvn/version "1.1"}}}'
Downloading: vlaaad/remote-repl/1.1/remote-repl-1.1.pom from clojars
Downloading: vlaaad/remote-repl/1.1/remote-repl-1.1.jar from clojars
@mikeananev
mikeananev / jks_example.clj
Last active April 11, 2024 04:48
Create SSL context from JKS in Clojure. Optionally check CN in certificate from server.
(ns jks-example
(:require [clojure.java.io :as io]
[io.pedestal.log :as log])
(:import (javax.net.ssl SSLContext KeyManagerFactory TrustManager TrustManagerFactory X509TrustManager)
(java.security KeyStore)
(java.security.cert CertificateException X509Certificate)))
(defn cn-check-trust-manager
[^String cn-match-string]
(reify X509TrustManager
@mikeananev
mikeananev / util.clj
Last active February 28, 2025 18:50
debug with clojure tap>
;; order for printing values
(def prn-lock (Object.))
(defmacro dbg*
"Macro sends form to tap> and returns the same form"
[args]
`(let [args# ~args]
(tap> (sorted-map :form (quote ~args) :meta (assoc ~(meta &form) :ns ~(str *ns*)) :ret args#))
args#))
@mikeananev
mikeananev / commons.clj
Created July 17, 2020 05:05
nif-let example
(defmacro nif-let
"Nested if-let. If all bindings are non-nil or true, executes body in the context of
those bindings. If a binding is nil or false, evaluates its `else-expr` form and stops
there. `else-expr` is otherwise not evaluated.
bindings* => binding-form else-expr
Example:
(nif-let [a x :a-is-nil
b y :b-is-nil
@mikeananev
mikeananev / Remote Debug Steps
Last active May 11, 2020 08:31
Cursive Remote Debug mode
1. Go to: Edit Configurations -> + -> (at the end of list) Remote
You should select "Remote", not Clojure REPL
2. Select port for debuger. In this example we use 5005.
3. Run Debug (green bug button).
4. Select Remote repl in configuration. Run it as normal remote repl.
5. Have a nice debugging...
@mikeananev
mikeananev / jvm.clj
Last active March 29, 2023 12:42
Create JVM Heap Dump and Thread Dump using Clojure
;; Copyright (c) Mikhail Ananev, 2020.
;; Red Stars Systems (https://rssys.org).
;;
;; Licensed to the Apache Software Foundation (ASF) under one
;; or more contributor license agreements. See the NOTICE file
;; distributed with this work for additional information
;; regarding copyright ownership. The ASF licenses this file
;; to you under the Apache License, Version 2.0 (the
;; "License"); you may not use this file except in compliance
;; with the License. You may obtain a copy of the License at
@mikeananev
mikeananev / a.clj
Last active April 17, 2020 15:07
until-> macro
(defmacro until->
[pred & [expr & forms]]
(let [g (gensym)
steps (map (fn [step]
`(if (or (~pred ~g) (instance? Throwable ~g))
~g
(try
(-> ~g ~step)
(catch Throwable t#
t#))))