Skip to content

Instantly share code, notes, and snippets.

@sorz
sorz / apcmetrics.py
Last active Apr 14, 2022
Turn APC UPS status `apcaccess status` to OpenMetrics (prometheus) exporter with zero-dependency Python script & systemd socket.
View apcmetrics.py
#!/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 Jan 3, 2022
Patch to yubioauth-android (8fbb3b1) for Canokey Pigeon.
View yubioauth_android_for_canokeys_pigeon.patch
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 Aug 26, 2021
A simple Prometheus export that collect A/C target temperature & load power from Xiaomi Air Conditioning Companion.
View README.md

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 Jul 14, 2021
All files related to a toy air temp/humi/dust mointor based on DHT22, GP2Y1010AU0F, Arduino and Cubieboard (or Raspberry Pi).
View DHT22.cpp
/*
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);
@sorz
sorz / gfwlist2regex.py
Last active Jul 13, 2021
Download and convert GFWList to url regex which compatible with Squid.
View gfwlist2regex.py
#!/usr/bin/env python
#encoding: utf-8
import urllib2
from base64 import b64decode
LIST_URL = 'https://autoproxy-gfwlist.googlecode.com/svn/trunk/gfwlist.txt'
BLACK_FILE = 'gfw.url_regex.lst'
WHITE_FILE = 'cn.url_regex.lst'
View chiannet-macao-nexus-5x.md

在 Nexus 5X 上使用中国电信(澳门)卡遇到的问题及可能的解决方案

症状

  • 中国电信(澳门)的电话卡插入美版 Nexus 5X 有信号能打电话发短信,但是不能上网。
  • 设置菜单中找不到 APN 相关选项,强行打开 APN 设置页面后提示「没有权限修改设置」。

注:由于手头的 Nexus 5X 已坏,无法对照操作,以下步骤在细节上可能有所出入。

方法一

View ehviewer-fix-comment.patch
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 Sep 2, 2020
Simple program that shows AQI on system tray as a colored pie chart.
View aqi_tray.pyw
#!/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 Aug 14, 2020
Lastest update on 2019-10-31. Mocked service may have changed since then. Compatibility issues expected.
View httpdns.py
#!/usr/bin/env python3
import asyncio
import logging
from aiohttp import web
from aiodnsresolver import Resolver, TYPES, DnsRecordDoesNotExist
from des import DesKey
TENCENT_KEYS = {
View e-hentai-prefetch-next-page.user.js
// ==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==