Skip to content

Instantly share code, notes, and snippets.

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

Marc Bachmann marcbachmann

🏳️‍🌈
View GitHub Profile
@marcbachmann
marcbachmann / .hyperterm.js
Last active January 10, 2024 06:58
hyperterm config
module.exports = {
config: {
// default font size in pixels for all tabs
fontSize: 12.5,
// font family with optional fallbacks
fontFamily: '"Meslo LG S for Powerline", Menlo, "DejaVu Sans Mono", "Lucida Console", monospace',
// terminal cursor background color (hex)
cursorColor: 'rgba(255,255,255,.4)',
[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 / 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 / jsonb_patch.sql
Last active March 7, 2022 09:32
postgres jsonb patch
-- ISC LICENSE
--
-- Copyright (c) 2021, Marc Bachmann <marc@livingdocs.io>
-- 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 / 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 marc@livingdocs.io
Will create a certificate using subject '/CN=marc@livingdocs.io'
and write the credentials into the 'marc@livingdocs.io.kubeconfig' file."
@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 / 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
@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 / sound.scpt
Created September 13, 2015 13:04
Switch audio output on mac
tell application "System Preferences" to activate
tell application "System Events"
get properties
tell application "System Preferences"
reveal anchor "output" of pane id "com.apple.preference.sound"
end tell
tell process "System Preferences"
set theRows to every row of table 1 of scroll area 1 of ¬
tab group 1 of window "sound"
repeat with aRow in theRows