Skip to content

Instantly share code, notes, and snippets.

View ceshine's full-sized avatar

CeShine Lee ceshine

View GitHub Profile
@ceshine
ceshine / convert.py
Created July 17, 2019 05:03
A simple script to convert markdown image specification to hugo shortcode (result is automatically copied to clipboard)
from subprocess import Popen, PIPE
def image_markdown_conversion():
try:
while True:
text = input("Input:").strip()
brackets, split_point = 1, 0
description = ""
assert len(text) > 5, "wrong format!"
@ceshine
ceshine / temporal_block.py
Last active November 25, 2018 15:03
Temporal Block (for TCNs)
class TemporalBlock(tf.layers.Layer):
def __init__(self, n_outputs, kernel_size, strides, dilation_rate, dropout=0.2,
trainable=True, name=None, dtype=None,
activity_regularizer=None, **kwargs):
super(TemporalBlock, self).__init__(
trainable=trainable, dtype=dtype,
activity_regularizer=activity_regularizer,
name=name, **kwargs
)
self.dropout = dropout
@ceshine
ceshine / zip_and_base64encode.py
Created November 19, 2018 09:59
Useful script for importing your own packages into Kaggle Kernels
from zipfile import ZipFile
import zipfile
from pathlib import Path
import base64
import sys
import io
def write_folder(zfile: ZipFile, dir_path: Path, prefix: str = ""):
assert dir_path.is_dir()
@ceshine
ceshine / extract.py
Last active October 29, 2018 04:01
Scripts to scrape and extract data from the Tourism Bureau of Taiwan
# WARNING: this script is out-dated since the last update of the Tourism Bureau website.
from pathlib import Path
import pandas as pd
SCHEMAS = [
(201201, "schema/residence-2012-01.csv"),
(201101, "schema/residence-2011-01.csv")
]
DATA_FILE_PATTERN = "raw_data/{year}-{month}.xls"
@ceshine
ceshine / keras-fashion-mnist-gpu.ipynb
Created October 8, 2018 08:53
Keras Fashion MNIST - GPU
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ceshine
ceshine / keras-fashion-mnist-cpu.ipynb
Created October 8, 2018 08:48
Keras Fashion MNIST - CPU
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ceshine
ceshine / keras-fashion-mnist-tpu.ipynb
Created October 8, 2018 08:53
Keras Fashion MNIST - TPU
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ceshine
ceshine / plotting.R
Created October 8, 2018 10:33
Plotting Script for the TPU blog psot
library(ggplot2)
library(ggthemes)
dat <- data.frame(
name = c("CPU", "GPU", "TPU"),
time = c(3 * 3600 + 6 * 60 + 4, 3 * 60 + 16, 1 * 60 + 42)
)
dat$log_time = log(dat$time)
ggplot(data=dat, aes(x=name, y=log_time)) +
@ceshine
ceshine / causal_conv1d.py
Created April 2, 2018 01:03
Causal Convolution 1D
import tensorflow as tf
class CausalConv1D(tf.layers.Conv1D):
def __init__(self, filters,
kernel_size,
strides=1,
dilation_rate=1,
activation=None,
use_bias=True,
kernel_initializer=None,