Skip to content

Instantly share code, notes, and snippets.

@runapp
runapp / sort-json.py
Created November 23, 2021 11:29
Sort json file by key, recursively.
import json
import collections
import os
def sort_keys(x):
if isinstance(x, list):
return [sort_keys(i) for i in x]
elif isinstance(x, dict):
ks = sorted(x.keys())
{
"$schema": "https://aka.ms/terminal-profiles-schema",
"actions": [
{
"command": "find",
"keys": "ctrl+shift+f"
},
{
"command": {
@runapp
runapp / nft-cheat-sheet.sh
Last active January 1, 2024 11:22
nftables related
# rate limit, max 20KB/s from 192.168.1.1
nft -f - <<EOF
table ip test {
chain inbound {
type filter hook input priority filter; policy accept;
ip saddr 192.168.1.1 limit rate over 20 kbytes/second drop
}
}
EOF
@runapp
runapp / btrfs-enable-quota.sh
Created July 21, 2021 07:43
Enable quota on btrfs, creating subvolume for every user and then
allusers=$(cat)
for i in $allusers ; do
mv $i ==$i && \
btrfs subvol create $i && \
chown --reference===$i $i
done
for i in $allusers ; do
cp -a --reflink=always ==$i/. $i
@runapp
runapp / wg-genconf.py
Last active June 11, 2021 02:22
Quickly generate a server and several clients for Wireguard.
#!/usr/bin/env python3
from typing import List, Tuple
from ipaddress import _BaseAddress, _BaseNetwork
import io
import math
import random
import argparse
import ipaddress
@runapp
runapp / server.sh
Created April 6, 2020 17:18
A simple postgresql wrapper
#!/bin/sh
if [ $EUID -eq 0 ]; then
echo "Please don't run me with root privilege!"
exit 1
fi
ROOT="$(dirname "$(readlink -f "$0")")"
DATABASE=db
@runapp
runapp / extract-eml-addr.py
Created December 20, 2019 08:14
Extract all email address in an .eml file, decoding all UTF-8 encoded names.
import re
NAME_PATTERN = re.compile(r'(?P<name>[^ "]+|".*") \<(?P<email>.*@.*)\>')
ENCODED_PATTERN = re.compile(r'=\?(?P<charset>.*)\?(?P<encoding>.*)\?(?P<encodedtext>.*)\?=')
import sys
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
@runapp
runapp / de-res.py
Created November 23, 2019 14:10
A naive python PE resource parser
import itertools
import struct
unpack = struct.unpack
ts = """CURSOR=1
BITMAP=2
ICON=3
MENU=4
DIALOG=5
STRING=6
import datetime
import random
import urllib.parse
import hmac
import hashlib
import base64
import requests
import pytz
""" To setup RAM sub-accounts, use the following policy:
@runapp
runapp / blink.css
Created February 7, 2018 18:02
CSS blinker! Native countryside fashion!