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 / 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)
#!/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 / 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
@lilydjwg
lilydjwg / use-cpu.c
Last active May 10, 2020 12:53
use-cpu: nothing but uses up one cpu core, printing out how much cpu time allocated to it every second
#include<stdio.h>
#include<sys/time.h>
#include<stdbool.h>
#include<signal.h>
#include<stdint.h>
#include<sys/resource.h>
volatile uint64_t count = 0;
void alarm_handler() {
@lilydjwg
lilydjwg / dns-ipv6-reply
Created April 17, 2016 13:37
Answer AAAA DNS queries on behalf of a DNS server
#!/usr/bin/env python3
import socket
import struct
import traceback
import subprocess
import time
import signal
import dnslib
@lilydjwg
lilydjwg / findorphanfiles
Created August 3, 2019 07:43
Find files not managed by pacman (for Arch Linux and derivatives)
#!/usr/bin/python3
import os
def allrepofiles():
repo = '/var/lib/pacman/local'
files = set()
for dirpath, dirnames, filenames in os.walk(repo):
for file in filenames:
if file != 'files':
@lilydjwg
lilydjwg / zhist.c
Created February 23, 2020 11:23
A simple C program to decode & encode zsh history file
//=====================================================================
// 让 zsh 的历史记录可读
//=====================================================================
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//---------------------------------------------------------------------
void readhist();
void writehist();
void usage();
@lilydjwg
lilydjwg / subreap.c
Created March 13, 2015 04:10
zsh/subreap module
#include<sys/prctl.h>
#include "subreap.mdh"
#include "subreap.pro"
/**/
static int
bin_subreap(char *nam, char **args, Options ops, UNUSED(int func))
{
int reaping = !OPT_ISSET(ops, 'u');
int result = prctl(PR_SET_CHILD_SUBREAPER, reaping);