Skip to content

Instantly share code, notes, and snippets.

View lilydjwg's full-sized avatar
🙃
dissappointed about the new UI and round avatars

依云 lilydjwg

🙃
dissappointed about the new UI and round avatars
View GitHub Profile
@lilydjwg
lilydjwg / libreap.c
Created February 14, 2014 12:34
make processes reap their own children processes
#include<stdio.h>
#include<sys/prctl.h>
__attribute__ ((constructor)) static void setup(void) {
if(prctl(PR_SET_CHILD_SUBREAPER, 1) != 0){
perror("prctl");
}
}
@lilydjwg
lilydjwg / mosh3.py
Created November 13, 2018 07:11
mosh3: a mosh helper that reuses ssh connections (ControlMaster)
#!/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 June 16, 2019 04:04
cleanup HaoZip file extension registration
# 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 December 31, 2017 08:44
git-ls-large: find large objects in your git repo
#!/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 05:03
readonlyroot: make / readonly but permit writes to some paths
#!/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 January 1, 2017 08:53
zfs-show: a wrapper to `zfs get` to show values from multiple properties in a table nicely
#!/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 / .gitconfig
Created April 25, 2016 05:44
gitconfig (for older versions of git)
[color]
diff = auto
status = auto
branch = auto
grep = auto
showbranch = auto
[core]
excludesfile = ~/.gitconfig.d/gitignore
quotepath = false
[alias]
#!/usr/bin/env python3
import os
import sys
from urllib.parse import parse_qs
import subprocess
import json
from PyQt5 import QtWebKit, QtWebKitWidgets
from PyQt5.QtCore import (
@lilydjwg
lilydjwg / show-mem-usage
Last active July 20, 2019 07:47
show-mem-usage: parse /proc/{pid}/maps and show how much memory is used by each file/type
#!/usr/bin/python3
'''parse /proc/{pid}/smaps and show how much RSS memory is used by each file/type'''
import sys
from collections import defaultdict
def filesize(size: int) -> str:
units = 'KMGTPEZY'
left = abs(size)
@lilydjwg
lilydjwg / lolcat.py
Last active February 4, 2020 12:24
lolcat.py: make rainbows over text
#!/usr/bin/env python3
# inspired by https://github.com/busyloop/lolcat
import sys
import re
import os
from math import ceil
from colorsys import hsv_to_rgb
from unicodedata import east_asian_width