Skip to content

Instantly share code, notes, and snippets.

@HungMingWu
HungMingWu / Allocator.h
Last active May 2, 2019 14:52
A workable C++11 Allocator
#pragma once
#include <iostream>
#include <atomic>
#include <memory>
namespace my {
std::atomic_int g_memory_used{ 0 };
template <typename T>
@HungMingWu
HungMingWu / ver1.cpp
Created February 20, 2019 08:05
Write my own custom asio async function
#include <boost/system/error_code.hpp>
#include <boost/asio/async_result.hpp>
#include <boost/asio/detail/handler_type_requirements.hpp>
template<
class ReadHandler>
BOOST_ASIO_INITFN_RESULT_TYPE(
ReadHandler, void(boost::system::error_code, std::size_t))
async_read(ReadHandler&& handler)
{
@HungMingWu
HungMingWu / test1.cpp
Last active November 2, 2018 09:57
Uncomplet C++ ASIO Example
#include <iostream>
#include <sstream>
#include <functional>
#include <boost/optional.hpp>
#include <boost/asio/ts/internet.hpp>
#include <boost/asio/ts/buffer.hpp>
#include <boost/asio.hpp>
// #define NETWORK_TS_ENABLED
scons arch=arm64-v8a extra_cxx_flags="-fPIC" benchmark_tests=0 validation_tests=0 opencl=1 embed_kernels=1 neon=1
./b2 link=static cxxflags=-fPIC --with-filesystem --with-test --with-log --with-program_options
./configure --host=arm-linux CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ --with-protoc=/usr/local/bin/protoc --prefix=/usr/local/arm_proto
CXX=aarch64-linux-gnu-g++ cmake -DARMCOMPUTE_ROOT=/ComputeLibrary -DARMCOMPUTE_BUILD_DIR=/ComputeLibrary/build -DBOOST_ROOT=/boost_1_64_0 -DTF_GENERATED_SOURCES=/usr/local -DBUILD_TF_PARSER=1 -DPROTOBUF_ROOT=/usr/local/arm_proto -DARMCOMPUTENEON=1 -DARMCOMPUTECL=1 ..
@HungMingWu
HungMingWu / Tensorflow-example.js
Created April 30, 2018 07:01
Minimal Tensorflow-JS Example
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.9.0"> </script>
<script>
const model = tf.sequential();
model.add(tf.layers.dense({ units: 1, inputShape: [1] }));
model.compile({ loss: 'meanSquaredError', optimizer: 'sgd' });
const xs = tf.tensor2d([1, 2, 3, 4], [4, 1]);
#include <type_traits>
#include <iostream>
#include <experimental/coroutine>
template<typename T>
struct coreturn {
struct promise;
friend struct promise;
using handle_type = std::experimental::coroutine_handle<promise>;
coreturn(const coreturn &) = delete;
#include <type_traits>
#include <iostream>
#include <experimental/coroutine>
struct generator {
struct promise_type {
int current_value;
promise_type() {
std::cout << "Promise created" << std::endl;
}
#include <type_traits>
#include <iostream>
#include <experimental/coroutine>
struct generator {
struct promise_type {
int current_value;
promise_type() {
std::cout << "Promise created" << std::endl;
}
@HungMingWu
HungMingWu / coroutine1.cpp
Last active April 27, 2018 07:39
Coroutine Example
#include <type_traits>
#include <iostream>
#include <experimental/coroutine>
template<typename T>
struct coreturn {
struct promise;
friend struct promise;
using handle_type = std::experimental::coroutine_handle<promise>;
coreturn(const coreturn &) = delete;
@HungMingWu
HungMingWu / gist:57f7bf4a3cf91956a9887d30725756f2
Created April 24, 2017 03:03
Boost ASIO ThreadPool Implementation
// MIT License
// Copyright (c) 2017 Poom Malakul Na Ayudhya
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions: