Skip to content

Instantly share code, notes, and snippets.

View kLiHz's full-sized avatar

kLiHz kLiHz

View GitHub Profile
@kLiHz
kLiHz / index.html
Created March 17, 2025 04:46
HNote data v2
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HNote Data v2</title>
</head>
<body>
<style>
body {
@kLiHz
kLiHz / IPRegExp.ts
Last active February 15, 2025 13:40
JavaScript RegExp to match valid IPv4 / IPv6 address
const d8 = '25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d';
export const ipv4RegStr = `((${d8})\\.){3}(${d8})`
export const ipv4Matcher = new RegExp(ipv4RegStr, 'g');
export const ipv4Validator = new RegExp(`^(${ipv4RegStr})$`);
// https://stackoverflow.com/questions/14638711/regular-expression-for-ipv6-addresses
@kLiHz
kLiHz / IPv4.ts
Last active February 15, 2025 09:49
Validate IP address (IPv4 / IPv6) in JavaScript / TypeScript
// WARNING: These code may be incorrect and may not be production ready, so use at your own risk.
export const dotDecimalIPv4Regex = /^((25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)\.){3}(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)$/;
const dottedComponentRegex = /^((0(?:x|X)[a-fA-F0-9]+)|(0[0-7]*)|([1-9]\d*))$/;
export function isIPv4(s: string): boolean {
const decimals = s.split('.');
// https://stackoverflow.com/questions/10133820/is-there-any-documentation-for-omitting-zeroes-in-dot-decimal-notation-of-ipv4-a
// https://linux.die.net/man/3/inet_aton
@kLiHz
kLiHz / main.ipynb
Last active July 21, 2024 22:31
Cloudflare datacenter colo lists
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kLiHz
kLiHz / worker.js
Last active September 25, 2024 19:33
Reverse proxying share.dmhy.org
export default {
/**
* Default fetch event handler
* @param request {Request}
* @param env
* @param ctx
* @returns {Promise<Response>}
*/
async fetch(request, env, ctx) {
const url = new URL(request.url);
@kLiHz
kLiHz / ban.ts
Last active April 2, 2025 15:58
Automatically ban (suspicious) qBittorrent peers (which comes from several CN IP CIDRs and takes hundreds of GBs traffic by downloading something again and agian), based on client name and source IP prefixes, with JavaScript (Deno)
import { formatBytes } from 'https://base64.muc.moe/assets/js/common/20240430/util.ts'
const endpoint = 'http://127.0.0.1:9876' // || 'http://localhost:8080';
const username = 'admin';
const password = 'adminadmin';
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);
async function login(username: string, password: string) {
@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