Skip to content

Instantly share code, notes, and snippets.

Avatar

Chao-Kuei Hung ckhung

View GitHub Profile
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',
@ckhung
ckhung / aasize.py
Last active Dec 3, 2021
print android app size as .csv: adb shell dumpsys diskstats | aasize.py
View aasize.py
#!/usr/bin/python3
# https://newtoypia.blogspot.com/2021/05/android-app-size.html
# 揪出手機上的腫脹軟體: android app 佔用空間大小散點圖
import argparse, fileinput, re, json
parser = argparse.ArgumentParser(
description='print android app size as .csv: adb shell dumpsys diskstats | aasize.py',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('files', nargs='*', help='files')
@ckhung
ckhung / xfadeffmpeg.py
Created May 22, 2021
generate ffmpeg command to do xfade
View xfadeffmpeg.py
#!/usr/bin/python3
# https://stackoverflow.com/a/66546687
# https://newtoypia.blogspot.com/2021/05/ffmpeg.html
# 一口氣串接爆多影片? ffmpeg 拯救可憐的手指
import argparse, subprocess, re
def gen_filter(segments, effect='fade', duration=0.3):
video_fades = ''
# fail! audio_fades = '\\\n[0:a]aresample=async=1;'
@ckhung
ckhung / json2erd.py
Last active Apr 2, 2022
[Generating ER Diagrams directly from *.sql files without even installing mysql](https://ckhung.medium.com/drawing-er-diagram-from-sql-file-alone-e7bef8cfe34b) / [在命令列上從 *.sql 檔直接產生 ER Diagram](https://newtoypia.blogspot.com/2022/04/sql-er-diagram.html)
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 May 24, 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