Skip to content

Instantly share code, notes, and snippets.

View princewang1994's full-sized avatar
🤔

Prince Wang princewang1994

🤔
View GitHub Profile
@princewang1994
princewang1994 / tmux.sh
Last active March 21, 2020 12:43 — forked from B-Galati/tmux.sh
tmux脚本示例
#!/bin/bash
tmux has-session -t ssh
if [ $? != 0 ]
then
tmux new-session -d -s ssh // 后台新建一个session
tmux split-window -h // 切割窗口
tmux select-pane -t 0 // 选择0号窗口
tmux send-keys "ssh zcmlc@host" C-m //向选择的窗口发送指令
tmux send-keys "cd /home/zcmlc/go/src/pro" C-m
tmux send-keys "ctl tail -f log" C-m
@princewang1994
princewang1994 / Makefile
Created June 30, 2018 14:11
C++使用Makefile编译
# 设置make命令入口
default_target: all
# 静态库build命令 make hello
hello:
g++ -c MyClass.cpp
ar -crv libhello.a MyClass.o
# all依赖hello
all: hello
@princewang1994
princewang1994 / matMul.cu
Last active November 4, 2018 15:19
简单的cuda矩阵相乘代码
#include <stdio.h>
#include <cuda_runtime.h>
#include <helper_cuda.h>
#include <iostream>
struct Matrix
{
int width;
int height;
float *elements;
@princewang1994
princewang1994 / test_getopt.sh
Last active August 8, 2020 04:16
bash使用getopts/getopt处理选项
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->
#!/bin/bash
# A small example program for using the new getopt(1) program.
# This program will only work with bash(1)
# An similar program using the tcsh(1) script language can be found
# as parse.tcsh
# Example input and output (from the bash prompt):
# ./parse.bash -a par1 'another arg' --c-long 'wow!*\?' -cmore -b " very long "
@princewang1994
princewang1994 / tf_xavier.py
Last active November 4, 2018 16:32
tensorflow实现的xavier初始化
def xavier_init(size):
in_dim = size[0]
xavier_stddev = 1. / tf.sqrt(in_dim / 2.)
return tf.random_normal(shape=size, stddev=xavier_stddev)
@princewang1994
princewang1994 / argparse.py
Last active November 8, 2018 08:29
Python中argparser的使用方法
import numpy as np
import argparse
def main():
parser = argparse.ArgumentParser()
# Positional arguments, must be parse
parser.add_argument('words', type=str, help='Contents you want to say')
# Add argment for enumerable arguments like follow using `choice` keyword
@princewang1994
princewang1994 / min-char-rnn.py
Last active November 4, 2018 16:30 — forked from karpathy/min-char-rnn.py
用最少的代码来实现一个rnn语言模型(numpy)
"""
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy)
BSD License
"""
import numpy as np
# data I/O
data = open('input.txt', 'r').read() # should be simple plain text file
chars = list(set(data))
data_size, vocab_size = len(data), len(chars)
@princewang1994
princewang1994 / pkl_dump.py
Last active November 8, 2018 08:27
pickle存储和读取object
# 如果是python2需要用cpickle
import pickle
your_data = {'foo': 'bar'}
# Store data (serialize)
with open('filename.pickle', 'wb') as handle:
pickle.dump(your_data, handle, protocol=pickle.HIGHEST_PROTOCOL)
@princewang1994
princewang1994 / PIL_compress.py
Last active March 11, 2017 14:14
PIL compress image
import Image
import os
import os.path
import sys
path = sys.argv[1]
small_path = (path[:-1] if path[-1]=='/' else path) +'_small'
if not os.path.exists(small_path):
os.mkdir(small_path)
for root, dirs, files in os.walk(path):
for f in files:
@princewang1994
princewang1994 / otsu.py
Last active November 8, 2018 08:32
在python中使用OSTU算法
## 在python中使用OSTU算法
import matplotlib.pyplot as plt
from skimage import data
try:
from skimage import filters
except ImportError:
from skimage import filter as filters
from skimage import exposure