Skip to content

Instantly share code, notes, and snippets.

Avatar

Maxim Penzin maxp

View GitHub Profile
@maxp
maxp / remove-nils.clj
Last active Mar 10, 2021
remove nil values from map
View remove-nils.clj
(let [data {:a :b :c nil :d 1}]
(->> data
(remove (comp nil? second))
(into {})))
;; {:a :b, :d 1}
View postgresql performance: bigint vs varchar
-- postgresql 13 default
-- ubuntu, core i5, ssd
create table t1 (i bigint, c varchar(20), t text);
create table t2 (i bigint, c varchar(20), t text);
insert into t1 (i,c,t)
select random() * 1000000, '', '12345678912345678912345678900'
from generate_series(0,1000000);
@maxp
maxp / bmk.core.clj
Created Aug 23, 2020
babashka maker library
View bmk.core.clj
(ns bmk.core
(:import
[java.time ZonedDateTime]
[java.time.format DateTimeFormatter])
(:require
[clojure.string :refer [split]]
[clojure.java.shell :refer [sh]]))
;=
@maxp
maxp / bmk.clj
Created Aug 23, 2020
babashka based maker
View bmk.clj
#!/usr/bin/env bb
(require 'babashka.classpath)
(babashka.classpath/add-classpath "./tools")
(ns bmk.main
(:require
[bmk.core :refer [print-lines cmd sh-c]]))
;=
View clojure-16068307781756836851.edn
{:clojure.main/message
"Execution error (ClassCastException) at unilog.config/start-logging! (config.clj:354).\nclass org.slf4j.impl.SimpleLogger cannot be cast to class ch.qos.logback.classic.Logger (org.slf4j.impl.SimpleLogger and ch.qos.logback.classic.Logger are in unnamed module of loader 'app')\n",
:clojure.main/triage
{:clojure.error/class java.lang.ClassCastException,
:clojure.error/line 354,
:clojure.error/cause
"class org.slf4j.impl.SimpleLogger cannot be cast to class ch.qos.logback.classic.Logger (org.slf4j.impl.SimpleLogger and ch.qos.logback.classic.Logger are in unnamed module of loader 'app')",
:clojure.error/symbol unilog.config/start-logging!,
:clojure.error/source "config.clj",
:clojure.error/phase :execution},
@maxp
maxp / build.clj
Created May 10, 2019
cljs node repl
View build.clj
(ns build
(:require [cljs.build.api :as b]))
(b/build "src"
{:output-to "main.js"
:output-dir "target"
:optimizations :simple
:target :nodejs
:main 'your-project.core})
@maxp
maxp / thread-loop.clj
Last active Mar 3, 2019
threaded init/step/cleanup lifecycle
View thread-loop.clj
;;
;; mlib: run proccessing loop in separate thread
;;
(ns mlib.thread
(:require
[clojure.core.async :refer [thread <!!]]))
;
(defn- thread-loop [state' init step cleanup]
@maxp
maxp / express-https.ts
Created Nov 22, 2018
https listener and key generation example
View express-https.ts
/**
openssl req -newkey rsa:2048 -nodes -batch -utf8 -keyout keytemp.pem -x509 -days 365 -out cert.pem \
-subj "/C=GB/ST=London/L=London/O=Global Security/OU=IT Department/CN=example.com"
openssl rsa -in keytemp.pem -out key.pem
*/
@maxp
maxp / random-hex
Created Nov 22, 2018
oneliner: generate random hex using nodejs
View random-hex
node -e "console.log(require('crypto').randomBytes(20).toString('hex'))"
@maxp
maxp / csr_key
Last active Sep 18, 2018
create key and certificate request
View csr_key
openssl req -utf8 -sha256 -out ${NAME}.csr -new -newkey rsa:2048 -nodes -keyout ${NAME}.key
https://www.openssl.org/docs/man1.0.2/apps/openssl-req.html
openssl req -nodes -newkey rsa:2048 -keyout example.key -out example.csr \
-subj "/C=GB/ST=London/L=London/O=Global Security/OU=IT Department/CN=example.com" \
-batch -utf8
-config "file"