Skip to content

Instantly share code, notes, and snippets.

View kLiHz's full-sized avatar

kLiHz kLiHz

View GitHub Profile
@kLiHz
kLiHz / ban.ts
Last active May 19, 2024 10:22
Automatically ban qBittorrent peers, based on client name, with JavaScript (Deno)
const endpoint = 'http://127.0.0.1:9876';
const mainDataUrl = new URL('/api/v2/sync/maindata', endpoint);
const torrentPeersUrl = new URL('/api/v2/sync/torrentPeers', endpoint);
const banPeers = new URL('/api/v2/transfer/banPeers', endpoint);
const f = async () => {
const r = await fetch(mainDataUrl);
const d = await r.json() as { torrents: {[hash: string]: { upspeed: number }} };
for (const [hash, _o] of Object.entries(d.torrents).filter(([_hash, { upspeed }]) => upspeed != 0)) {
torrentPeersUrl.search = `?hash=${hash}`;
@kLiHz
kLiHz / README.md
Last active May 11, 2024 03:08
Reverse Proxying rustup.rs with Cloudflare Workers

Suppose your Worker's domain is $REVERSE_PROXIED_RUSTUP_DOMAIN (e.g. rustup.muc.moe).

Usage

Visit $REVERSE_PROXIED_RUSTUP_DOMAIN for the website rustup.rs.

And set these environment variables for rustup:

  • RUSTUP_DIST_SERVER: https://$REVERSE_PROXIED_RUSTUP_DOMAIN
@kLiHz
kLiHz / changing-cloudflare-universal-ssl-ca.md
Last active March 22, 2024 06:13
Changing Cloudflare Universal SSL CA
@kLiHz
kLiHz / calc.py
Last active September 5, 2023 21:59
How much credit is necessary to give customer the cost price?
import csv
with open('items.csv') as f:
items = [{
'sales': int(i['sales']),
'cost': float(i['cost']),
'price': float(i['price']),
} for i in csv.DictReader(f, skipinitialspace=True)]
tot_sales = sum([i['sales'] for i in items])
@kLiHz
kLiHz / README.md
Last active July 29, 2023 11:27
Parse `tree` command txt output
#include <algorithm>
#include <string>
#include <iostream>
template<typename IntType>
class fraction {
IntType A;
IntType B;
public:
static IntType gcd(IntType x, IntType y) {
@kLiHz
kLiHz / demo.py
Created March 20, 2023 06:37
JavaScript-Like Wrapper for Python 3 URL Parser
from urllib.parse import urlparse, urljoin, parse_qsl, urlencode
class URLSearchParams:
def __init__(self, options: str = '', hook = None) -> None:
self.hook = hook
if type(options) is str:
if len(options) == 0:
self.l = list()
else:
self.l = parse_qsl(options[1:] if options[0] == '?' else options)
@kLiHz
kLiHz / spliting.cpp
Last active November 10, 2022 18:31
C++: `std::string` convenient functions
#include <vector>
#include <string>
#include <numeric>
auto prettify(std::vector<std::string> const& v) {
return "["
+ (v.empty() ? "" : ("'" + v.front() + "'"
+ std::accumulate( v.begin() + 1, v.end(), std::string(),
[](std::string& s, auto const & t){ return std::move(s) + ", '" + t + "'";} )))
+ "]";
@kLiHz
kLiHz / README.md
Last active May 17, 2022 17:46
About SVG output of diagrams.net

Optimize SVG output of diagrams.net

draw.io, available at https://app.diagrams.net, is an easy-to-use diagramming tool. However, the exporting of *.drawio files needs to be taken care of most of the times.

As for PNG exporting, currently the default setting may generates blurring image. Fortunately, this can be fixed by scaling the diagram into a larger one. [^png-export]

As for the SVG, things become a bit complicated.

When user viewing the software exported SVG files in a web browser, everything seems just fine. But when they try importing these SVGs into softwares like Word or Inkscape, users may see a "Viewer does not support full SVG 1.1" (now changed to "Text is not SVG - cannot display") text on their image.