Skip to content

Instantly share code, notes, and snippets.

View ckhung's full-sized avatar

Chao-Kuei Hung ckhung

View GitHub Profile
@ckhung
ckhung / sana.py
Last active January 31, 2019 15:03
stock analysis: (sana.py) 拿股票三維資料學習 pandas 的 multiindex
# https://newtoypia.blogspot.com/2019/01/pandas-multiindex.html
# 「拿股票三維資料學習 pandas 的 multiindex」
import re, os, time
import pandas as pd
import numpy as np
from numpy import NaN
from warnings import warn
datapath = os.environ['HOME']+'/stock/day'
@ckhung
ckhung / producer-consumer.py
Last active May 13, 2021 03:11
multiple producers and multiple consumers working on the same queue
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# slightly modified from https://stackoverflow.com/questions/53778588/two-condition-variables-attached-to-the-same-lock-different-behaviors-in-python
# 也請見 「概念性、宏觀視野的程序/執行緒同步機制總覽」
# https://newtoypia.blogspot.com/2017/12/synchronization.html
# Note: pip3 install colored
from threading import Thread, Lock, Condition
import time
@ckhung
ckhung / fst-ffmpeg.Dockerfile
Last active September 29, 2018 14:25
cpu-only Dockerfile for fast style transfer
# https://github.com/lengstrom/fast-style-transfer
FROM ckhung/fast-style-transfer:18C
# https://www.faqforge.com/linux/how-to-install-ffmpeg-on-ubuntu-14-04/
RUN add-apt-repository -y ppa:mc3man/trusty-media
RUN apt-get update
RUN apt-get -y dist-upgrade
RUN apt-get -y install ffmpeg
RUN pip install moviepy
# possible ramifications on proxmox:
@ckhung
ckhung / 371.conf
Last active November 20, 2018 20:35
/etc/pve/lxc conf file for a proxmox lxc to be used as a docker host
# https://newtoypia.blogspot.com/2018/09/proxmox-lxc-storage.html
# 幫 proxmox 的 lxc 擴充硬碟
arch: amd64
hostname: whale
memory: 1024
mp0: local-zfs:subvol-371-disk-2,mp=/var/lib/docker,size=10G
net0: bridge=vmbr35,hwaddr=ff:ff:ff:ff:ff:71,ip=192.168.35.99/24,name=eth0,type=veth
onboot: 0
ostype: debian
rootfs: local-zfs:subvol-371-disk-1,size=4G
@ckhung
ckhung / bus-pos.php
Created January 18, 2018 13:09
從 PTX (公共運輸整合資訊流通服務平台) 開放資料產生 geojson 檔
<?php
# 範例參數:
# bus-pos.php?city=Taichung&rid=151
# 其他城市名稱請見 http://ptx.transportdata.tw/ptx/Download/API_URI_Convention%E6%96%87%E4%BB%B6_v1.pdf 第 4 頁
parse_str($_SERVER["QUERY_STRING"], $Q);
$time_string = gmdate('D, j M Y H:i:s') . ' GMT';
$signature = base64_encode(hash_hmac("sha1", "x-date: $time_string", $_SERVER['PTX_KEY'], true));
@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
@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 / gj-voronoi.py
Last active October 13, 2023 03:02
compute the voronoi diagram of a set of points given in geojson format
#!/usr/bin/python3
# coding=utf-8
# -*- coding: utf-8 -*-
# example output at umap: https://umap.openstreetmap.fr/zh-tw/map/python3-gj-voronoipy-tkecgeojson_774525
import argparse, scipy, warnings, json, scipy.spatial, math
import numpy as np
def voronoi(data):
if type(data) is dict:
@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 / similar-distro.gnuplot
Last active October 15, 2017 09:41
draw a few similar gaussian distributions
#!/usr/bin/gnuplot
# http://gnuplot.sourceforge.net/demo/transparent.html
Gauss(x,mu,sigma) = 1./(sigma*sqrt(2*pi)) * exp( -(x-mu)**2 / (2*sigma**2) )
set xrange [-4:4]
plot \
Gauss(x,0.03,1.02) title '', \
Gauss(x,-0.05,1.03) title '', \
Gauss(x,0.05,0.98) title '', \
Gauss(x,0.02,0.97) title '', \
Gauss(x,-0.02,0.96) title ''