Skip to content

Instantly share code, notes, and snippets.

View zhangyuchi's full-sized avatar

Terrell Franzman zhangyuchi

View GitHub Profile
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 / 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));
}
@zhangyuchi
zhangyuchi / memusg
Created June 14, 2017 04:07 — forked from netj/memusg
memusg -- Measure memory usage of processes
#!/usr/bin/env bash
# memusg -- Measure memory usage of processes
# Usage: memusg COMMAND [ARGS]...
#
# Author: Jaeho Shin <netj@sparcs.org>
# Created: 2010-08-16
############################################################################
# Copyright 2010 Jaeho Shin. #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); #
@zhangyuchi
zhangyuchi / memcpy.c
Created June 8, 2017 04:36 — forked from nicky-zs/memcpy.c
One way to solve the glibc compatibility problem. In my case, when building a program with libthrift.a on linux with glibc version 2.15, ld always links memcpy@GLIBC_2.14 which cannot be found on systems with glibc version < 2.14. So, use this file to define a symbol __wrap_memcpy and use -Wl,--wrap=memcpy to tell ld using this symbol when meeti…
#include <string.h>
void *__memcpy_glibc_2_2_5(void *, const void *, size_t);
asm(".symver __memcpy_glibc_2_2_5, memcpy@GLIBC_2.2.5");
void *__wrap_memcpy(void *dest, const void *src, size_t n)
{
return __memcpy_glibc_2_2_5(dest, src, n);
}