Skip to content

Instantly share code, notes, and snippets.

View EvanLyu732's full-sized avatar
:octocat:
Welcome!

EvanLyu732 EvanLyu732

:octocat:
Welcome!
View GitHub Profile
@EvanLyu732
EvanLyu732 / effective_modern_cmake.md
Created October 5, 2021 12:14 — forked from mbinna/effective_modern_cmake.md
Effective Modern CMake

Effective Modern CMake

Getting Started

For a brief user-level introduction to CMake, watch C++ Weekly, Episode 78, Intro to CMake by Jason Turner. LLVM’s CMake Primer provides a good high-level introduction to the CMake syntax. Go read it now.

After that, watch Mathieu Ropert’s CppCon 2017 talk Using Modern CMake Patterns to Enforce a Good Modular Design (slides). It provides a thorough explanation of what modern CMake is and why it is so much better than “old school” CMake. The modular design ideas in this talk are based on the book [Large-Scale C++ Software Design](https://www.amazon.de/Large-Scale-Soft

@EvanLyu732
EvanLyu732 / Install NVIDIA Driver and CUDA.md
Created January 30, 2022 04:00 — forked from wangruohui/Install NVIDIA Driver and CUDA.md
Install NVIDIA Driver and CUDA on Ubuntu / CentOS / Fedora Linux OS
@EvanLyu732
EvanLyu732 / introrx.md
Created February 7, 2022 14:14 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@EvanLyu732
EvanLyu732 / latency.txt
Created September 14, 2022 01:21 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
// Generalized memoization for function pointer, From "Functional Programming in C++" Chapter6 lazy evaluation
#include <map>
#include <tuple>
template <typename Result, typename... Args>
auto make_memoized(Result (*f)(Args...))
{
std::map<std::tuple<Args...>, Result> cache;
return [f, cache](Args... args) mutable -> Result
// Defer asio output From C++ High Performance Page 522
#include <boost/asio.hpp>
#include <chrono>
#include <iostream>
using namespace std::chrono;
int main() {
auto ctx = boost::asio::io_context{};
@EvanLyu732
EvanLyu732 / get_gmt_time.cpp
Created October 13, 2022 07:33
Get Current Timestamp in GMT Time
#include <chrono>
#include <iostream>
#include <time.h>
using namespace std::chrono;
int main() {
system_clock::time_point now = system_clock::now();
time_t tt = system_clock::to_time_t(now);
tm utc_tm = *gmtime(&tt);
@EvanLyu732
EvanLyu732 / spdlog.hpp.in
Last active May 12, 2023 03:10
network sinker using spdlog based on cmake configure file
#pragma once
/**
* Goal is to provided easy to use wrapping api, for user.
*
* Mode1: color sinker, auto rotate file location
* Mode2: web sinker injection
* Mode3: stacktrace mode
**/
@EvanLyu732
EvanLyu732 / enableNetworkSinker.cmake
Created October 17, 2022 07:52
spdlog.hpp.in corresponding cmake macro
# Parameter:
# LOG MODULE: folder name
# BIND_PORT: network sinker register port
# SEND_PORT: network sinker publish port
macro(enable_logging LOG_MODULE BIND_PORT SEND_PORT)
if(NOT spdlog_FOUND)
find_package(spdlog REQUIRED)
endif()
if(NOT Boost_FOUND)
@EvanLyu732
EvanLyu732 / install_protoc.sh
Created October 18, 2022 10:16
Install protoc shell scripts
#!/bin/bash
# replace this line with target version
VERSION=v3.14.0
# and this line with target platform
PLATFORM=linux-x84_64
PROTOC_ZIP=protoc-${VERSION}-${PLATFORM}.zip
curl -OL https://github.com/protocolbuffers/protobuf/releases/download/$VERSION/$PROTOC_ZIP
sudo unzip -o $PROTOC_ZIP -d /usr/local bin/protoc