Skip to content

Instantly share code, notes, and snippets.

@theidexisted
theidexisted / clang_windows_cross.cmake
Created June 5, 2020 03:55 — forked from HiImJulien/clang_windows_cross.cmake
Toolchain file to cross-compile from clang (WSL-Ubuntu) to Windows.
# Cross toolchain configuration for using clang-cl.
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_VERSION 10.0)
set(CMAKE_SYSTEM_PROCESSOR AMD64)
set(CMAKE_C_COMPILER "/usr/bin/clang-cl-9")
set(CMAKE_CXX_COMPILER "/usr/bin/clang-cl-9")
set(CMAKE_LINKER "/usr/bin/lld-link-9")
#include <condition_variable>
#include <cstdio>
#include <functional>
#include <future>
#include <iostream>
#include <memory>
#include <memory>
#include <mutex>
#include <mutex>
#include <queue>
default:
g++ -O0 -ggdb3 -std=c++11 -o example -lcds_d main.cpp -pthread
clear:
rm example
// Note:
// To test RedisClient, a Redis Server must be running at localhost:6479
#include "RedisClient.h"
#include <gtest/gtest.h>
#include <thread>
template <class client_t>
class RedisClientTest : public testing::Test {
public:
virtual void SetUp () override {
#include <algorithm>
#include <cctype>
#include <fstream>
#include <iostream>
#include <iterator>
#include <set>
#include <string>
using namespace std;

Latency Comparison Numbers

Type time ms comment
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 300 ns 20x L2 cache, 200x L1 cache
#!/bin/bash
work_dir="/home/zampread/banker_cost"
date=`date +"%Y_%m_%d"`
data_minute=`date +"%Y_%m_%d_%H_%M"`
table_name="banker_record_"$date
output_file="banker_cost_"$data_minute
current_file="banker_cost_current.txt"
function query_mysql {
// https://leetcode.com/problems/find-k-pairs-with-smallest-sums/
// a brute-force solution, just for demonstration how to get container from priority_queue
template <class T,
class Container = vector<T>,
class Compare = less<typename Container::value_type> >
class priority_queue_v2 : public priority_queue<T, Container, Compare> {
public:
using base_t = priority_queue<T, Container, Compare>;
priority_queue_v2(const Compare& cmp)
@theidexisted
theidexisted / virtual_function.cpp
Created May 22, 2016 13:52
watch out for return value
class Shape {
public:
virtual ~Shape() { } // A virtual destructor
virtual void draw() = 0; // A pure virtual function
virtual void move() = 0;
// ...
virtual Shape* clone() const = 0; // Uses the copy constructor
virtual Shape* create() const = 0; // Uses the default constructor
};
@theidexisted
theidexisted / cmakelists.txt
Created January 27, 2016 08:59
for proxygen build
project(echo_server CXX)
cmake_minimum_required(VERSION 2.8)
file(GLOB SRC_FILES ${PROJECT_SOURCE_DIR}/*.cpp)
set(CMAKE_CXX_FLAGS_DEBUG "-DDEBUG -g -O0 -Wall -std=c++11")
set(CMAKE_CXX_FLAGS "-O2 -Wall -std=c++11")
add_executable(echo_server
${SRC_FILES}
)