Skip to content

Instantly share code, notes, and snippets.

Avatar
🙃
dissappointed about the new UI and round avatars

依云 lilydjwg

🙃
dissappointed about the new UI and round avatars
View GitHub Profile
@lilydjwg
lilydjwg / pacsync
Created Oct 29, 2020
pacsync: sync with latest mirrors, download from fastest ones
View pacsync
#!/bin/bash -e
unshare -m bash <<'EOF'
mount --make-rprivate /
for f in /etc/pacman.d/*.sync; do
filename="${f%.*}"
mount --bind "$f" "$filename"
done
pacman -Sy
EOF
@lilydjwg
lilydjwg / colors.py
Last active Nov 19, 2020
colors.py: show all kinds of terminal colors at a glance
View colors.py
#!/usr/bin/python3
from functools import partial
def colors16():
for bold in [0, 1]:
for i in range(30, 38):
for j in range(40, 48):
print(f'\x1b[{bold};{i};{j}m {bold};{i};{j} |\x1b[0m', end='')
print()
@lilydjwg
lilydjwg / use-cpu.c
Last active May 10, 2020
use-cpu: nothing but uses up one cpu core, printing out how much cpu time allocated to it every second
View use-cpu.c
#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 / zhist.c
Created Feb 23, 2020
A simple C program to decode & encode zsh history file
View zhist.c
//=====================================================================
// 让 zsh 的历史记录可读
//=====================================================================
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//---------------------------------------------------------------------
void readhist();
void writehist();
void usage();
@lilydjwg
lilydjwg / gh-check
Last active Nov 29, 2020
gh-check: speed test to known GitHub IPs
View gh-check
#!/usr/bin/python3
import asyncio
import time
import socket
import argparse
import aiohttp
class MyConnector(aiohttp.TCPConnector):
@lilydjwg
lilydjwg / findorphanfiles
Created Aug 3, 2019
Find files not managed by pacman (for Arch Linux and derivatives)
View findorphanfiles
#!/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':
View btrfs-autosnapshot
#!/usr/bin/python3
import os
import datetime
import subprocess
import logging
import tempfile
import contextlib
import ctypes
from pathlib import Path
@lilydjwg
lilydjwg / show-mem-usage
Last active Jul 20, 2019
show-mem-usage: parse /proc/{pid}/maps and show how much memory is used by each file/type
View show-mem-usage
#!/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 / 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 Jun 16, 2019
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)
You can’t perform that action at this time.