Skip to content

Instantly share code, notes, and snippets.

Avatar
🦄
Hello Underworld. Hello 人工稚能.

Lei Mao leimao

🦄
Hello Underworld. Hello 人工稚能.
View GitHub Profile
View chat_client.py
from __future__ import annotations
from typing import IO
import asyncio
import sys
import contextlib
import aiofiles.threadpool
from chat_streams import split_lines, write, handle_writes
async def handle_reads(reader: asyncio.StreamReader) -> None:
@leimao
leimao / class.cpp
Created Jan 7, 2020
Constructor with default arguments. `g++ class.cpp test.cpp -o test`
View class.cpp
#include "class.h"
Test::Test(int a, int b): mA{a}, mB{b}
{
}
int Test::getA()
{
return this->mA;
}
@leimao
leimao / ClearInputBuff.cpp
Created Dec 30, 2019 — forked from manadream/ClearInputBuff.cpp
Clearing input buffer in C++ completely
View ClearInputBuff.cpp
#include <iostream>
#include <limits>
using namespace std;
int main(){
char var[10];
bool valid = false;
while(!valid){
cout << "Enter a string 9 characters long: ";
@leimao
leimao / onnx_device.py
Created Nov 12, 2019
Run ONNX model on different devices
View onnx_device.py
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 / python_parallel.py
Last active Nov 4, 2019
Python Parallel Computing Example
View python_parallel.py
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 / example.py
Created Nov 2, 2019
Python Attributes
View example.py
import module
class Chinese(object):
# Class attributes
nationality = "China"
# Instance attributes
def __init__(self, name, birth_year):
@leimao
leimao / asterisk_usages.py
Created Oct 25, 2019
* usages, *args, **kwargs in Python
View asterisk_usages.py
# 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)
View step-by-step-git-workflow.md

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

View step-by-step-git-workflow.md

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 / fast_tf_estimator_predict.py
Created Aug 28, 2019
TensorFlow Predict Using tf.Estimator without Rebuilding Graphs.
View fast_tf_estimator_predict.py
"""
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