Skip to content

Instantly share code, notes, and snippets.

View aelindeman's full-sized avatar

Alex Lindeman aelindeman

  • 38.89, -77.02
  • 05:32 (UTC -04:00)
View GitHub Profile
@aelindeman
aelindeman / update-theme-switcher-sunrise-sunset.py
Last active December 11, 2024 21:32
updates the GNOME Night Theme Switcher extension's night mode times to your local sunrise/sunset in the absence of geoclue
#!/usr/bin/python3
# run `pip3 install --user astral` or `apt install python3-astral` first
# install to `~/.local/libexec/update-theme-switcher-sunrise-sunset.py`
import json
import os
import subprocess
from pathlib import Path
from astral import Observer, sun
@aelindeman
aelindeman / readme.md
Last active March 31, 2025 02:12
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);