This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import glob | |
filenames = glob.glob('file/path') | |
for i, file in enumerate(filenames) | |
os.rename(file, "new/file/name/%02d" % i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class getSentences(object): | |
def __init__(self, dirname): | |
self.dirname = dirname | |
def split_paragraph(self, raw): | |
def is_punt(char): | |
stop = ['。', '!', '…', '?'] | |
return char in stop # 判断是否要分句的标点符号 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
OlderNewer