Skip to content

Instantly share code, notes, and snippets.

@paulc
paulc / fzf.py
Last active April 5, 2021 14:24
Python fzf wrapper
import shlex,subprocess
def fzf(input,multi=False,args="",outf=lambda b:b.decode()):
cmd = ["fzf","--read0","--print0",*(["--multi"] if multi else []),*shlex.split(args)]
enc = lambda b:{bytes:lambda v:v,str:lambda v:v.encode()}.get(type(b),lambda v:str(v).encode())(b)
p = subprocess.run(cmd,input=b"\x00".join([enc(i) for i in input or []]),stdout=subprocess.PIPE)
if multi:
return [outf(i) for i in p.stdout.rstrip(b"\x00").split(b"\x00")]
else:
return outf(p.stdout.rstrip(b"\x00"))
@paulc
paulc / lit-html.html
Created March 29, 2021 16:32
LitHTML starter
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="lit-html starter">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>LitHTML</title>
<script type="module">
@paulc
paulc / alpine-chroot-install-freebsd.sh
Created February 27, 2021 22:59
alpine-chroot-install-freebsd
#!/bin/sh
# vim: set ts=4:
#---help---
# Usage: alpine-chroot-install [options]
#
# This script installs Alpine Linux into a chroot and optionally sets up
# qemu-user and binfmt to emulate different architecture (e.g. armhf).
#
# If qemu-user and binfmt is needed, the script checks if both are available.
# If not, it tries to install them using apt-get. Beside this the script should
@paulc
paulc / bitbar.py
Created February 14, 2021 22:13
Some useful utils for BitBar/SwiftBar
import shlex
#
# Some useful utils for BitBar/SwiftBar
#
class Line:
def __init__(self,text,**params):
@paulc
paulc / launchctl.py
Last active April 8, 2021 22:16
Simple 'launchctl list' parser
#!/usr/bin/env python3
import pprint,re,subprocess,sys
#
# Simple parser for 'launchctl list <service>' output
#
# This works for simple outputs (which is true in most cases) but will fail for
# complex outputs - in particular nested arrays/dicts
#
@paulc
paulc / yaml-get.sh
Created January 31, 2021 19:31
yaml-get
#!/bin/sh
# XXX THIS DOESN'T WORK XXX
awk -v key="${1?Usage: yaml_get_section <section>}" -v debug=${DEBUG-0} '
BEGIN {
found = 0
multiline = 0
}
@paulc
paulc / bhyve_cloudinit
Last active January 30, 2021 21:30
Bhyve cloud-init
#!/bin/sh
# KEYWORD: firstboot
# PROVIDE: bhyve_cloudinit
# REQUIRE: NETWORKING
# BEFORE: LOGIN
. /etc/rc.subr
: ${bhyve_cloudinit_enable:="NO"}
@paulc
paulc / test-vnet.sh
Last active January 25, 2021 17:45
Test VNET IPv6 jail configuration
#!/bin/sh
# Host network configuration
GW=$(route -6 get default | awk '/gateway/ { split($2,a,"%"); print a[1] }')
EXT_IFACE=$(route -6 get default | awk '/interface/ { print $2 }')
EXT_INET6=$(ifconfig $EXT_IFACE inet6 | awk '/inet6 2/ { print $2; exit }')
JAIL=${JAIL-ipv6test}
# Create bridge
if [ "${BRIDGE}" == "" ]
@paulc
paulc / syncthing-config.xml
Created December 27, 2020 16:17
syncthing-config.xml
<configuration version="32">
<folder id="default" label="Default Folder" path="/syncthing/Default Folder" type="sendreceive" rescanIntervalS="3600" fsWatcherEnabled="true" fsWatcherDelayS="10" ignorePerms="false" autoNormalize="true">
<filesystemType>basic</filesystemType>
<device id="ZZUFR4D-J2HAHRQ-P2HX2QO-BJIUR2R-RH74FDD-BTD2UTK-LS7G2R5-BLPNLA5" introducedBy=""></device>
<device id="7WVD7UP-Y2JNG3R-LOXIT4V-2P7GREB-BTZM7LK-XJEBJ4Z-QI4CUUE-FWJYSQA" introducedBy=""></device>
<minDiskFree unit="%">1</minDiskFree>
<versioning>
<cleanupIntervalS>0</cleanupIntervalS>
</versioning>
<copiers>0</copiers>
@paulc
paulc / Caddyfile
Last active January 23, 2021 17:10
FreeBSD 12.2 FLARUM
<host> {
root * /var/flarum/public
php_fastcgi 127.0.0.1:9000
file_server
header /assets {
+Cache-Control "public, must-revalidate, proxy-revalidate"
+Cache-Control "max-age=25000"
Pragma "public"
}
encode gzip