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 / 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 / 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);
});
});
#!/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 / 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";
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 / 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

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 / 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
package main
import (
"bufio"
"encoding/json"
"fmt"
"log"
"os"
"github.com/grafana/tanka/pkg/kubernetes/manifest"
@Duologic
Duologic / diff.sh
Last active October 29, 2020 15:18
cleaner diff with tanka/kubectl
#!/usr/bin/env sh
# Usage: export KUBECTL_EXTERNAL_DIFF=/path/to/diff.sh
function warning() {
ORANGE='\033[0;33m'
NC='\033[0m' # No Color
>&2 printf "${ORANGE}WARNING: ${1}${NC}\n"
}
warning "last-applied-configuration <redacted>"