Skip to content

Instantly share code, notes, and snippets.

@gerritjvv
gerritjvv / helm-avoid-nil-pointer.md
Created September 21, 2023 10:01
helm avoid nil pointer on nested values and maps

When you nest values in yaml like

server:
  spec:
    cpu: 0.5

You use it in helm as {{ .Values.server.spec.cpu | default 0.5 }}, which works fine till you try the values as not defined
e.g

@gerritjvv
gerritjvv / k8s_yamls.sh
Created September 21, 2023 09:56
Download yaml resources from kubernetes recursively using bash point free style
#!/usr/bin/env bash
echo "ingress deployments services statefulset" | \
xargs -n 1 -I ktype \
sh -c 'kubectl get ktype | tail -n+2 | awk '\''{print $1}'\'' | xargs -t -P 2 -I resource sh -c '\''kubectl get ktype resource -o yaml > resource.yml'\'''
# echo "ingress deployments services statefulset" | xargs -n 1 -I ktype sh -c
# ^^ runs a command for each ingress deployments etc.. the -I parameter is string substitution, i.e where ever it sees ktype it will put the ingress deployments etc read from stdin.
# kubectl get ktype | tail -n+2 | awk '{print $1}' | xargs -t -P 2 -I resource sh -c 'kubectl get ktype resource -o yaml > resource.yml'
(ns lcm.core)
;; Finding the least common multiplier for a list of numbers
;; Reference material
;; https://en.wikipedia.org/wiki/Least_common_multiple
;; https://en.wikipedia.org/wiki/Euclidean_algorithm
;; https://lemire.me/blog/2013/12/26/fastest-way-to-compute-the-greatest-common-divisor/
;; https://octave.sourceforge.io/octave/function/lcm.html
(defn bigint-gcd ^long [^long a ^long b]
(.longValue (.gcd (BigInteger/valueOf a) (BigInteger/valueOf b))))
@gerritjvv
gerritjvv / Averages.java
Created October 4, 2021 08:52
Averages in 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),

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.

#!/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:
#!/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 July 27, 2020 13:46
Apply a function walking multiple levels of maps and vectors
(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 July 8, 2020 10:08
Clojure - finding something in a list
(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 June 23, 2020 09:22
Update variables with a PROD Prefix in bash
# 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