Skip to content

Instantly share code, notes, and snippets.

View weidonglian's full-sized avatar

Weidong Lian weidonglian

View GitHub Profile
@weidonglian
weidonglian / main.go
Created November 12, 2017 22:38 — forked from nmerouze/main.go
JSON-API with Go and MongoDB: Final Part
package main
import (
"encoding/json"
"log"
"net/http"
"reflect"
"time"
"github.com/gorilla/context"
@weidonglian
weidonglian / greeter_async_server.cc
Created April 7, 2018 19:02 — forked from yang-g/greeter_async_server.cc
grpc async server toy example
// Class encompasing the state and logic needed to serve a request.
class CallDataBase {
public:
// Take in the "service" instance (in this case representing an asynchronous
// server) and the completion queue "cq" used for asynchronous communication
// with the gRPC runtime.
CallDataBase(Greeter::AsyncService* service, ServerCompletionQueue* cq)
: service_(service), cq_(cq), status_(PROCESS) {}
virtual ~CallDataBase() {}
@weidonglian
weidonglian / allocator.cpp
Last active July 16, 2018 12:50
C++ Collection
template <class T, class TAlloc>
class FlVecAllocator {
public:
template <typename U>
using rebind = FlVecAllocator<U, TAlloc>;
using value_type = T;
using pointer = value_type *;
FlVecAllocator() noexcept = default;
@weidonglian
weidonglian / docker
Last active August 7, 2018 21:02
Docker cheat sheet
# Fix the docker sudo issue
sudo usermod -aG docker $USER # Require logout and then login.
@weidonglian
weidonglian / gist:9b48baa9d032f558a490f4993c53c45e
Created August 28, 2018 11:43 — forked from bengolder/gist:2709743
Quick Git Guide [written in markdown]

Git, used along with Github, is a great way to manage the work of writing code. It allows you to collaborate easily on even very large-scale projects, and provides a great place to quickly host code for sharing it with others. If you're going to write significant amounts of code, I highly recommend using it.

Below is a list of commented Git commands in rough order of probable workflow. I use this as a quick reference for using Git. If you happen to want to add comments or questions, I'm making this blog entry into a Github Gist. You can view it here.

git init #start a repo
git add mynewfile.py #track a file
git rm --cached myoldfile.py #untrack a file
git commit -m 'my commit message' #commit changes with a note 
git push -u origin master # push to the 'master' branch on the 'origin' remote

git branch mynewbranch #create a new branch

struct Connection {
void disconnected()
{
m_connection = Disconnected();
}
void interrupted()
{
m_connection = std::visit(InterruptedEvent(*this), m_connection);
}
#sudo apt-get update
#sudo apt-get install -y build-essential autoconf libtool git pkg-config curl automake libtool curl make g++ unzip
#sudo apt-get clean
GRPC_RELEASE_TAG=v1.11.x
GRPC_DIR=$(pwd)
cd ${GRPC_DIR}
#git clone -b ${GRPC_RELEASE_TAG} https://github.com/grpc/grpc ${GRPC_DIR} && \
cd ${GRPC_DIR} && \
# git submodule update --init && \
@weidonglian
weidonglian / notifyAddrChange.go
Created September 27, 2020 19:07 — forked from KatelynHaworth/notifyAddrChange.go
A simple go program leveraging the Window API to listen for IPv4 network address change events
package main
import (
"log"
"syscall"
"unsafe"
"golang.org/x/sys/windows"
)
func main() {
s := time.Now()
args := os.Args[1:]
if len(args) != 6 { // for format LogExtractor.exe -f "From Time" -t "To Time" -i "Log file directory location"
fmt.Println("Please give proper command line arguments")
return
}
startTimeArg := args[1]
finishTimeArg := args[3]
//
// Companion code to https://medium.com/statuscode/pipeline-patterns-in-go-a37bb3a7e61d
//
// To run:
// go get github.com/pkg/errors
// go run -race pipeline_demo.go
//
package main