Skip to content

Instantly share code, notes, and snippets.

@aelindeman
aelindeman / readme.md
Last active May 12, 2024 18:15
ZeroTier on PiKVM

Using ZeroTier on PiKVM

Requires PiKVM OS version 2022.06.20 or newer.

Steps

  1. Install ZeroTier, then start and stop it to generate an identity

@aelindeman
aelindeman / AbortablePromise.ts
Created October 13, 2022 19:49
adds cancel behavior to ES6 Promises (e.g. for React components)
export default <T>(promise: Promise<T>, ac: AbortController): Promise<T> => {
if (ac.signal.aborted) {
return Promise.reject(ac.signal);
}
return new Promise((resolve, reject) => {
ac.signal.addEventListener('abort', () => {
reject(ac.signal);
});
@aelindeman
aelindeman / nut-influx.py
Last active April 20, 2022 19:14
InfluxDB adapter script for NUT (Network UPS Tools) output
#!/usr/bin/env python3
import subprocess
import sys
import time
MEASUREMENT_NAME = "nut"
UPS_STATUS = {
"OL": "Online",
@aelindeman
aelindeman / slack_plugin.py
Created April 26, 2021 14:51
Slack reporter plugin for pytest
import os
import time
from collections import defaultdict
from datetime import timedelta
from enum import Enum
from typing import Dict, List, Optional
import requests
from _pytest.config import Config
from _pytest.config.argparsing import Parser
@aelindeman
aelindeman / MethodCallLoggingMetaclass.py
Created February 24, 2021 15:43
Python metaclass that logs calls to methods
import logging
from types import FunctionType
class MethodCallLoggingMetaclass(type):
def __new__(mcs, name, bases, attrs):
for attr_name, attr_value in attrs.items():
if isinstance(attr_value, FunctionType):
attrs[attr_name] = mcs.log_wrapper(attr_value, name)
return super().__new__(mcs, name, bases, attrs)
@aelindeman
aelindeman / aplay.service
Created November 19, 2020 23:45
alsa audio passthrough service with fifo
[Unit]
Description=aplay passthrough audio from arecord
BindsTo=arecord.service
[Service]
Environment=INPUT=/var/run/arecord
ExecStart=/usr/bin/aplay $INPUT
@aelindeman
aelindeman / borg
Last active March 9, 2020 14:55
Borg stuff
#!/bin/sh
set -eu
borg create \
--filter AME \
--list \
--stats \
--exclude-caches \
--exclude-from "$HOME/.config/borg/exclude" \
@aelindeman
aelindeman / exportall
Created February 19, 2020 14:05
bash script to export all key=value pairs in a file as environment variables to the terminal
#!/usr/bin/env bash
exportall() {
export $(grep -v '^#' "${1:-.env}" | xargs)
}
@aelindeman
aelindeman / README.md
Created January 20, 2020 18:46
convert an array of environment variables to a Javascript object

example usage:

const envArray = [
  'PATH=/usr/local/bin:/usr/bin:/usr/sbin',
  'HOME=/home/alex',
  'FOO=bar'
];

const envObject = toEnvObject(envArray);
@aelindeman
aelindeman / template.xml
Created January 4, 2020 19:14
React function component live template for IntelliJ/WebStorm
import React from 'react';
export interface $TM_FILENAME_BASE$Props {
}
const $TM_FILENAME_BASE$: React.FC<$TM_FILENAME_BASE$Props> = props => {
return (
<>
$END$