Skip to content

Instantly share code, notes, and snippets.

@zhangyoufu
zhangyoufu / aliyun-cs-credential.sh
Last active August 8, 2025 15:25
使用阿里云OpenAPI获得Kubernetes集群kubeconfig的用户证书(长期/临时),依赖jq、yq、aliyun-cli
#!/bin/bash
set -euo pipefail
: $CLUSTER_ID
: ${PRIVATE:=false} # auto use private IP if public IP not available
: ${MINUTES:=60} # defaults to 1 hour
: ${SHOW_CLUSTER:=}
: ${REGION_ID:=cn-shanghai} # choose nearest region as OpenAPI endpoint, don't need to match ACK cluster location
echo >&2 '+ aliyun cs DescribeClusterUserKubeconfig'
@zhangyoufu
zhangyoufu / mt76_tx_hang_reset
Created August 2, 2025 00:36
/etc/init.d/mt76_tx_hang_reset chmod +x / enable / start
#!/bin/sh /etc/rc.common
START=90
STOP=01
USE_PROCD=1
start_service() {
procd_open_instance
procd_set_param command /bin/sh -c 'while :; do read < /sys/kernel/debug/ieee80211/phy1/mt76/tx_hang_reset; [ "$REPLY" -eq 0 ] || break; sleep 5; done; reboot'
procd_close_instance
#!/usr/bin/env python3
from collections.abc import Buffer, Generator
from typing import TypeAlias
import re
Token: TypeAlias = int | bytes | str
Result: TypeAlias = int | bytes | list['Result'] | dict[bytes, 'Result']
regexp = re.compile(rb'([del])|i(-?\d+)e|(\d+):')
@zhangyoufu
zhangyoufu / steamguard_otp.sh
Created March 12, 2025 06:09
calculate SteamGuard OTP in shell script (standard TOTP, last step use base26 charset, truncate to 5 chars)
#!/bin/bash
tohex() { od -An -t x1 | tr -d '[:space:]'; }
fromhex() { printf %b "$(echo "$1" | sed 's/../\\x&/g')"; }
steamguard_otp() {
SECRET_HEX=$(base32 -d <<<"$1" | tohex)
DIGEST_HEX=$(fromhex "$(printf "%016x" "$(($(date +%s)/30))")" | openssl dgst -sha1 -mac HMAC -macopt hexkey:"${SECRET_HEX}" -binary | tohex)
OFFSET=$((0x${DIGEST_HEX:39:1}))
X=$((0x${DIGEST_HEX:$((OFFSET*2)):8}&0x7FFFFFFF))
# dmidecode -t 0
Vendor: SeaBIOS
Version: e623647
Release Date: 04/01/2014
# cat /proc/iomem
000c0000-000c91ff : Video ROM # https://gitlab.com/qemu-project/qemu/-/blob/3257fc8383b13856e6719d1390655ce24bafd071/pc-bios/vgabios-cirrus.bin
000c9800-000cbbff : Adapter ROM # https://gitlab.com/qemu-project/qemu/-/blob/3257fc8383b13856e6719d1390655ce24bafd071/pc-bios/kvmvapic.bin
fffc0000-ffffffff : Reserved # dd if=/dev/mem bs=1024 skip=4194048 count=256 of=seabios.bin
@zhangyoufu
zhangyoufu / bypass-windows-setup-compatibility-check.reg
Created February 25, 2025 11:58
setupcompat.dll ConX::Compatibility::CCompatibilityCheckerFactory::CreateCompatibilityChecker
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\Setup\MoSetup]
"MoSetupTests"=dword:00000001
"CompatCheckTestHookCategory"=dword:00000000
https://support.microsoft.com/en-US/rss-feed-picker is not actively maintained
https://support.microsoft.com/en-us/feed/atom/<UUID>
https://support.microsoft.com/en-us/feed/rss/<UUID>
0cfbf2af-24ea-3e18-17e6-02df7331b571 Windows Server 2012
02b57d93-e28e-9404-10a8-8a6b85e3eb6f Windows Server 2012 R2 ESU
c3a1be8a-50db-47b7-d5eb-259debc3abcc Windows Server 2016
eb958e25-cff9-2d06-53ca-f656481bb31f Windows Server 2019
2d67e9fb-2bd2-6742-08ee-628da707657f Windows Server 2022
e54d3179-52dc-2ffd-1cea-f5c0319a5cad Windows Server 2025, all editions
@zhangyoufu
zhangyoufu / china_mobile_province_code.txt
Created February 9, 2025 07:37
中国移动省份代码(中国大陆)
100 北京
200 广东
210 上海
220 天津
230 重庆
240 辽宁
250 江苏
270 湖北
280 四川
290 陕西
@zhangyoufu
zhangyoufu / check-hyperv-enlightenment.c
Created November 17, 2024 18:24
check enabled Hyper-V Enlightenment inside VM
#include <intrin.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
/******************************************************************************/
// include/qemu/bitops.h
#define BIT(nr) (1UL << (nr))
@zhangyoufu
zhangyoufu / gist:0b3123fe37e2906536827ace81c0ad5d
Created November 3, 2024 09:40
Windows Processor Architecture Enumeration
0: PROCESSOR_ARCHITECTURE_INTEL
1: PROCESSOR_ARCHITECTURE_MIPS
2: PROCESSOR_ARCHITECTURE_ALPHA
3: PROCESSOR_ARCHITECTURE_PPC
4: PROCESSOR_ARCHITECTURE_SHX
5: PROCESSOR_ARCHITECTURE_ARM
6: PROCESSOR_ARCHITECTURE_IA64
7: PROCESSOR_ARCHITECTURE_ALPHA64
8: PROCESSOR_ARCHITECTURE_MSIL
9: PROCESSOR_ARCHITECTURE_AMD64