Skip to content

Instantly share code, notes, and snippets.

View FinalTheory's full-sized avatar

Yan Huang FinalTheory

View GitHub Profile
@FinalTheory
FinalTheory / CMakeLists.txt
Created September 24, 2015 13:24
C extension中发起新线程回调Python函数时未获取GIL导致core的演示代码
cmake_minimum_required(VERSION 3.3)
project(demo)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2")
set(SOURCE_FILES demo.c)
# if you could not build successfully or error occured when importing nids
@FinalTheory
FinalTheory / divert_mem_pool.c
Last active January 24, 2016 11:50
Simple lock-free memory pool based on linked list
#include "divert_mem_pool.h"
#include <stdlib.h>
divert_mem_pool_t *divert_create_pool(size_t max_alloc) {
divert_mem_pool_t *pool =
calloc(sizeof(divert_mem_pool_t), 1);
if (pool == NULL) {
return NULL;
}
@FinalTheory
FinalTheory / FastPatch.py
Created August 18, 2016 08:29
FastPatch.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Author: 黄龑(huangyan13@baidu.com)
# Created Time: 2016/08/18 14:23
# File Name: fast_patch.py
# Description:
#
# Copyright (c) 2015 Baidu.com, Inc. All Rights Reserved
@FinalTheory
FinalTheory / gist:796c4496e366832254f5ab523cdd9ec3
Created May 19, 2017 03:54 — forked from mattbierner/gist:090a80d25259b6472827
Compile Time Brainfuck C++ Metaprogramming Evaluator
#include <utility>
using iochar = char;
using memval = unsigned char;
/* BF Memory Cell */
template <memval val = 0>
struct Cell {
enum { value = val };
@FinalTheory
FinalTheory / hanoi.cpp
Last active May 22, 2017 13:39
C++ Template Hanoi
#include <iostream>
#include <utility>
template <typename T, T a, T b>
struct pair {
static constexpr auto first = a;
static constexpr auto second = b;
static void print() { std::cout << first << "->" << second << std::endl; }
};
#include <iostream>
#include <type_traits>
template<typename ... Args>
struct get_size;
template<>
struct get_size<> {
static constexpr int size = 0;
};
@FinalTheory
FinalTheory / example.cpp
Last active December 4, 2018 07:16
Minimal framework internal cost demo
// g++ example.cpp -O2 -std=c++11 -o example
#include <cstdlib>
#include <string>
#include <chrono>
#include <thread>
#include <mutex>
#include <vector>
#include <functional>
#include <condition_variable>
@FinalTheory
FinalTheory / test.cpp
Created December 26, 2018 16:42
std::cout cause frash
// g++ test.cpp -static -o test -std=c++11
// ./test
struct Foo
{
Foo();
} foo;
#include <iostream>
Foo::Foo()