Skip to content

Instantly share code, notes, and snippets.

@kfatehi
kfatehi / proxmox_get_vm_name.sh
Last active October 20, 2023 17:17
Get a Proxmox VM's name via MAC address via API and use it in a telegraf override
#!/bin/bash
PROXMOX_SERVER="pve:8006"
USERNAME="root@pam"
PASSWORD="<your pve password>"
NODE="pve"
INTERNAL_BRIDGE="vmbr1"
NIC="ens18" # nic name inside the vm to be templatized
MAC_ADDRESS="$(ip addr show $NIC | grep -m 1 -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}' | tr 'a-f' 'A-F' | head -n1)"
# Step 1: Login and get ticket and CSRF token
@kfatehi
kfatehi / _wireguard_nat_guide.txt
Last active September 30, 2023 05:10
wireguard nat
apt install wireguard-tools
cd /etc/wireguard
# https://www.wireguard.com/quickstart/
umask 077
wg genkey | tee privatekey | wg pubkey > publickey
# https://stanislas.blog/2019/01/how-to-setup-vpn-server-wireguard-nat-ipv6/
echo "net.ipv4.ip_forward = 1
net.ipv6.conf.all.forwarding = 1" > /etc/sysctl.d/wg.conf
@kfatehi
kfatehi / grafana_alert_maint.py
Created August 2, 2023 00:13
Reveal dashboards and panels that have alerts but no notification channels
# Reveal dashboards and panels that have alerts but no notification channels
# Works on Grafana v8 Alerts (v9 changes alerts a lot)
# This script is useful for when you accidentally change alert notification channel
import requests
from config import base_url, api_key
headers = {'Authorization': f'Bearer {api_key}'}
def get_dashboards():
url = f'{base_url}/api/search'
response = requests.get(url, headers=headers)
@kfatehi
kfatehi / gist:adee7a5019473f3f07679f21889c9d07
Created December 12, 2022 04:12
fix subscribestar urls
document.querySelectorAll('[data-href]').forEach((a)=>{ a.href = a.dataset.href; a.onclick=(e)=>{e.preventDefault(); e.stopPropagation(); window.open(a.href, 'blank')}} )
@kfatehi
kfatehi / output.txt
Created November 19, 2022 23:26
M1 Mac Mini GCC Preprocessor Defines (output of echo | gcc -dM -E -)
#define _LP64 1
#define __AARCH64EL__ 1
#define __AARCH64_CMODEL_SMALL__ 1
#define __AARCH64_SIMD__ 1
#define __APPLE_CC__ 6000
#define __APPLE__ 1
#define __ARM64_ARCH_8__ 1
#define __ARM_64BIT_STATE 1
#define __ARM_ACLE 200
#define __ARM_ALIGN_MAX_STACK_PWR 4
@kfatehi
kfatehi / dance.sh
Created October 5, 2022 22:12
ascii dance script
B=' o \ o / _ o __| \ / |__ o _ \ o / o '
C='/|\ | /\ ___\o \o | o/ o/__ /\ | /|\'
D='/ \ / \ | \ /) | ( \ /o\ / ) | (\ / | / \ / \'
E='55555555556666668888888777777555557777777766666666666677777775555'
P=0
function dance() {
if [ $P -ge ${#B} ]; then
P=0
fi
N=${E:$P:1}
@kfatehi
kfatehi / _test.spec.mjs
Created July 28, 2022 18:06
Playwright parallel independent sessions
import { test, expect } from '../helper/test.mjs';
import { signInProcess} from '../helper/sign_in_helper.mjs'
test('test', async ({ page, bpd, playwright }) => {
await Promise.all([
(async ()=>{
const browser2 = await playwright.chromium.launch();
const context2 = await browser2.newContext();
const page2 = await context2.newPage();
const pc2 = await bpd.createCompanyWithUsersContacts();
@kfatehi
kfatehi / rebroadcast.sh
Created April 17, 2022 06:22
Rebroadcast (transcode) the audio of a video livestream over Icecast.
#!/bin/bash
# You can use streamlink to extract the stream URL, e.g.:
# PL_URL=$(streamlink --stream-url https://livestream-website-url best)
# Generally figured out from this gist...
# https://gist.github.com/keiya/c8a5cbd4fe2594ddbb3390d9cf7dcac9
PL_URL=https://some.owncast-server.tv/hls/1/stream.m3u8
while ! curl -s $PL_URL | grep -q offline; do
@kfatehi
kfatehi / global-video-shortcuts-userscript.js
Last active March 13, 2022 22:06
Global Video Shortcuts Userscript
// ==UserScript==
// @name Global Video Shortcuts
// @namespace Violentmonkey Scripts
// @match *://*/*
// @grant none
// @version 1.0
// @author -
// @description lets you step through videos on any site using youtube's keyboard shortcut design
// ==/UserScript==
docker run --name timescaledb -t timescale/timescaledb:latest-pg12 -e POSTGRES_USER=user -e POSTGRES_PASSWORD=pass -e POSTGRES_DB=db -p 5432:5432
docker run --name grafana -t grafana/grafana:7.5.6 -p 3000:3000
now you can visit port 3000 and add a datasource using the credentials