Skip to content

Instantly share code, notes, and snippets.

View sorz's full-sized avatar
😱
AAHHH

Shell Chen sorz

😱
AAHHH
View GitHub Profile
@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 / 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 / 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;
@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.

diff --git a/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryDetailParser.java b/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryDetailParser.java
index 27f9a671..1f541301 100644
--- a/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryDetailParser.java
+++ b/app/src/main/java/com/hippo/ehviewer/client/parser/GalleryDetailParser.java
@@ -73,7 +73,7 @@ public class GalleryDetailParser {
private static final GalleryTagGroup[] EMPTY_GALLERY_TAG_GROUP_ARRAY = new GalleryTagGroup[0];
private static final GalleryCommentList EMPTY_GALLERY_COMMENT_ARRAY = new GalleryCommentList(new GalleryComment[0], false);
- private static final DateFormat WEB_COMMENT_DATE_FORMAT = new SimpleDateFormat("dd MMMMM yyyy, HH:mm z", Locale.US);
+ private static final DateFormat WEB_COMMENT_DATE_FORMAT = new SimpleDateFormat("dd MMMMM yyyy, HH:mm", Locale.US);
@sorz
sorz / aqi_tray.pyw
Last active September 2, 2020 05:32
Simple program that shows AQI on system tray as a colored pie chart.
#!/usr/bin/env python3
"""Simple program that shows AQI on system tray as a colored pie chart.
It fetches PM_2.5 data via Graphite's HTTP API every minutes.
Required Python packages:
requests, pystray, Pillow
"""
import time
import webbrowser
@sorz
sorz / httpdns.py
Created August 14, 2020 08:32
Lastest update on 2019-10-31. Mocked service may have changed since then. Compatibility issues expected.
#!/usr/bin/env python3
import asyncio
import logging
from aiohttp import web
from aiodnsresolver import Resolver, TYPES, DnsRecordDoesNotExist
from des import DesKey
TENCENT_KEYS = {
// ==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==
[Unit]
Description=Setup WireGuard link
After=network-online.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/wg-quick up %i
ExecStop=/usr/bin/wg-quick down %i