Skip to content

Instantly share code, notes, and snippets.

View ckhung's full-sized avatar

Chao-Kuei Hung ckhung

View GitHub Profile
@ckhung
ckhung / ms2sqlite.sh
Last active May 24, 2021 03:03
a hackish script to convert this MS sql server script: https://www.dofactory.com/sql to a sqlite script
#!/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 February 15, 2021 02:43
surrender the keyboard focus to the next window. to be called from ~/.xbindkeysrc
#!/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 January 27, 2020 09:45
2020立委選舉統計資料轉檔
#!/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 August 3, 2023 08:46
From a plurk mail in html format, generate a summary
#!/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 / tf-sprec.ipynb
Created August 3, 2019 09:18
running (in google colab) the speech recognition example from tensorflow source code
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 July 27, 2019 06:56
randomly pick n samples from each word/directory
#!/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 July 13, 2019 07:46
colab test: automatic image colorization
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 07:15
apache2 config to enable wildcard ssl certificate
<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 December 9, 2020 23:59
puppeteer 簡單互動範例: 下載環保署空氣品質監測網資料
#!/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();
@ckhung
ckhung / pptscraper.js
Last active February 15, 2019 02:17
web scraper capable of downloading javascript-generated content using puppeteer.
#!/usr/bin/env node
// http://toddhayton.com/2018/08/01/scraping-with-puppeteer/
// usage example:
// ./pptscraper.js https://www.cwb.gov.tw/V7/observe/real/46744.htm > a.htm
const homedir = require('os').homedir();
const puppeteer = require(homedir + '/node_modules/puppeteer');
const url = process.argv[2];
const sel = process.argv[3];
async function main() {