Skip to content

Instantly share code, notes, and snippets.

Avatar

Chao-Kuei Hung ckhung

View GitHub Profile
View json2erd.py
#!/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 / ms2sqlite.sh
Last active Feb 19, 2021
a hackish script to convert this MS sql server script: https://www.dofactory.com/sql to a sqlite script
View ms2sqlite.sh
#!/bin/sh
# a hackish script to convert this MS sql server script:
# https://www.dofactory.com/sql
# to a sqlite script
#
# usage:
# 1. ./ms2sqlite.sh sample-model.sql > model-sqlite.sql
# 2. edit model-sqlite.sql and manually:
# 2.1 remove all the "if exists ..."
@ckhung
ckhung / nextwindow.py
Created Feb 15, 2021
surrender the keyboard focus to the next window. to be called from ~/.xbindkeysrc
View nextwindow.py
#!/usr/bin/python3
# window manager must not enable auto-focusing!
# 視窗管理員不可啟用 「焦點跟隨滑鼠」!
import re, subprocess
F = open('/tmp/nextwindow.log', 'a')
winlist = subprocess.run(['wmctrl', '-l'], stdout=subprocess.PIPE)
winlist = winlist.stdout.decode('utf-8').split('\n')
winlist = [ re.sub('(\S+\s+){3}', '', w) for w in winlist ]
@ckhung
ckhung / elecxls2csv.py
Last active Jan 27, 2020
2020立委選舉統計資料轉檔
View elecxls2csv.py
#!/usr/bin/python3
# 立委選舉統計資料轉檔
# 詳見 https://newtoypia.blogspot.com/2020/01/xlsxlsx-csv.html
import sys, re, argparse
import pandas as pd
from numpy import isnan
from warnings import warn
@ckhung
ckhung / plk-ms.perl
Last active Sep 2, 2019
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
# lynx -dump plurk/3202.html | ~/plk-ms.perl | sort > plurk-summary.txt
@ckhung
ckhung / tf-sprec.ipynb
Created Aug 3, 2019
running (in google colab) the speech recognition example from tensorflow source code
View tf-sprec.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ckhung
ckhung / subsample.py
Created Jul 27, 2019
randomly pick n samples from each word/directory
View subsample.py
#!/usr/bin/python3
# randomly pick n samples from each word/directory
# of speech_commands_v0.02/ data set:
# https://download.tensorflow.org/data/speech_commands_v0.02.tgz
# usage: subsample.py -f -n 300 * > ~/list.txt
# tar czf ~/dsc.tgz $(cat ~/list.txt)
import argparse, os, random
from warnings import warn
@ckhung
ckhung / aic.ipynb
Last active Jul 13, 2019
colab test: automatic image colorization
View aic.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ckhung
ckhung / default-ssl.conf
Last active May 12, 2019
apache2 config to enable wildcard ssl certificate
View default-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin 貴哥的電子郵件信箱
DocumentRoot /var/www/html/abc
ServerName abcdef.frdm.info
ErrorLog ${APACHE_LOG_DIR}/abcdef/error.log
CustomLog ${APACHE_LOG_DIR}/abcdef/access.log combined
Header set Access-Control-Allow-Origin "*"
SSLCertificateFile /etc/letsencrypt/live/frdm.info/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/frdm.info/privkey.pem
@ckhung
ckhung / airtw-scraper.js
Last active Dec 9, 2020
puppeteer 簡單互動範例: 下載環保署空氣品質監測網資料
View airtw-scraper.js
#!/usr/bin/env node
// http://toddhayton.com/2018/08/01/scraping-with-puppeteer/
// airtw-scraper.js https://www.cwb.gov.tw/V7/observe/real/46757.htm > a.htm
const homedir = require('os').homedir();
const puppeteer = require(homedir + '/node_modules/puppeteer');
const url = 'https://airtw.epa.gov.tw/';
async function main() {
const browser = await puppeteer.launch();