Skip to content

Instantly share code, notes, and snippets.

View Gowee's full-sized avatar
🙂

Hung-I Wang Gowee

🙂
View GitHub Profile
@Gowee
Gowee / stamp_photo.py
Created February 3, 2024 05:24
Add a date stamp to photos
#!/usr/bin/env python3
import sys
from PIL import Image, ImageDraw, ImageFont
from PIL.ExifTags import TAGS, GPSTAGS
from datetime import date, datetime, timezone
def calculate_crop_dimensions(image, ratio=3/2):
width, height = image.size
l = width > height # is landscape
if not l:
@Gowee
Gowee / wow.worker.js
Created May 17, 2023 02:09
(draft, incomplete) WebSocket based-proxy service on Workers
const WOW_TOKEN = "W0w!"
async function handleRequest(request) {
const upgradeHeader = request.headers.get('Upgrade');
const token = request.headers.get('X-WOW-TOKEN');
const addr = request.headers.get('X-WOW-ADDR');
if (token !== WOW_TOKEN) {
return new Response('Forbidden', { status: 403 });
}
if (!upgradeHeader || upgradeHeader !== 'websocket') {
#!/bin/sh
parted /dev/vda -- mklabel gpt
parted /dev/vda -- mkpart esp 1MiB 100MiB
parted /dev/vda -- mkpart primary 100MiB 100%
parted /dev/vda -- set 1 boot on
mkfs.ext4 -L nixos /dev/vda2 # btrfs not working?
mkfs.vfat -F32 -n boot /dev/vda1
mkdir -p /mnt
mount /dev/vda2 /mnt
mkdir -p /mnt/boot
@Gowee
Gowee / MDExtBot.py
Last active July 31, 2022 07:12
Backup 2017-01.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Backup 2017-01-07.
from uuid import uuid4
from telegram import InlineQueryResultArticle, ParseMode, \
InputTextMessageContent
from telegram.ext import Updater, InlineQueryHandler, CommandHandler
@Gowee
Gowee / gettelegraf.sh
Created April 16, 2022 07:06
Openwrt get telegraf
#!/bin/sh
set -eux
cd /tmp
filename=$(opkg update && opkg info telegraf | grep "Filename:" | cut -d' ' -f2)
repo=$(cat /etc/opkg/distfeeds.conf | grep "openwrt_packages" | cut -d' ' -f3)
url="$repo/$filename"
wget -q $url
@Gowee
Gowee / wgporo.sh
Last active April 4, 2022 08:52
Rotate Wireguard ports
#!/bin/sh
set -u
WGIF="winnie"
STEP=3600
PSTART=5500
PEND=5999
CONFFILE="/etc/wireguard/$WGIF.conf"
PLEN=$((PEND-PSTART+1))
#!/usr/bin/env python3
# filter disinct connections by 4-tuples from tcpdump output
pairs = set()
while (line := input()):
time, family, orig, _, dest, remaining = line.split(maxsplit=5)
dest = dest[:-1]
if (orig, dest) not in pairs:
print(f"{orig} > {dest}, {time}, {remaining}")
pairs.add((orig, dest))
# -*- coding: utf8 -*-
# To be deployed to Tecent SCF
# https://console.cloud.tencent.com/scf/
import json
def main_handler(event, context):
srcip = event['requestContext']['sourceIp']
dest_url = "https://water-meter.bamboo.workers.dev/callback?ip=" + srcip
resp = {
"isBase64Encoded": False,
@Gowee
Gowee / openingsourceorg.iv
Last active September 30, 2021 08:21
The Telegram InstantView template rule for OpeningSource.org
# Maintained by: Hung-I WANG <whygowe@gmail.com>
~version: "2.1"
# e.g. `/1234`, `/1234/zh-tw`
?path: /\d+/(\w+/)?
# # The Telegram IV parser treats the webpage incorrectly, which results in mal-structured HTML/XML. Here try to fix it by rewrapping <meta> into <head> and moving them to the front of <body>.
# @prepend("<head>"): /html
# @prepend_to($@): //meta
@Gowee
Gowee / tomato-renew-tls-cert.sh
Created June 25, 2021 01:20
Shell script for renewing the TLS cert of the WebUI of AdvancedTomato
#!/bin/sh
# The script is simply adapted from:
# https://codeinsecurity.wordpress.com/2020/03/08/setting-a-custom-https-certificate-in-tomato-or-advancedtomato/
# The script is expected to work with uacme with a hook script:
# https://gist.github.com/Gowee/e756f925cfcbd5ab32d564ee3c795786
set -eu
FQDN="foobar.example.org" # TO BE FILLED
UACME_HOOK=/path/to/uacme-hook.sh # TO BE FILLED