Skip to content

Instantly share code, notes, and snippets.

View juwencheng's full-sized avatar
🏠
Working from home

Juwencheng juwencheng

🏠
Working from home
View GitHub Profile
@juwencheng
juwencheng / git-fancy-pancy.sh
Created April 13, 2016 09:32 — forked from sverweij/git-fancy-pancy.sh
Fancy command line git history
# shamelessly copied from @d
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
@juwencheng
juwencheng / example_go_filepath_Walk.go
Created January 9, 2017 06:18
example of filepath.Walk function
package main
import (
"fmt"
"os"
"path/filepath"
)
func main() {
walfFn := func(path string, info os.FileInfo, err error) error {
@juwencheng
juwencheng / test_overwrite_file.go
Last active January 10, 2017 07:49
将内容以覆盖的形式写入文件中
package main
import (
"io/ioutil"
"time"
)
func main() {
counter := 0
go func() {
@juwencheng
juwencheng / compress.go
Created January 10, 2017 13:19 — forked from iamralch/compress.go
ZIP archives in Golang
import (
"archive/zip"
"io"
"os"
"path/filepath"
"strings"
)
func zipit(source, target string) error {
zipfile, err := os.Create(target)
@juwencheng
juwencheng / measure_memory_with_go.go
Created January 12, 2017 03:02
通过pid查看消耗内存
// ref: http://stackoverflow.com/questions/31879817/golang-os-exec-realtime-memory-usage?noredirect=1&lq=1
func calculateMemory(pid int) (uint64, error) {
f, err := os.Open(fmt.Sprintf("/proc/%d/smaps", pid))
if err != nil {
return 0, err
}
defer f.Close()
res := uint64(0)
@juwencheng
juwencheng / pickle_tutorial.py
Created February 16, 2017 01:13
通过Pickle保存和加载数据
import pickle
# save object to pickle
file = open('data.pickle', 'wb') # `b` abbr of binary
pickle.dump({'key':'value'}, file)
file.close()
# load object from pickle
file = open('data.pickle', 'rb')
dict = pickle.load(file)
file.close()
@juwencheng
juwencheng / deep_neural_network_with_hidden_layer.py
Last active May 11, 2017 06:39
Create a simple deep neural network just with one hidden layer. reached 95.1% accuracy
from tensorflow.examples.tutorials.mnist import input_data
# 如果 one_hot 设为 False , 标签则会输出数字
mnist = input_data.read_data_sets("../MNIST_data", one_hot=True)
import tensorflow as tf
batch_size = 50
display_step = 2
learning_rate = 0.03
training_epochs = 30
@juwencheng
juwencheng / conv_network.py
Last active May 11, 2017 06:45
convolution network , input-conv-maxpool-fc-output
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
# input
def neural_input(image_shape, name="x"):
return tf.placeholder(tf.float32, [None, *image_shape], name=name)
def neural_label(n_classes, name="labels"):
return tf.placeholder(tf.float32, [None, n_classes], name=name)
@juwencheng
juwencheng / floyd-tutorial-hello.py
Last active May 12, 2017 01:51
floyd tutorial demo
# coding=utf-8
print("Hello World!")
print("你好!")
@juwencheng
juwencheng / min-char-rnn.py
Last active May 13, 2017 05:48 — forked from karpathy/min-char-rnn.py
Minimal character-level language model with a Vanilla Recurrent Neural Network, in Python/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)