Skip to content

Instantly share code, notes, and snippets.

View Duologic's full-sized avatar

Jeroen Op 't Eynde Duologic

View GitHub Profile
@Duologic
Duologic / generate_libsonnet.sh
Last active July 27, 2020 16:17
PoC: Generates a jsonnet lib from a Helm chart
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
DIRNAME=$(dirname $0)
if [ "$#" != 2 ] && [ "$#" != 3 ]&& [ "$#" != 4 ]; then
>&2 echo "arguments invalid"
echo "Usage: `basename $0` <path to helm chart> <output dir> ['<helm_args>'] [overwrite]"
exit 1
fi

Option 1

└── lib/k.libsonnet imports vendor/k8s-alpha
    └── vendor/k8s-util imports lib/k.libsonnet
        └── library imports vendor/k8s-util
  • Known pattern, same as ksonnet-util/kausal.libsonnet
  • It is clear that the library depends on opinionated library k8s-util
  • Single import for both, k.libsonnet might be imported twice for the newcomer
@Duologic
Duologic / jsonnet-lint-method-use.sh
Created July 20, 2020 09:28
Naive linter that looks for method-use in Jsonnet
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
DIRNAME=$(dirname $0)
if [ "$#" != 1 ]; then
echo "Usage: `basename $0` <file_to_lint>"
exit 1
fi
func traverseControllerRef(controllerRef *metav1.OwnerReference, namespace string) (*metav1.OwnerReference, error) {
obj, err := client.
AppsV1().
RESTClient().
Get().
Resource(fmt.Sprintf("%ss", controllerRef.Kind)).
Name(controllerRef.Name).
Namespace(namespace).
Do().Raw()
if err != nil {
@Duologic
Duologic / cam.html
Last active April 10, 2020 08:08
Quick and dirty Pan/Tilt for IPCam Foscam FI9821P
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Move camera feed left/right/up/down using arrow keys</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
$(function() {
var username = "username";
var password = "password";
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
CLUSTER_NAME=example
BASEDIR=$(dirname $(realpath "$0"))
API_PORT=8555
EXPOSE=30041:30041/tcp
SERVER=${SERVER-localhost}
@Duologic
Duologic / sw.js
Created May 2, 2019 16:16
Very basic service worker for PWA apps (from the Google example code)
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('/sw.js').then(function(registration) {
// Registration was successful
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}, function(err) {
// registration failed :(
console.log('ServiceWorker registration failed: ', err);
});
});
@Duologic
Duologic / wsgi.py
Created April 26, 2019 10:00
This initialises Honeycomb.io in a Django/Uwsgi setup (also works with django-admin runserver)
import os
import logging
import beeline
from django.core.wsgi import get_wsgi_application
def init_beeline():
from django.conf import settings # BEELINE = {'writekey': '', 'dataset': ''}
logging.info(f'beeline initialization in process pid {os.getpid()}')
@Duologic
Duologic / tesseract_poc.html
Last active April 12, 2019 16:49
Tesseract POC
<!DOCTYPE html>
<html>
<head>
<script src='https://cdn.jsdelivr.net/gh/naptha/[email protected]/dist/tesseract.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/camanjs/4.0.0/caman.full.js'></script>
<script type="text/javascript">
var stopIt = false;
var sleep = function (ms) {
return new Promise(resolve => setTimeout(resolve, ms));
@Duologic
Duologic / collect_zendesk_views_metrics.py
Last active May 9, 2018 12:45
Quick and dirty script to get Zendesk view counts into InfluxDB, Graphite/Carbon AND Prometheus (oh no, overkill)
# pip install zendesk influxdb awesome-slugify
from influxdb import InfluxDBClient
from slugify import slugify
from zendesk import Zendesk
import graphitesend
import os
import socket
import time