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 / chat_client.py
Created August 30, 2020 19:57
EdgeDB AsyncIO Tutorial ChatBot: https://youtu.be/SyiTd4rLb2s
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 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;
}
@leimao
leimao / ClearInputBuff.cpp
Created December 30, 2019 07:44 — forked from manadream/ClearInputBuff.cpp
Clearing input buffer in C++ completely
#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 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 / 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 / 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 / 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)

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 / 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