Skip to content

Instantly share code, notes, and snippets.

@RainJayTsai
RainJayTsai / tw_address_analysis.py
Last active November 29, 2023 02:15
regex to analysis tw address
try:
import re2 as re
except:
import re
pattern = '(?P<code>\d{5}|\d{3})?\s*(?P<country>[台臺]灣)?(?P<city>\D+?[縣市])(?P<district>\D+?(市區|鎮區|鎮市|[鄉鎮市區]))?(?P<village>\D+?[村里](?!路))?(?P<neighbor>\d+[鄰])?(?P<road>\D+?(村路|[路街道段]))?(?P<section>(\d|\D)?段)?(?P<lane>\d+巷)?(?P<alley>\d+弄)?(?P<no>\d+號?)?(?P<seq>[-之]\d+?(號))?(?P<floor>(((\D|\d)+樓)|((B|地下室?)\d+)))?(?P<other>.+)?'
addr_regex = re.compile(pattern)
cn_num = '一二三四五六七八九十'
cn_mapping = {k: str(v) for k, v in zip(list(cn_num),
S3_ACCESS_KEY_ID_GITLAB_BACKUP=<ACCESS_KEY>
S3_SECRET_ACCESS_KEY_GITLAB_BACKUP=<SECRET_KEY>
@RainJayTsai
RainJayTsai / convert_voc2createml.py
Created September 9, 2021 14:13 — forked from bezineb5/convert_voc2createml.py
Pascal VOC annotation to Apple createML annotations conversion tool
import argparse
import json
import logging
import pathlib
from xml.etree import ElementTree
log = logging.getLogger(__name__)
def _parse_arguments() -> argparse.Namespace:
@RainJayTsai
RainJayTsai / server.conf
Created June 7, 2021 03:04 — forked from laurenorsini/server.conf
OpenVPN configuration for /etc/openvpn/server.conf
local 192.168.2.0 # SWAP THIS NUMBER WITH YOUR RASPBERRY PI IP ADDRESS
dev tun
proto udp #Some people prefer to use tcp. Don't change it if you don't know.
port 1194
ca /etc/openvpn/easy-rsa/keys/ca.crt
cert /etc/openvpn/easy-rsa/keys/Server.crt # SWAP WITH YOUR CRT NAME
key /etc/openvpn/easy-rsa/keys/Server.key # SWAP WITH YOUR KEY NAME
dh /etc/openvpn/easy-rsa/keys/dh1024.pem # If you changed to 2048, change that here!
server 10.8.0.0 255.255.255.0
# server and remote endpoints
@RainJayTsai
RainJayTsai / Makefile
Created January 13, 2020 03:25 — forked from doubleyou/Makefile
grpc-gateway python example
GATEWAY_FLAGS := -I. -I/usr/local/include -I$(GOPATH)/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis -I/usr/local/include
GRPC_FLAGS := --python_out=. --grpc_python_out=.
code:
python -m grpc_tools.protoc $(GRPC_FLAGS) $(GATEWAY_FLAGS) *.proto
gw:
protoc $(GATEWAY_FLAGS) \
--go_out=Mgoogle/api/annotations.proto=github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis/google/api,plugins=grpc:. \
@RainJayTsai
RainJayTsai / build_tensorflow_in_docker
Created April 15, 2019 01:56
build tensorflow in docker the image is python:3.6 ( debian )
FROM python:3.6
# install bazel
# check the bazel version what you want to build tensroflw and change the VERSION
# https://www.tensorflow.org/install/source#linux
ARG BAZEL_VERSION 0.15.0
ARG TENSORFLOW_VERSION 1.12.0
RUN apt-get update; apt-get install openjdk-8-jdk
RUN set -ex && wget https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-installer-linux-x86_64.sh \
&& chmod +x bazel-${BAZEL_VERSION}-installer-linux-x86_64.sh ./bazel-${BAZEL_VERSION}-installer-linux-x86_64.sh \
@RainJayTsai
RainJayTsai / minimize_docker_python_application
Last active May 26, 2022 06:25
using docker BUILDKIT example, cache pip and mount temp whl to install. tensorflow python3.6
# syntax = docker/dockerfile:experimental
FROM python:3.6 as base
######################################
FROM base as builder
ENV PYTHONPATH=$PYTHONPATH:/install/lib/python3.6/site-packages/
# bind a wheel and install it
@RainJayTsai
RainJayTsai / compress.py
Created March 18, 2019 03:45
python sanic compress
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
### fork from https://github.com/subyraman/sanic_compress
import gzip
DEFAULT_MIME_TYPES = frozenset([
'text/html', 'text/css', 'text/xml',
'application/json',
@RainJayTsai
RainJayTsai / gmmhmm.py
Created February 20, 2019 06:29 — forked from kastnerkyle/gmmhmm.py
GMM-HMM (Hidden markov model with Gaussian mixture emissions) implementation for speech recognition and other uses
# (C) Kyle Kastner, June 2014
# License: BSD 3 clause
import scipy.stats as st
import numpy as np
class gmmhmm:
#This class converted with modifications from https://code.google.com/p/hmm-speech-recognition/source/browse/Word.m
def __init__(self, n_states):
self.n_states = n_states
@RainJayTsai
RainJayTsai / server.py
Created January 4, 2019 08:10 — forked from scturtle/server.py
python socks5 proxy server with asyncio (async/await)
#!/usr/bin/env python3.5
import socket
import asyncio
from struct import pack, unpack
class Client(asyncio.Protocol):
def connection_made(self, transport):
self.transport = transport
self.server_transport = None