Skip to content

Instantly share code, notes, and snippets.

View ckhung's full-sized avatar

Chao-Kuei Hung ckhung

View GitHub Profile
@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
Created September 25, 2024 04: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
ACTIVE_BORDER_COLOR="#ffff80"
INACTIVE_BORDER_COLOR="#80c080"
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 2x$TITLE_HEIGHT xc:$ACTIVE_BORDER_COLOR top-left-active.png
convert -size 2x$TITLE_HEIGHT xc:$ACTIVE_BORDER_COLOR top-right-active.png
convert -size 2x16 xc:$ACTIVE_BORDER_COLOR left-active.png
convert -size 2x16 xc:$ACTIVE_BORDER_COLOR right-active.png
convert -size 16x2 xc:$ACTIVE_BORDER_COLOR bottom-active.png
@ckhung
ckhung / split-gmail.pl
Last active September 19, 2024 03:07
split-gmail.pl: extract bank statements: 把 zimbra mail server 下載回來的 *.eml 檔當中的銀行/信用卡/電費/電信費帳單抓出來、移除密碼,成為單純的 pdf 檔 + split-gmail.pl 把 gmail 的一個 *.mbox 拆成每封信一個檔案
#!/usr/bin/perl -w
# usage: split-gmail.pl test.mbox
# split test.mbox, a file exported from gmail, into one mail per file, named m0001.mbox, m0002.mbox, ...
$fn = sprintf("m%04d.mbox", 1);
open(FH, '>', $fn) or die $!;
$N = 0;
while (<>) {
# a sample string we are matching against:
@ckhung
ckhung / prj2html.py
Last active May 28, 2024 08:57
噗浪 rss: 用 xq 轉 json 再用 prj2html.py 轉 html
#!/usr/bin/python3
# for f in *.xml ; do xq . $f > ${f/%xml/json} ; done
# python3 prj2html.py *.json > new.html
# 詳見 https://newtoypia.blogspot.com/2021/09/xml-js-jq-rss.html
import argparse, json, re
from warnings import warn
@ckhung
ckhung / json2erd.py
Last active March 14, 2024 09:40
[Generating ER Diagrams directly from *.sql files without even installing mysql](https://ckhung.medium.com/drawing-er-diagram-from-sql-file-alone-e7bef8cfe34b) / [在命令列上從 *.sql 檔直接產生 ER Diagram](https://newtoypia.blogspot.com/2022/04/sql-er-diagram.html)
#!/usr/bin/python3
# convert the output (as json) of
# https://github.com/iamcal/SQLParser
# to the input of
# https://github.com/BurntSushi/erd
# or to the input of
# https://github.com/ehne/ERDot
#
# For example, suppose you have ~/sakila-schema.sql from https://downloads.mysql.com/docs/sakila-db.tar.gz
@ckhung
ckhung / gj-voronoi.py
Last active October 13, 2023 03:02
compute the voronoi diagram of a set of points given in geojson format
#!/usr/bin/python3
# coding=utf-8
# -*- coding: utf-8 -*-
# example output at umap: https://umap.openstreetmap.fr/zh-tw/map/python3-gj-voronoipy-tkecgeojson_774525
import argparse, scipy, warnings, json, scipy.spatial, math
import numpy as np
def voronoi(data):
if type(data) is dict: