Skip to content

Instantly share code, notes, and snippets.

View ckhung's full-sized avatar

Chao-Kuei Hung ckhung

View GitHub Profile
@ckhung
ckhung / sscapcat.sh
Last active November 1, 2025 01:42
screenshot caption concatenation
#!/bin/bash
# screenshot caption concatenation
# assumption:
# 1. all screenshot files are of the same extension, of the same size, with ordered file names.
# 2. there are no other files with names sscapcat[059]-* in /tmp.
read -r x_pad y_header y_content y_caption out_file <<<$(echo 0 0 0 0 result.jpg)
while getopts 'x:y:o:h' opt; do
# Norman Wildberger + Dean Rubine
# Finding a root of a cubic polynomial with geode
# https://youtu.be/oIHd3zDDDCE?si=BIlgB9ub57UPdJ38&t=1730
def Q(t2, t3):
return 1 + (t2+t3) * (1+2*t2+3*t3+5*t2*t2+16*t2*t3+12*t3*t3)
def shift(C, ap):
return [
C[0] + ap*C[1] + ap*ap*C[2] + ap*ap*ap*C[3],
@ckhung
ckhung / flow.dot
Last active July 21, 2025 02:18
共筆維護試算表、地圖自動更新,大尺寸 (較大試算表) 版本
// dot -Tsvg flow.dot > flow.svg
digraph "gs2umap 資料流向 (上下游關係)" {
rankdir = TB;
overlap = scale;
key [ label="gsheet-key.txt" ];
gs [ label="google sheet" ];
php [ label="gs2umap.php" ];
python [ label="gs2umap.py" ];
@ckhung
ckhung / gsheet2umap.php
Last active July 13, 2025 03:06
convert a google sheet containing longitude and latitude fields into a csv file recognized by umap of osm
<?php
// 共筆維護試算表、地圖自動更新 https://newtoypia.blogspot.com/2025/03/gsheet-umap.html
if (! (isset($_GET['html']) && filter_var($_GET['html'], FILTER_VALIDATE_URL))) {
echo 'needs "html" variable on command line';
return;
}
$url = $_GET['html'];
$htmlContent = file_get_contents($url);
$tmpHtmlFile = tempnam(sys_get_temp_dir(), 'html_');
@ckhung
ckhung / nmj2csv.pl
Created February 1, 2025 02:41
generate a csv file with date time strings that are easier to sort, from the output of: notmuch show --format=json '*' | jq 'map(.[0][0] | [.headers.Date, .id, .headers.Subject])'
#!/usr/bin/perl -w
# This script processes the output of:
# notmuch show --format=json '*' | jq 'map(.[0][0] | [.headers.Date, .id, .headers.Subject])'
# to create a csv file with date time strings that are easier to sort.
use Date::Parse;
while (<>) {
next unless /"(.*)"/;
my $item = $1;
@ckhung
ckhung / csv2vcf.py
Created January 10, 2025 07:16
convert csv files to a vcf (vcard) file
#!/usr/bin/python3
import argparse, re, csv
parser = argparse.ArgumentParser(
description='read csv files and print to stdout in vcf format',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('-d', '--delimiter', type=str, default=',',
help='field delimiter character')
parser.add_argument('mapping',
@ckhung
ckhung / .mbsyncrc
Last active December 17, 2024 07:40
mbsync 與 msmtp 的設定檔 + mutt/ 目錄底下的四個設定檔
# ~/.mbsyncrc
# modified from https://www.cosroe.com/2024/05/neomutt-isync.html
# Global defaults that apply to all channels / accounts / stores
# Create in both places
Create Both
# Do not remove if missing in one place
Remove None
# Permanently delete those messages marked for deletion
@ckhung
ckhung / imap7to8.py
Created November 23, 2024 13:26
mutt_oauth2.py and scripts to convert imap encoded foldernames or subject names
#!/usr/bin/env python3
# https://stackoverflow.com/a/12803967
# IMAP folder path encoding (IMAP UTF-7) for Python
import sys, re
from imapclient import imap_utf7
for line in sys.stdin:
line = line.strip().encode('ascii')
@ckhung
ckhung / lagrange.gpt
Last active October 19, 2024 07:31
lagrange points as seen using effective potential plot
# lagrange points as seen using effective potential plot
len(x,y) = sqrt(x*x+y*y)
# mass of planet relative to that of star
alpha = 0.01 # "mu" in wikipedia
# mass of star and mass of planet
Ms = 1000
Mp = Ms * alpha
@ckhung
ckhung / gen-theme-tiles.sh
Last active October 4, 2025 01:40
generate tiles needed for window border parts for a dark xfce4 theme so that one can have a dark desktop with bright window borders
# 2025/10/04 把原先的黃/綠色框改成紫色框,跟 Sweet-Dark-v40 原來的顏色比較搭
ACTIVE_BORDER_COLOR="#ce93ff"
INACTIVE_BORDER_COLOR="#7944aa"
TITLE_HEIGHT=18
for i in 1 2 3 4 5 ; do convert -size 24x$TITLE_HEIGHT xc:$ACTIVE_BORDER_COLOR title-$i-active.png ; done
convert -size 5x$TITLE_HEIGHT xc:$ACTIVE_BORDER_COLOR top-left-active.png
convert -size 5x$TITLE_HEIGHT xc:$ACTIVE_BORDER_COLOR top-right-active.png
convert -size 3x16 xc:$ACTIVE_BORDER_COLOR left-active.png
convert -size 3x16 xc:$ACTIVE_BORDER_COLOR right-active.png