Skip to content

Instantly share code, notes, and snippets.

View marcbachmann's full-sized avatar
🏳️‍🌈

Marc Bachmann marcbachmann

🏳️‍🌈
View GitHub Profile
@marcbachmann
marcbachmann / useFakeDate.js
Created March 29, 2022 20:05
A replacement for sinon.useFakeTimers
const OriginalDate = global.Date
function restoreFakeDate () {
global.Date = OriginalDate
}
function useFakeDate (date) {
date = new OriginalDate(date)
class Date extends OriginalDate {
constructor (...args) {
@marcbachmann
marcbachmann / zaddhset.lua
Last active January 11, 2022 18:52
Redis Scheduled Jobs
-- zaddhset sortedsetkey score hsetkey fieldname fieldvalue [fieldname fieldvalue ...]
-- sortedsetkey = KEYS[1]
-- score = KEYS[2]
-- hsetkey = KEYS[3]
-- fields = ARGV
if #KEYS ~= 3 or #ARGV < 2 or #ARGV % 2 ~= 0 then
return {err="ERR wrong number of arguments for 'zaddhset' command"}
end
if redis.call('EXISTS', KEYS[3]) == 1 then return nil end
@marcbachmann
marcbachmann / kubernetes-create-user.sh
Last active September 19, 2021 16:01
Kubernetes create user certificate
#!/bin/bash
set -e
USERNAME=$1
if ! grep -qE '^[a-zA-Z0-9.@\-\+_]{2,100}$' <<< "$USERNAME"; then
1>&2 echo -e "❌ Username is missing or contains invalid characters
Usage: ./kubernetes-create-user.sh [email protected]
Will create a certificate using subject '/[email protected]'
and write the credentials into the '[email protected]' file."
@marcbachmann
marcbachmann / jsonb_patch.sql
Last active March 7, 2022 09:32
postgres jsonb patch
-- ISC LICENSE
--
-- Copyright (c) 2021, Marc Bachmann <[email protected]>
-- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
-- copyright notice and this permission notice appear in all copies.
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
@marcbachmann
marcbachmann / ndjson-iterator.js
Created September 30, 2020 22:50
Newline Delimited JSON Stream Iterator for json streams in the browser
const response = await fetch(`http://localhost:8080/stream`, {
method: 'get',
headers: {
Authorization: `Bearer SomeToken`
}
})
for await (const value of ndJsonIterator(response.body)) {
console.log(value)
}
@marcbachmann
marcbachmann / etc_docker_daemon.json
Created January 29, 2018 18:50
docker container logs using rsyslog & journald
{ "log-driver": "journald", "log-opts": {"tag": "{{.Name}}/{{.ID}}"}}
@marcbachmann
marcbachmann / Dockerfile
Created November 21, 2017 01:03
syslog-ng Dockerfile
FROM multiarch/alpine:x86_64-v3.6 as syslog-ng
ENV VERSION=3.12.1
RUN apk --no-cache add ca-certificates glib pcre eventlog libressl json-c && \
apk add --no-cache --virtual .build-deps alpine-sdk wget build-base glib-static glib-dev eventlog-dev pcre-dev libressl-dev python2-dev json-c-dev && \
wget -O "/tmp/syslog-ng-$VERSION.tar.gz" "https://github.com/balabit/syslog-ng/releases/download/syslog-ng-$VERSION/syslog-ng-$VERSION.tar.gz" && \
cd /tmp && \
tar zxfv "syslog-ng-$VERSION.tar.gz" && \
cd "syslog-ng-$VERSION"
@marcbachmann
marcbachmann / syslog-ng.conf
Created November 21, 2017 00:39
syslog-ng
@version: 3.12
options {
chain_hostnames(0);
time_reopen(10);
time_reap(360);
log_fifo_size(2048);
create_dirs(yes);
group(adm);
perm(0640);
[SERVICE]
Flush 5
Daemon Off
Log_Level info
Parsers_File /etc/fluent-bit/parsers.conf
[INPUT]
Name Tail
Path /mnt/data/docker/containers/*/*.log
Path_Key file
@marcbachmann
marcbachmann / Travis Docker Scripts.md
Last active September 21, 2020 14:08
Several bash scripts for TravisCI. Scripts to update docker, run a http proxy, and pull most recent docker image from docker hub

Travis Docker Scripts

Usage

Define the GIST url and pipe some script to bash/sh

GIST=https://gist.githubusercontent.com/marcbachmann/16574ba8c614bb3b78614a351f324b86/raw/a7e17acc57938a047c093f560858e3b0a8e2c741
curl -s $GIST/script-name | bash