Skip to content

Instantly share code, notes, and snippets.

@paulc
paulc / inet6.md
Last active October 12, 2023 16:44
FreeBSD VNET inet6 (Hetzner Cloud)

Ensure bridge inherits mac addresses

echo if_bridge_load=YES >> /boot/loader.conf
echo net.link.bridge.inherit_mac=1 >> /etc/sysctl.conf

Configure external IPv6 address on bridge0

@paulc
paulc / .vimrc
Last active August 5, 2023 09:22
Vimrc
set nocompatible
set nomodeline
set hidden
set bs=2
set ai
set tabstop=4
set shiftwidth=4
set expandtab
set smarttab
@paulc
paulc / modal.html
Created October 31, 2022 15:59
Alpine.js/Bulma Modal
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css">
<script src="//unpkg.com/alpinejs" defer></script>
<title>Modal</title>
</head>
<body>
@paulc
paulc / oracle_cloudconfig.sh
Created June 18, 2022 13:46
Configure WG endpoint (Oracle Linux)
#!/bin/sh
# Configure WG endpoint (Oracle Linux)
WG_PRIVATE_KEY=
WG_ADDRESS=
WG_PEER=
WG_PSK=
WG_ALLOWED_IP=
WG_ENDPOINT=
@paulc
paulc / kv.c
Created April 21, 2022 22:11
Simple TAILQ based kv
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <stdio.h>
#include <sys/queue.h>
typedef struct _kv {
@paulc
paulc / resolve.py
Created February 2, 2022 18:04
resolve.py - simple recursive DNS resolver
from dnslib import DNSRecord,DNSError,QTYPE
ROOT_NS='198.41.0.4'
def find_cname(a,qtype,cname):
for r in a.rr:
if QTYPE[r.rtype] == qtype and r.rname == cname:
return str(r.rdata)
elif QTYPE[r.rtype] == 'CNAME' and r.rname == cname:
return find_cname(a,qtype,str(r.rdata))
@paulc
paulc / utf8.js
Last active January 11, 2022 16:25
UTF8 <-> String
/*
* Extracted from https://github.com/google/closure-library/blob/master/closure/goog/crypt/crypt.js
*
* @license
* Copyright The Closure Library Authors.
* SPDX-License-Identifier: Apache-2.0
*/
export function stringToUtf8ByteArray(str) {
var out = [], p = 0
@paulc
paulc / base64.js
Created June 20, 2021 11:41
Base64 module for QuickJS
import * as os from "os";
import * as std from "std";
export const Base64 = {
_key : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
decode: function(input) {
input = input.replace(/[^A-Za-z0-9\+\/\=]/g,"");
@paulc
paulc / img-clone.sh
Last active May 2, 2021 09:31
img-clone.sh
#!/bin/sh
set -o pipefail
set -o errexit
set -o nounset
USAGE="USAGE: $0 <template> <target> <userdata> [<instance_config>]"
TEMPLATE="${1?${USAGE}}"
TARGET="${2?${USAGE}}"
@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"))