Skip to content

Instantly share code, notes, and snippets.

View huangziwei's full-sized avatar

Ziwei Huang huangziwei

View GitHub Profile
@huangziwei
huangziwei / markdown_furigana.py
Last active March 2, 2016 08:55
a python script for writing furigana in markdown
import fileinput
import re
import sys
```
eg. [東京]{とうきょう} -> <ruby>東京<rp>(</rp><rt>とうきょう</rt><rp>)</rp></ruby>
```
for line in fileinput.input(sys.argv[1:], inplace=True):
line = re.sub(r'\[(.*?)\]\{(.*?)\}', r'<ruby>\1<rp>(</rp><rt>\2</rt><rp>)</rp></ruby>', line.rstrip())
print(line)
@huangziwei
huangziwei / gbk-to-utf8.py
Created January 25, 2016 08:39
.txt 乱码解决方案
import sys
import codecs
input_file = sys.argv[1]
with codecs.open(input_file, 'r', encoding='gbk') as f:
out_name = 'new' + f.name
with codecs.open(input_file, 'w', encoding='utf-8') as o:
# -*- coding: utf-8 -*-
from __future__ import print_function
# import commands
import subprocess
import sys
import numpy as np
from termcolor import colored
### Get result from `fping`
@huangziwei
huangziwei / rename_files.py
Created March 1, 2016 04:49
rename (multiple )files
import os
import glob
filenames = glob.glob('file/path')
for i, file in enumerate(filenames)
os.rename(file, "new/file/name/%02d" % i)
class getSentences(object):
def __init__(self, dirname):
self.dirname = dirname
def split_paragraph(self, raw):
def is_punt(char):
stop = ['。', '!', '…', '?']
return char in stop # 判断是否要分句的标点符号
import re
def clean_txt(raw):
raw = re.sub('[A-Za-z]+', '', raw) # 去英文
raw = re.sub('\d+(\.)?\d?', '', raw) # 去数字
raw = re.sub('\W+', '', raw) # 去标点
return raw
@huangziwei
huangziwei / rois_rot.py
Created May 2, 2017 15:42
rotate coordinates of rois
def rotate_roi(d):
ang_deg = d['wParamsNum'][31] # ratoate angle (degree)
ang_rad = ang_deg * np.pi / 180 # ratoate angle (radian)
d_rois = d['ROIs']
d_rois_rot = scipy.ndimage.interpolation.rotate(d_rois, ang_deg)
(shift_x, shift_y) = 0.5 * (np.array(d_rois_rot.shape) - np.array(d_rois.shape))
(cx, cy) = 0.5 * np.array(d_rois.shape)
@huangziwei
huangziwei / rois_rot.py
Created May 2, 2017 15:42
rotate coordinates of rois
def rotate_roi(d):
ang_deg = d['wParamsNum'][31] # ratoate angle (degree)
ang_rad = ang_deg * np.pi / 180 # ratoate angle (radian)
d_rois = d['ROIs']
d_rois_rot = scipy.ndimage.interpolation.rotate(d_rois, ang_deg)
(shift_x, shift_y) = 0.5 * (np.array(d_rois_rot.shape) - np.array(d_rois.shape))
(cx, cy) = 0.5 * np.array(d_rois.shape)
@huangziwei
huangziwei / roi_func.py
Created May 9, 2017 12:41
some functions for roi detection
def load_h5_data(file_name):
with h5py.File(file_name,'r') as f:
return {key:f[key][:] for key in list(f.keys())}
def detect_soma_centroid(M):
"""
detect the coordinate of soma on stack image.
Return
#!/bin/bash
git clone https://github.com/pyenv/pyenv .pyenv
echo 'export PYENV_ROOT="/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
exec $SHELL
pyenv install miniconda3-latest
pyenv shell miniconda3-latest
conda install numpy scipy jupyter matplotlib scikit-learn