Skip to content

Instantly share code, notes, and snippets.

View ckhung's full-sized avatar

Chao-Kuei Hung ckhung

View GitHub Profile
View bus-pos.php
<?php
# 範例參數:
# bus-pos.php?line=Taichung/151
# 其他城市名稱請見
$QS = array_key_exists('QUERY_STRING', $_SERVER) ? $_SERVER["QUERY_STRING"] : '';
parse_str($QS, $Q);
# $Q = array(
# 'line' => 'Taichung/151'
# );
@ckhung
ckhung / plk-ms.perl
Last active August 3, 2023 08:46
From a plurk mail in html format, generate a summary
View plk-ms.perl
#!/usr/bin/perl -w
# plurk mail summary
# plurk-sent mail
# => *.mbox (by gmail)
# => *.html (by hypermail)
# => *.txt (by lynx -dump)
# => plk-ms.perl
# e.g.
# hypermail -m plurk.mbox -d plurk
# for f in plurk/????.html ; do lynx -dump $f | perl plk-ms.perl ; done | sort > ~/plurk-summary.txt
@ckhung
ckhung / linespector.py
Last active June 24, 2023 09:05
line inspector w/ selenium
View linespector.py
# Enter a python3 interpreter. Then do this:
# exec(open('linespector.py').read())
# And try, line by line, the commented out code at the end.
# Wonderful reference:
# https://cosmocode.io/how-to-connect-selenium-to-an-existing-browser-that-was-opened-manually/
# ( found from here: https://stackoverflow.com/a/70088095 )
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
@ckhung
ckhung / line-sel.py
Last active May 15, 2023 07:13
Use selenium to read messages from the "line" messaging app as an extension of chrome.
View line-sel.py
# This is an experimental piece of code for reading messages
# from the "line" messaging app as an extension of chrome.
# https://chrome.google.com/webstore/detail/line/ophjlpahpchlmihnnnihgmmeilfjmjjc?hl=zh-TW
# My linux is LMDE 5 (elsie), and my chromium is 113.0.5672.63,
# directly installed with apt install.
# I have also done:
# pip3 install selenium webdriver-manager beautifulsoup4
# To use this program:
# 0. Create a line account if you don't have one.
# Note: Line is control-hungry.
@ckhung
ckhung / country-codes.csv
Last active April 28, 2023 12:05
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
iso3 m49 owid_name other_name reg1 reg2 continent region_type is_historical defined_by
ABW 533 Aruba Aruba Caribbean Latin America and the Caribbean North America country False owid
AFG 4 Afghanistan Afghanistan Southern Asia Asia country False owid
AGO 24 Angola Angola Middle Africa Sub-Saharan Africa Africa country False owid
AIA 660 Anguilla Anguilla Caribbean Latin America and the Caribbean North America country False owid
ALA 248 Åland Islands Aland Islands Northern Europe Europe country False owid
ALB 8 Albania Albania Southern Europe Europe country False owid
AND 20 Andorra Andorra Southern Europe Europe country False owid
ANT Netherlands Antilles country True owid
ARE 784 United Arab Emirates United Arab Emirates Western Asia Asia country False owid
@ckhung
ckhung / knight.py
Last active April 4, 2023 05:19
knight's tour
View knight.py
#!/usr/bin/python3
import argparse, sys, os, atexit
from ansi import cursor
from ansi.color import fg, bg, fx
from time import sleep
# manual fix for ansi.cursor.erase
from ansi.sequence import sequence
cursor.erase = sequence('2J')
@ckhung
ckhung / ctimer.py
Last active March 24, 2023 03:05
a timer shown at the upper right corner of the terminal w/ chime
View ctimer.py
#!/usr/bin/python3
import argparse, sys
from time import sleep
from ansi.color import fg, bg, fx
import ansi.cursor as cr
# from playsound import playsound
def show_msg(msg):
seq = (
@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
View gj-area-centroid.py
#!/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'
View db-iconv.py
#!/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
View batting.csv
year Derek Derek_hit David David_hit
1995 48 12 411 104
1996 582 183 140 45