Skip to content

Instantly share code, notes, and snippets.

@lilydjwg
lilydjwg / mosh3.py
Created Nov 13, 2018
mosh3: a mosh helper that reuses ssh connections (ControlMaster)
View mosh3.py
#!/usr/bin/env python3
# inspired by
# https://github.com/mobile-shell/mosh/issues/24#issuecomment-201893250
import sys
import os
import subprocess
def main():
@lilydjwg
lilydjwg / cleanup_haozip.py
Last active Jan 9, 2018
cleanup HaoZip file extension registration
View cleanup_haozip.py
# Note: admin privileges is necessary
import winreg
i = 0
while True:
key = winreg.EnumKey(winreg.HKEY_CLASSES_ROOT, i)
value = winreg.QueryValue(winreg.HKEY_CLASSES_ROOT, key)
if value.startswith('HaoZip.'):
print(f'Deleting {key} ({value})...', end='', flush=True)
@lilydjwg
lilydjwg / git-ls-large
Created Dec 31, 2017
git-ls-large: find large objects in your git repo
View git-ls-large
#!/bin/bash -e
if [[ $# -gt 1 ]]; then
idx=($@)
else
idx=(.git/objects/pack/pack-*.idx)
fi
objects=$(git verify-pack -v "${idx[@]}" | grep -v -e 'non delta' -e 'chain length' -e '.git/objects' | sort -k3nr | head)
@lilydjwg
lilydjwg / readonlyroot
Created May 15, 2017
readonlyroot: make / readonly but permit writes to some paths
View readonlyroot
#!/bin/bash -e
if [[ $EUID -ne 0 ]]; then
echo >&2 "Need to be root."
exit 1
fi
if ! mountpoint /mnt >/dev/null; then
exit 2
fi
@lilydjwg
lilydjwg / zfs-show
Created Jan 1, 2017
zfs-show: a wrapper to `zfs get` to show values from multiple properties in a table nicely
View zfs-show
#!/usr/bin/env python3
import sys
import subprocess
from collections import namedtuple, OrderedDict
Record = namedtuple('Record', 'name property value source')
def get_widths(item):
return [len(x) for x in item.values()]
@lilydjwg
lilydjwg / mynetns_run
Created May 13, 2016
mynetns_run: Run a program in a seperate network namespace
View mynetns_run
#!/bin/bash -e
NETNS_FILE=/var/run/netns/mynet
MNTNS_FILE=/var/run/ns/mynet_mnt
if [[ ! -f $NETNS_FILE ]]; then
ip netns add mynet
ip link add mynet0 type veth peer name mynet1
ip link set mynet0 up
@lilydjwg
lilydjwg / colorpicker.c
Created Apr 25, 2016
a simple colorpicker in GTK
View colorpicker.c
//=====================================================================
// 拾取颜色并输出
// 返回值:
// 0 正常
// 1 被取消
// 2 语法错
//---------------------------------------------------------------------
#include<gtk/gtk.h>
#include<ctype.h>
//---------------------------------------------------------------------
@lilydjwg
lilydjwg / .gitconfig
Created Apr 25, 2016
gitconfig (for older versions of git)
View .gitconfig
[color]
diff = auto
status = auto
branch = auto
grep = auto
showbranch = auto
[core]
excludesfile = ~/.gitconfig.d/gitignore
quotepath = false
[alias]
@lilydjwg
lilydjwg / dns-ipv6-reply
Created Apr 17, 2016
Answer AAAA DNS queries on behalf of a DNS server
View dns-ipv6-reply
#!/usr/bin/env python3
import socket
import struct
import traceback
import subprocess
import time
import signal
import dnslib
@lilydjwg
lilydjwg / _whoneeds
Last active May 29, 2016
A fast whoneeds implemention in Python for Arch Linux
View _whoneeds
#compdef whoneeds
_pactree "$@"
You can’t perform that action at this time.