Skip to content

Instantly share code, notes, and snippets.

View helinwang's full-sized avatar

Helin Wang helinwang

  • Bay Area
View GitHub Profile
@helinwang
helinwang / tf_idf.go
Last active January 27, 2016 08:14
calculate max tfidf of each word in text corpus (given directory) in golang
package main
import (
"flag"
"fmt"
"io/ioutil"
"math"
"os"
"sort"
"strings"
@helinwang
helinwang / gist.go
Last active December 11, 2016 16:27
save and load tensorflow tensors using tensorflow golang api
// Save:
outTensor, err := tf.NewTensor(filename)
if err != nil {
return err
}
_, err = session.Run(
map[tf.Output]*tf.Tensor{
graph.Operation("save/Const").Output(0): outTensor,
},
nil,
@helinwang
helinwang / main.go
Created July 27, 2017 07:21
go net/rpc graceful shutdown
package main
import (
"context"
"flag"
"log"
"net/http"
"net/rpc"
"os"
"os/signal"
@helinwang
helinwang / init.el
Last active November 29, 2017 20:04
emacs rtags configuration
(menu-bar-mode -1)
(global-set-key "\M-g" 'goto-line)
(global-set-key "\M-." 'rtags-find-symbol-at-point)
(global-set-key "\M-," 'rtags-location-stack-back)
(global-set-key (kbd "M-]") 'next-error) ; Go to next error (or msg)
(global-set-key (kbd "M-[") 'previous-error) ; Go to previous error or msg
(global-set-key (kbd "M-m") 'rtags-find-references-at-point)
(require 'package)
@helinwang
helinwang / run.sh
Created December 20, 2017 23:57
Run docker with nvidia-gpu without nvidia-docker
ls /dev/nvidia* | xargs -I{} echo '--device {}:{}'
docker run -v /var/lib/nvidia-docker/volumes/nvidia_driver/384.98:/driver --device /dev/nvidia0:/dev/nvidia0 --device /dev/nvidiactl:/dev/nvidiactl --device /dev/nvidia-uvm:/dev/nvidia-uvm --device /dev/nvidia-uvm-tools:/dev/nvidia-uvm-tools -it -v `pwd`:/data nvidia/cuda:8.0-runtime-ubuntu16.04 bash
export PATH=$PATH:/driver/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/driver/lib64/
@helinwang
helinwang / program_summary.py
Created February 16, 2018 23:03
Print PaddlePaddle Operators and Blocks
def program_summary(program):
print("--------------------")
for block in program.blocks:
for op in block.ops:
outputs = [[x + ":"] + op.output(x) for x in op.output_names]
inputs = [[x + ":"] + op.input(x) for x in op.input_names]
print(block.idx, op.type, inputs, "|", outputs)
@helinwang
helinwang / gist:ea9a2e88f20278d2cb53
Created June 17, 2014 13:49
golang https server
package main
import (
"net/http"
"fmt"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Println("Inside handler")
fmt.Fprintf(w, "Hello world from my Go program!")
@helinwang
helinwang / .pre-commit-config.yaml
Created March 2, 2018 22:29
PaddlePaddle EDL .pre-commit-config.yaml
- repo: https://github.com/dnephin/pre-commit-golang
sha: e4693a4c282b4fc878eda172a929f7a6508e7d16
hooks:
- id: go-fmt
files: \.go$
- id: go-lint
files: \.go$
exclude: (.*\/client\/.*\.go|.*\generated\.deepcopy\.go)$
- repo: local
@helinwang
helinwang / .travis.yml
Created March 2, 2018 22:31
PaddlePaddle EDL .travis.yml file
matrix:
include:
- language: go
go: 1.8.x
sudo: required
install:
- go get -u github.com/golang/lint/golint
- curl https://glide.sh/get | bash
- sudo pip install pre-commit
script:
@helinwang
helinwang / log15.diff
Last active March 11, 2018 05:51
Improve golang log15 library
diff --git a/format.go b/format.go
index bce4914..fb40b9d 100644
--- a/format.go
+++ b/format.go
@@ -12,8 +12,8 @@ import (
)
const (
- timeFormat = "2006-01-02T15:04:05-0700"
- termTimeFormat = "01-02|15:04:05"