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'
@gerritjvv
gerritjvv / core.async-lazy-sequence
Created October 30, 2013 11:07
This is for a situation where you have N amount of threads reading from different sources and want to consume all of the data they produce as a single sequence. Can be described as merging N queues from different sources and works well when the data produced is from IO. e.g. My usage is with kafka, I have multiple kafka topics and partitions to …
(use 'clojure.core.async)
;this is the function you want to use
(defn lazy-channels [chs]
(lazy-seq (cons (let [ [v _] (alts!! chs)] v) (lazy-channels chs))))
;now for the tesging
(def chs [ (chan) (chan) (chan) ]) ; the channels can come from anywhere, here we are using three channels for testing
(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 / gist:5866665
Last active May 24, 2022 21:46
Calling an external process from Clojure
(comment
This is the easiest and most concise way of calling an external process in Java. The inheritIO methods causes the command to output stdout and errout to the same place as your current process (which most of the times is the console), no need to create mechanisms for reading asynchronously from input streams to get at the information.
http://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html
)
(def ret (.waitFor (-> (ProcessBuilder. ["gzip" "-t" "g.txt.gz"]) .inheritIO .start)))
@gerritjvv
gerritjvv / gist:5807270
Created June 18, 2013 17:06
Clojure functions for dealing with ftp or sftp server using the commons vfs2 library. from https://github.com/gerritjvv/pseidon
(ns pseidon.core.ds.ftp
(:require [pseidon.core.conf :refer [get-conf get-conf2] ]
)
(:use clojure.tools.logging
))
(import
'(org.apache.commons.vfs2 FileContent FileObject FileSystemManager FileSystemOptions VFS Selectors)
@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