Skip to content

Instantly share code, notes, and snippets.

Avatar

Chao-Kuei Hung ckhung

View GitHub Profile
@ckhung
ckhung / batting.csv
Created May 15, 2022
juxtaposed "binary" Marimekko charts, good for visualizing Simplson's paradox invloving some "hit" ratios
View batting.csv
year Derek Derek_hit David David_hit
1995 48 12 411 104
1996 582 183 140 45
@ckhung
ckhung / country-codes.csv
Last active May 22, 2022
Prepend the 3-letter ISO country code and continent name to every line, except the 1st line, of a csv file containing country names
View country-codes.csv
No name iso m49 reg1 reg2 continent
1 Afghanistan AFG 004 Southern Asia Asia
2 Åland Islands ALA 248 Northern Europe Europe
3 Albania ALB 008 Southern Europe Europe
4 Algeria DZA 012 Northern Africa Africa
5 American Samoa ASM 016 Polynesia Oceania
6 Andorra AND 020 Southern Europe Europe
7 Angola AGO 024 Middle Africa Sub-Saharan Africa Africa
8 Anguilla AIA 660 Caribbean Latin America and the Caribbean North America
9 Antarctica ATA 010 Antarctica Antarctica
@ckhung
ckhung / pfs.py
Last active Jan 12, 2022
priority first search on a graphviz dot file
View pfs.py
#!/usr/bin/python3
# See this article for more explanations:
# https://ckhung.medium.com/4-in-1-priority-first-search-in-python-bfs-dfs-prims-and-dijkstra-s-algorithms-4e9fe8ccba87
# pip3 install pqdict pydot networkx
# python3 pfs.py -a dijk -0 E t02.dot
# python3 pfs.py -a prim -0 G t02.dot
# https://github.com/nvictus/priority-queue-dictionary
View bip_demo.py
#!/usr/bin/python3
# https://medium.com/mycrypto/the-journey-from-mnemonic-phrase-to-address-6c5e86e11e14
# pip3 install bip_utils
# python3 bip_demo.py
# For the 1st example, private key and address of path0
# have been verified using exodus wallet.
# For the 2nd example, the computed master key does not match the article...?
# If you have a private key stored in a file named priv_key_file.txt
# this program will also create a derived pair of keys from it
# as a 3rd example.
@ckhung
ckhung / gecko.php
Last active Dec 5, 2021
generate a csv listing of your favorite cryptocurrencies, suitable for importing into a google sheet
View gecko.php
<?php
// usage:
// http://.../gecko.pgp??q=bitcoin,ethereum,solana,polkadot
// or
// http://.../gecko.pgp??q=mycrypto.csv
// where mycrypto.csv contains the id of a coin on each line.
// Find the exact id of your coin in this list:
// https://api.coingecko.com/api/v3/coins/list
// See this doc for more info:
@ckhung
ckhung / example.pdmenu
Last active Dec 3, 2021
pdmenu example
View example.pdmenu
# https://newtoypia.blogspot.com/2021/09/pdmenu.html
# pdmenu 幫麻瓜製作常用功能文字選單
title:貴哥的 pdmenu 教學範例
color:desktop:yellow:black
color:menu:yellow:blue
color:menuhot:cyan:blue
color:unselmenu:green:black
color:selbar:black:yellow
@ckhung
ckhung / mcnc.py
Last active Dec 3, 2021
multicast netcat
View mcnc.py
#!/usr/bin/python3
# multicast netcat
# https://newtoypia.blogspot.com/2021/09/netcat.html
# 齊步走! 用 netcat 同步指揮教室裡的所有電腦
import argparse, sys, re, readline
from warnings import warn
from subprocess import Popen, PIPE
@ckhung
ckhung / _voicmd.py
Last active Sep 4, 2021
primitive voice command interface w/ pocketsphinx as backend
View _voicmd.py
#!/usr/bin/python3
import argparse, os, re
from warnings import warn
import subprocess
parser = argparse.ArgumentParser(
description='invoke pocketsphinx and produce keystrokes',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('-k', '--kwokfn', type=str, default='',
@ckhung
ckhung / prj2html.py
Created Sep 4, 2021
把 「xml-js 所轉出的噗浪 rss => json」 再轉成 html
View prj2html.py
#!/usr/bin/python3
# for f in *.xml ; do xml-js $f --compact | jq . > ${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
View odsfiles2col.py
#!/usr/bin/python3
# https://github.com/pyexcel/pyexcel-ods/issues/41
# pyexcel-ods issue: use "<text:p>" instead of "<text:line-break/>" for newlines (line breaks) in cells
import argparse, re, sys, json
from pyexcel_ods3 import save_data
from warnings import warn
parser = argparse.ArgumentParser(
description='read many text files into two columns of an ods file, with filenames as the key column and contents as the value column',