Skip to content

Instantly share code, notes, and snippets.

@iwconfig
iwconfig / restic
Created September 10, 2024 14:32
Execute restic repository scripts as sub commands of restic itself. E.g. `restic-foo backup [...]` can be executed as `restic foo backup [...]`. Inspired by https://forum.restic.net/t/recipes-for-managing-repository-environment-variables/1716/2
#!/usr/bin/env bash
## Place this file in /usr/local/bin and make it executable.
## reference: https://forum.restic.net/t/recipes-for-managing-repository-environment-variables/1716/2
REPO_NAME="$1"
REPO_SCRIPT="/usr/local/sbin/restic-$REPO_NAME"
# Check if the corresponding script exists and is executable
if [ -x "$REPO_SCRIPT" ]; then
@iwconfig
iwconfig / textburrito.py
Created August 4, 2024 18:44
Wraps regular text or shell commands by a specific width. Does hard wraps, word wraps and shell wraps. Handles prefixes and suffixes, initial and subsequent. Returns a wrapped string by default.
#!/usr/bin/env python3
import shlex
def wrap(string, width, prefix='', initial_prefix='', subsequent_prefix='', suffix='', initial_suffix='', subsequent_suffix='', word_wrap=False, cmd_wrap=False, join=True, join_with='\n'):
lines = []
if word_wrap or cmd_wrap:
for line in string.strip().splitlines():
line_list = []
line_length = 0
for word in shlex.split(line, posix=False) if cmd_wrap else line.split():
@iwconfig
iwconfig / proxmox-config-parser.py
Created August 3, 2024 19:53
Parser for Proxmox .conf files
#!/usr/bin/env python3
import configparser
import json
from pprint import pp
def parse_proxmox_config(file_path):
parser = configparser.ConfigParser(allow_no_value=True, delimiters=':')
with open(file_path, 'r') as file:
content = file.read()
@iwconfig
iwconfig / teldrive-rclone.json
Created July 3, 2024 14:34
scoop package for teldrive rclone fork (windoze). Usage: `scoop install <url_or_path_to_teldrive-rclone.json>`
{
"homepage": "https://github.com/divyam234/rclone",
"version": "1.67.2",
"license": "MIT license",
"url": "https://github.com/divyam234/rclone/releases/download/v1.67.2/rclone-v1.67.2-windows-amd64.zip",
"hash": "e32f95a5af686f2e79515ef3eddb52b7a8a21a030388f72223261e869fa5d970",
"extract_dir": "rclone-v1.67.2-windows-amd64",
"bin": "rclone.exe",
"shortcuts": [
[
@iwconfig
iwconfig / svtplay-format-filters.sh
Created June 14, 2024 18:28
A more manageable yt-dlp/youtube-dl format filtering for svtplay.se. Defaults to the best quality, dash and hevc, and skips accessibilities.
#!/usr/bin/env bash
# A more manageable yt-dlp/youtube-dl format filtering for svtplay.se. It outputs a
# complete format filter string. Defaults to the best quality, dash and hevc, and
# avoids all audio accessibilities. It handles both 2-channel and 6-channel audio.
# Use --audio-multistream to merge both tracks.
# It takes zero up to three arguments, each of which is one of "best" or "worst".
# The first is for video, the second for audio and the third argument is for the
# third "generic" fallback if both the first and the second filters fail. By default
@iwconfig
iwconfig / README.md
Created May 3, 2024 20:38
Replace text, e.g. secrets, in all files in all git commits using `git filter-branch` and `sed`.

Replace text, e.g. secrets, in all files in all git commits using git filter-branch and sed.

a. Download replace-text.sh

b. Clone the gist repo in the same directory as replace-text.sh

  • using SSH url:

    1. git clone git@gist.github.com:<reponame (hash)>
  • using HTTPS url:

# Normalizes filenames and folders !!
# because fuck you HFS+
# I hate you so
# so much
# Very WIP and probably abandoned because
# I dont feel like fixing the bugs and i'll just
# consider all this as wasted time and redo my
# rsync command with `--iconv=utf-8-mac,utf-8`,
@iwconfig
iwconfig / blocket-bostad-google-maps.user.js
Last active May 2, 2022 11:41
Lägger till en knapp vid kartan, den som visas i Blockets bostadsannonser, för att öppna annonsens address i Google Maps istället
// ==UserScript==
// @name Blocket bostad Google Maps
// @namespace http://tampermonkey.net/
// @version 0.2
// @description try to take over the world!
// @author You
// @downloadURL https://gist.github.com/iwconfig/69c74cf7fa57ef9034c0b0dee7fa20e5/raw/blocket-bostad-google-maps.user.js
// @updateURL https://gist.github.com/iwconfig/69c74cf7fa57ef9034c0b0dee7fa20e5/raw/blocket-bostad-google-maps.user.js
// @supportURL https://gist.github.com/iwconfig/69c74cf7fa57ef9034c0b0dee7fa20e5
// @match https://bostad.blocket.se/*
@iwconfig
iwconfig / parse-yaml.sh
Last active December 7, 2021 17:31
parse yaml in pure bash
#!/usr/bin/env bash
ryml () { local IFS=': ' ; read E C ;}
while ryml; do # alternatively: while IFS=': ' read E C; do
case $E in
parent)
parent=${E} ;;
child)
echo ${parent}.${E}: ${C} ;;
@iwconfig
iwconfig / parse-xml.sh
Last active December 7, 2021 17:32
parse xml in pure bash
#!/usr/bin/env bash
rdom () { local IFS=\> ; read -d \< E C ;}
while rdom; do # alternatively: while IFS=\> read -d \< E C; do
case $E in
tvshow|episodedetails)
parent=${E} ;;
title|showtitle|season|episode|plot|aired|thumb)
echo ${parent}.${E}: ${C} ;;