Skip to content

Instantly share code, notes, and snippets.

View Averages.java
import java.util.HashMap;
import java.util.List;
import java.util.LongSummaryStatistics;
import java.util.Map;
import java.util.stream.Collectors;
class Averages {
public static void main(String[] args) {
List<Map<String, Long>> data = List.of(
Map.of("age", 18L, "rate", 30L),
View reduce_python_lambda.md

Advice on how to reduce code size

There are use cases where you need to reduce the total size of your python deployed code including library code.

E.g:

I have to deploy a layer with pandas and numpy etc. Total size cannot be over 260mb.

View histogram.py
#!/usr/bin/env python3
# pip3 install matplotlib
# pip3 install numpy
import matplotlib.pyplot as plt
import numpy as np
import sys
file = sys.argv[1]
with open(file, 'rb') as io:
View record_sounds.py
#!/usr/bin/env python3
# pip3 install sounddevice --user
# pip3 install numpy
# pip3 install scipy
import sounddevice as sd
import numpy as np
fs=44100
duration = 5 # seconds
@gerritjvv
gerritjvv / mapvals.clj
Created Jul 27, 2020
Apply a function walking multiple levels of maps and vectors
View mapvals.clj
(require '[clojure.walk :refer [postwalk]])
(defn mapvals [f m]
(let [v-f (fn [v]
(cond
(map? v) v
(coll? v) (into (empty v) (map f) v)
:else (f v)))
@gerritjvv
gerritjvv / in.clj
Created Jul 8, 2020
Clojure - finding something in a list
View in.clj
(defn in? [vs ls]
(boolean (some (partial (set vs)) ls)))
(in? [1 2] [3 4 2 5]) => false
(in? [1 2] [3 1 4 2 5]) => true
(defn in? [v ls]
(loop [[x & rs] ls]
(if-not x
@gerritjvv
gerritjvv / prod_config.sh
Created Jun 23, 2020
Update variables with a PROD Prefix in bash
View prod_config.sh
# The aim is to support e.g
# URL="dburl" variables and then override at will when PROD_URL is available.
switch_prod.sh
for v in $(env | awk '/PROD_/ {gsub(/PROD_/,""); print $1}'); do
eval "export $v"
done
@gerritjvv
gerritjvv / aws_sqs.clj
Created Sep 23, 2019
clojure cognitect aws sqs
View aws_sqs.clj
;; deps:
;; [com.cognitect.aws/api "0.8.352"]
;; [com.cognitect.aws/endpoints "1.1.11.632"]
;; [com.cognitect.aws/sqs "742.2.519.0"]
;; [mount "0.1.16"]
;; [cheshire "5.8.1"]
(require '[cognitect.aws.client.api :as aws])
(require '[mount.core :as mount)
View golang-crypto-bench-output
=== RUN TestNaiveTimesEncryptGCM
Run 0. Did 1000000 iterations in 2.481178232s
Run 1. Did 1000000 iterations in 2.495653698s
Run 2. Did 1000000 iterations in 2.554544033s
Run 3. Did 1000000 iterations in 2.735187669s
Run 4. Did 1000000 iterations in 2.468231834s
Run 5. Did 1000000 iterations in 2.508428888s
Run 6. Did 1000000 iterations in 2.515230338s
Run 7. Did 1000000 iterations in 2.757054756s
Run 8. Did 1000000 iterations in 2.807702375s
@gerritjvv
gerritjvv / javaaesbenchmarks.md
Last active Jun 17, 2019
Java JVM AES CBC GCM Benchmarks
View javaaesbenchmarks.md

Vanilla Java JCE

Benchmark                       Mode  Cnt      Score      Error  Units
AesJce.enc_aes128CbcHmacSha256  thrpt  200  40722.671 ±  739.025  ops/s
AesJce.enc_aes256CbcHmacSha512  thrpt  200  39288.300 ±  979.722  ops/s
AesJce.enc_aes128GCM            thrpt  200  75599.381 ± 1197.385  ops/s

AesJce.dec_aes128CbcHmacSha256  thrpt  200  49830.138 ± 1040.007  ops/s
AesJce.dec_aes256CbcHmacSha512  thrpt  200  51758.272 ±  839.378  ops/s
AesJce.dec_aes128GCM            thrpt  200  76144.372 ± 2626.274  ops/s