Skip to content

Instantly share code, notes, and snippets.

@gerritjvv
gerritjvv / aws_sqs.clj
Created September 23, 2019 13:03
clojure cognitect aws sqs
;; 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)
=== 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 June 17, 2019 07:05
Java JVM AES CBC GCM Benchmarks

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
@gerritjvv
gerritjvv / cliArgumentsAsMap.java
Created September 27, 2017 23:16
Convert CLI main arguments into a Map for quick no extra lib console java apps
public static Map<String, Object> argumentsAsMap(String[] args){
Map<String, Object> m = new HashMap<>();
for(int i = 0; i < args.length; i++){
String lbl = args[i].trim();
if(lbl.startsWith("-") && i+1 < args.length && !args[i+1].trim().startsWith("-")) {
m.put(removePrefixes(lbl), args[i+1].trim());
i++;
} else {
import posixpath
import argparse
import urllib
import os
from SimpleHTTPServer import SimpleHTTPRequestHandler
from BaseHTTPServer import HTTPServer
class RootedHTTPServer(HTTPServer):
@gerritjvv
gerritjvv / kafka-clj.pool-impl.clj
Created June 15, 2016 17:15
Performance of ConcurrentLinkedQueue + Semaphore vs atom + persistent_vector for queue implementation
(ns
^{:doc "Concurrent keyed pool implementation using ConcurrentHashMap and ConcurrentLinkedQueue"}
kafka-clj.pool-impl
(:use criterium.core)
(:import (java.util.concurrent ConcurrentLinkedQueue ConcurrentHashMap Semaphore ExecutorService Executors TimeUnit)))
;; add [criterium "0.4.4"] to you're project.clj file
;; then use run-test-cc and run-test-a
;;
;; Results for both ConcurrentLinkedQueue + Semaphore and for atom + vector access is the same
from mymem import cache_set, cache_get
########################
#### private functions
def chunk_seq(file_name, chunk_size):
'''
Create a lazy sequence for bytes each up to chunk_size (default 1048576)
'''
@gerritjvv
gerritjvv / convert.sh
Last active January 25, 2016 20:39
Convert mkv to avi
for f in ./*.mkv; do
echo "convert $f"
ffmpeg -i "$f" -f avi -c:v mpeg4 -b:v 4000k -c:a libmp3lame -b:a 320k "${f%.*}.avi"
done
@gerritjvv
gerritjvv / linecounting.clj
Created September 16, 2015 08:28
efficient clojure line counting
(import '(java.io InputStreamReader FileInputStream BufferedReader))
(import '(java.util.zip GZIPInputStream))
(defn gz-line-counter [^String file-name]
(let [^BufferedReader reader (BufferedReader. (InputStreamReader. (GZIPInputStream. (FileInputStream. file-name))))]
(try
(loop [i 0]
(if (.readLine reader)
(recur (inc i))
i))
@gerritjvv
gerritjvv / gist:4c353066e6bd1135449a
Created May 7, 2015 22:23
using bounded clojure agents from fun-utils
(require '[fun-utils.agent :as fagent] :reload)
(def agnt (fagent/agent {} :mailbox-len 10))
;send to the agent
(fagent/send agnt assoc-in [:a :b] 2)
;deref
@agnt
;;{:a {:b 2}}