Skip to content

Instantly share code, notes, and snippets.

View leimao's full-sized avatar
🦤
Hello Underworld. Hello 人工稚能.

Lei Mao leimao

🦤
Hello Underworld. Hello 人工稚能.
View GitHub Profile
@leimao
leimao / template_specialization.cpp
Created May 4, 2019 18:51
Template Specialization Usages
// https://www.geeksforgeeks.org/template-specialization-c/
@leimao
leimao / csv_splitter.py
Created August 1, 2019 18:16 — forked from jrivero/csv_splitter.py
A Python CSV splitter
import os
def split(filehandler, delimiter=',', row_limit=10000,
output_name_template='output_%s.csv', output_path='.', keep_headers=True):
"""
Splits a CSV file into multiple pieces.
A quick bastardization of the Python CSV library.
Arguments:
@leimao
leimao / fast_tf_estimator_predict.py
Created August 28, 2019 22:05
TensorFlow Predict Using tf.Estimator without Rebuilding Graphs.
"""
Speeds up estimator.predict by preventing it from reloading the graph on each call to predict.
It does this by creating a python generator to keep the predict call open.
Usage: Just warp your estimator in a FastPredict. i.e.
classifier = FastPredict(learn.Estimator(model_fn=model_params.model_fn, model_dir=model_params.model_dir), my_input_fn)
This version supports tf 1.4 and above and can be used by pre-made Estimators like tf.estimator.DNNClassifier.
Author: Marc Stogaitis
# https://github.com/marcsto/rl/blob/master/src/fast_predict2.py
"""
import tensorflow as tf

Git/Github step-by-step Workflow

Step-by-step guide for creating a feature or bugfix branch, submit it for code review as a pull request and once approved, merge upstream. This guide is intended for internal developers with push access to all relevant repos.

You should understand rebasing and squashing. For a very good explanation on rebasing and squashing with pull requests see How to Rebase a Pull Request. Also worth reading is the Hacker's Guide to Git.

Setup

Git/Github step-by-step Workflow

Step-by-step guide for creating a feature or bugfix branch, submit it for code review as a pull request and once approved, merge upstream. This guide is intended for internal developers with push access to all relevant repos.

You should understand rebasing and squashing. For a very good explanation on rebasing and squashing with pull requests see How to Rebase a Pull Request. Also worth reading is the Hacker's Guide to Git.

Setup

@leimao
leimao / asterisk_usages.py
Created October 25, 2019 23:51
* usages, *args, **kwargs in Python
# The object after * must be a iterator
# * is used to unpack a iterator
list_1 = [0,1,2]
print(list_1)
# Iterate list
print(*list_1)
print("*"*50)
@leimao
leimao / example.py
Created November 2, 2019 05:11
Python Attributes
import module
class Chinese(object):
# Class attributes
nationality = "China"
# Instance attributes
def __init__(self, name, birth_year):
@leimao
leimao / python_parallel.py
Last active November 4, 2019 22:50
Python Parallel Computing Example
import threading
import multiprocessing
import time
import random
class ParallelCounter(object):
"""
ParallelCounter instance would have num_counter counters, and num_worker workers.
Each worker would contribute to all counters.
@leimao
leimao / onnx_device.py
Created November 12, 2019 04:06
Run ONNX model on different devices
import onnxruntime
import numpy as np
import time
from onnxruntime.datasets import get_example
# ONNXRuntime API Documentation
# https://microsoft.github.io/onnxruntime/python/api_summary.html
log_severity_level = 0
model_name = "logreg_iris.onnx"
@leimao
leimao / class.cpp
Created January 7, 2020 17:39
Constructor with default arguments. `g++ class.cpp test.cpp -o test`
#include "class.h"
Test::Test(int a, int b): mA{a}, mB{b}
{
}
int Test::getA()
{
return this->mA;
}