Skip to content

Instantly share code, notes, and snippets.

View sorz's full-sized avatar
😱
AAHHH

Shell Chen sorz

😱
AAHHH
View GitHub Profile
2667b2a20e4eaa792096f3fba493881965997563
@sorz
sorz / httpdns.py
Last active May 14, 2025 13:10
(Non-standard) HTTP DNS resolver. I used it to hijack some Chinese apps' queries on my home gateway during 2019–2021. May not work today.
#!/usr/bin/env python3
import asyncio
import logging
from typing import Tuple, List
from aiohttp import web
from aiodnsresolver import Resolver, TYPES, DnsRecordDoesNotExist
from des import DesKey
TENCENT_KEYS = {
@sorz
sorz / readme.md
Created January 27, 2025 10:16
Enable your FIDO SSH key (ed25519-sk) ONLY IF the hardware key (e.g. YubiKey) is plugged in. (Auto disable key when plug it out). For Windows / OpenSSH.

Having multiple YubiKeys (+ fallback auth method) for ssh is annoying: I must keep pressing ESC until the right key kicks in.

This script is intended to be executed every time your hardware key is plugged in or out. It checks current inserted hardware keys and comment/uncomment IdentityFile /path/to/id_<ID> lines in ~/.ssh.config.

You may follow this post to setup a Scheduled Task (two actually, one for plug, one for unplug) to invoke this script.

@sorz
sorz / http_echo.py
Created May 5, 2023 07:26
Simple TCP server that echo everything with prepended HTTP response headers.
#!/usr/bin/env python3
import asyncio
from asyncio import StreamReader, StreamWriter
LISTEN = ('::', 8080)
WAIT_SECS = 3
BUF_SIZE = 4096
HTTP_RESPONSE = [
'HTTP/1.1 200 OK',
@sorz
sorz / yubioauth_android_for_canokeys_pigeon.patch
Last active January 15, 2023 14:04
Patch to yubioauth-android (8fbb3b1) for Canokey Pigeon.
diff --git a/app/src/main/java/com/yubico/yubikitold/transport/usb/UsbDeviceManager.java b/app/src/main/java/com/yubico/yubikitold/transport/usb/UsbDeviceManager.java
index 1e5ed82..060b32f 100644
--- a/app/src/main/java/com/yubico/yubikitold/transport/usb/UsbDeviceManager.java
+++ b/app/src/main/java/com/yubico/yubikitold/transport/usb/UsbDeviceManager.java
@@ -29,7 +29,7 @@ public final class UsbDeviceManager {
private transient UsbDevicePredicate deviceFiler = new UsbDevicePredicate() {
@Override
public boolean test(UsbDevice usbDevice) {
- return usbDevice.getVendorId() == 0x1050;
+ return usbDevice.getVendorId() == 0x1050 || usbDevice.getVendorId() == 0x20A0;
// ==UserScript==
// @name E-Hentai Prefetch Next Page
// @namespace Violentmonkey Scripts
// @match https://e-hentai.org/s/*
// @match https://exhentai.org/s/*
// @grant none
// @version 0.2.0
// @author sorz
// @description Prefetch image file on the next page for faster browsing.
// ==/UserScript==
@sorz
sorz / cdma_pdu.py
Created June 16, 2017 07:59
Decode SMS from CDMA PDU
from datetime import datetime
import binascii
import logging
import io
def _parse_fields(raw):
"""Return a iterators of (id, value)."""
raw = io.BytesIO(raw)
while True:
@sorz
sorz / apcmetrics.py
Last active April 14, 2022 08:48
Turn APC UPS status `apcaccess status` to OpenMetrics (prometheus) exporter with zero-dependency Python script & systemd socket.
#!/usr/bin/env python3
import sys
import socket
from subprocess import Popen, PIPE
def main():
sock = socket.fromfd(3, socket.AF_INET, socket.SOCK_STREAM)
while True:
@sorz
sorz / README.md
Created August 26, 2021 09:38
A simple Prometheus export that collect A/C target temperature & load power from Xiaomi Air Conditioning Companion.

Prometheus exporter for Xiaomi A/C Companion

A simple Prometheus export that collect A/C target temperature & load power from Xiaomi Air Conditioning Companion.

It serves as a simple demo, you may expand it to other Mi devices & metrics. See python-miio's document.

@sorz
sorz / DHT22.cpp
Last active July 14, 2021 16:46
All files related to a toy air temp/humi/dust mointor based on DHT22, GP2Y1010AU0F, Arduino and Cubieboard (or Raspberry Pi).
/*
DHT22.cpp - Library for DHT22/DHT11 relative humidity & temperature sensor.
Created by Sorz. 2014-07-18.
*/
#include "Arduino.h"
#include "DHT22.h"
TempHumiSensor::TempHumiSensor(int pin)
{
pinMode(pin, INPUT_PULLUP);