Skip to content

Instantly share code, notes, and snippets.

View ckhung's full-sized avatar

Chao-Kuei Hung ckhung

View GitHub Profile
@ckhung
ckhung / gj-area-centroid.py
Last active September 2, 2022 14:27
add an "area" field and a "centroid" field to feature.geometry for (multi)polygons in a geojson file
#!/usr/bin/python
# coding=utf-8
# -*- coding: utf-8 -*-
# This script adds an "area" field (in square meters)
# and a "centroid" field to feature.geometry
# for Polygon's and MultiPolygon's in a geojson file.
# Usage example:
# ./gj-area-centroid.py university.geojson
@ckhung
ckhung / db-iconv.py
Created August 30, 2022 03:28
find deal-breakers for 'iconv -f utf8 -t big5'
#!/usr/bin/python3
# find deal-breakers for 'iconv -f utf8 -t big5'
# 例: 清冠一號中醫診所清單裡面有一些簡體字「号」「络」和放大鏡符號等等,
# 會造成 iconv 從 utf8 轉 big5 時失敗。 這個程式可以列出有哪幾列有問題。
# https://docs.google.com/spreadsheets/d/e/2PACX-1vQjf_HNeEZKM-XJX-q5v4cfNrB3kcv4gOT8kFbV9rurfoX_H5Qv9112Pv0PgYNFSzbReyNlQkLrJib3/pubhtml#
# 使用方式: python3 db-iconv 某中文utf8編碼檔
# 每列呼叫一次 iconv, 有點慢
import argparse, re
@ckhung
ckhung / batting.csv
Created May 15, 2022 13:21
juxtaposed "binary" Marimekko charts, good for visualizing Simplson's paradox invloving some "hit" ratios
year Derek Derek_hit David David_hit
1995 48 12 411 104
1996 582 183 140 45
@ckhung
ckhung / ptx-example.bash
Last active February 13, 2022 10:02
PTX (公共運輸整合資訊流通服務平臺) 的 bash 查詢範例
#!/bin/bash
# PTX (公共運輸整合資訊流通服務平臺) 的 bash 查詢範例
# 詳見: https://newtoypia.blogspot.tw/2018/01/ptx-bash-php.html
# 需要安裝 httpie 及 openssl 等套件
# 使用方式:
# ./ptx-example.bash 'https://ptx.transportdata.tw/MOTC/v2/Bus/DisplayStopOfRoute/City/Taichung/151?%24format=JSON'
# 或
# ./ptx-example.bash 'https://ptx.transportdata.tw/MOTC/v2/Bus/DisplayStopOfRoute/City/Taichung/151?%24format=JSON' 'Thu, 10 Feb 2022 09:07:10 GMT'
# 會印出 (1) http 指令 (2) 查詢結果
# (3) 查詢用的時間戳記及簽章 (在五分鐘內可供再次使用)
@ckhung
ckhung / ptx-example.php
Last active February 10, 2022 09:31
PTX (公共運輸整合資訊流通服務平臺) 的 php 查詢範例
<?php
# PTX (公共運輸整合資訊流通服務平臺) 的 php 查詢範例
# 詳見: https://newtoypia.blogspot.tw/2018/01/ptx-bash-php.html
# 使用方式:
# php ptx-example.php 'https://ptx.transportdata.tw/MOTC/v2/Bus/DisplayStopOfRoute/City/Taichung/151?%24format=JSON'
# 或
# php ptx-example.php 'https://ptx.transportdata.tw/MOTC/v2/Bus/DisplayStopOfRoute/City/Taichung/151?%24format=JSON' 'Thu, 10 Feb 2022 09:07:10 GMT'
# 本程式不需要任何外加套件; 但關於 「如何保護私密資訊」, 請見
# http://phpsec.org/projects/guide/3.html
#!/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 / pfs.py
Last active January 12, 2022 11:42
priority first search on a graphviz dot file
#!/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
@ckhung
ckhung / gecko.php
Last active December 5, 2021 04:05
generate a csv listing of your favorite cryptocurrencies, suitable for importing into a google sheet
<?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 December 3, 2021 02:37
pdmenu example
# 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 December 3, 2021 02:33
multicast netcat
#!/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