Skip to content

Instantly share code, notes, and snippets.

View zhangyuchi's full-sized avatar

Terrell Franzman zhangyuchi

View GitHub Profile
@zhangyuchi
zhangyuchi / thread_libev.cc
Created December 24, 2014 07:31
multithread libev exsample, cross thread notify
//This program is demo for using pthreads with libev.
//Try using Timeout values as large as 1.0 and as small as 0.000001
//and notice the difference in the output
//(c) 2009 debuguo
//(c) 2013 enthusiasticgeek for stack overflow
//Free to distribute and improve the code. Leave credits intact
#include <ev.h>
#include <stdio.h> // for puts
package main
import (
"encoding/json"
"fmt"
"log"
"github.com/graphql-go/graphql"
)
@zhangyuchi
zhangyuchi / futures03_async_await.md
Created September 5, 2019 07:04 — forked from bmwill/futures03_async_await.md
Futures 0.3 and Async/Await

OUTDATED

Futures 0.3 and Async/Await

This document will try to give a short tutorial of how to use the new style futures (0.3), how to use Async/Await, and how to use the compatibility layer to interoperate with old futures (0.1) and tokio.

Terminology

When dealing with futures in this new world there are a lot of different parts and it can be difficult to keep things straight at times. As such here is a quick run down of the different parts and what they are.

@zhangyuchi
zhangyuchi / effective_modern_cmake.md
Created March 22, 2019 02:59 — 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

@zhangyuchi
zhangyuchi / multiinherit_shared.cc
Created January 7, 2015 11:39
multiple inherit enable_shared_from_this
/* Trick to allow multiple inheritance of objects
* inheriting shared_from_this.
* cf. http://stackoverflow.com/a/12793989/587407
*/
/* First a common base class
* of course, one should always virtually inherit from it.
*/
class MultipleInheritableEnableSharedFromThis: public std::enable_shared_from_this<MultipleInheritableEnableSharedFromThis>
{
@zhangyuchi
zhangyuchi / centos7ksiso.md
Created December 7, 2017 07:06 — forked from abrahamrhoffman/centos7ksiso.md
CentOS 7 Kickstart File & How to build an (auto install) ISO

CentOS 7 Kickstart File - HOWTO Build ISO

There is so much documentation online from RedHat and CentOS about this topic - it's sad that I am writing this. But the real state of documentation on this topic (CentOS 7 + KS + ISO = Bootable DVD) is almost non-existent.

I found this: http://smorgasbork.com/component/content/article/35-linux/151-building-a-custom-centos-7-kickstart-disc-part-1

Which I greatly appreciate and +1, but the documentation is half-baked and there are numerous errors.

Finally... FINALLY! After four days of banging my head, I got this to work. Hopefully someone else will be able to do this in a few hours, instead of blowing their weekend like me. :(

@zhangyuchi
zhangyuchi / readfile.cc
Created September 15, 2017 12:31
read file content to string
#include <sstream>
std::ifstream t("file.txt");
std::stringstream buffer;
buffer << t.rdbuf();
@zhangyuchi
zhangyuchi / openssl-ecc.c
Last active June 30, 2017 09:53 — forked from louismullie/openssl-ecc.m
OpenSSL ECC encrypt/decrypt
secure_t * ecies_encrypt(char *key, unsigned char *data, size_t length) {
void *body;
HMAC_CTX hmac;
int body_length;
secure_t *cryptex;
EVP_CIPHER_CTX cipher;
unsigned int mac_length;
EC_KEY *user, *ephemeral;
size_t envelope_length, block_length, key_length;
#include <unistd.h>
#include <stdio.h>
/* since pipes are unidirectional, we need two pipes.
one for data to flow from parent's stdout to child's
stdin and the other for child's stdout to flow to
parent's stdin */
#define NUM_PIPES 2
@zhangyuchi
zhangyuchi / getcpunum.cc
Created June 26, 2017 10:55
获取cpu核心数
#include <unistd.h>
int main(){
return static_cast<int>(sysconf(_SC_NPROCESSORS_ONLN));
}