Skip to content

Instantly share code, notes, and snippets.

Zheng Luo htfy96

Block or report user

Report or block htfy96

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
htfy96 /
Last active Jan 17, 2020
static inline vs inline vs static in C++

In this article we compared different behavior of static, inline and static inline free functions in compiled binary. All the following test was done under g++ 7.1.1 on Linux amd64, ELF64.

Test sources


#pragma once

inline int only_inline() { return 42; }
static int only_static() { return 42; }
htfy96 / install_dep_and_build
Created Dec 5, 2019
Install conan packages and build with cmake_multi generator
View install_dep_and_build
# Usage:
# Assuming you are in ROOT/build
# and ROOT contains conanfile.txt and CMakeLists.txt
# ./install_dep_and_build [Debug|Release|RelWithDebInfo]
# Prerequisite:
# Make sure you have
# [generators]
_deps/wasiclang-src/opt/wasi-sdk/bin/clang --sysroot _deps/wasiclang-src/opt/wasi-sdk/share/wasi-sysroot stb_vorbis.c -c -o stb_vorbis.
_deps/wasiclang-src/opt/wasi-sdk/bin/clang -Wl,--export-all --sysroot _deps/wasiclang-src/opt/wasi-sdk/share/wasi-sysroot *.o -o lib.wasm
cargo/release/lucetc --bindings _deps/mod_lucet-src/lucet-wasi/bindings.json --reserved-size 256MiB lib.wasm -o --opt-level 2
htfy96 / childexit-pipe.c
Created Sep 23, 2019
Detecting child exit with pipe
View childexit-pipe.c
#include <stdio.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <assert.h>
#include <sys/select.h>
#include <stdbool.h>
htfy96 /
Last active Dec 19, 2018
Restrict C++ unsafe behaviors in unsafe{} block using clang-query and simple commands

C++ has a lot of dark corners. Unfortunately, sometimes we need to allow inexperienced developers to write some C++ code to meet the deadline. The intersection of the two cases often makes things worse: programmers used to delegate memory management to garbage collection tend to throw off new everywhere in the source, and those stuck with compile error will use every evil hack to get around with it. Code review is a feasible way to ensure code quality in this case, but a better choice is to restrict them into a relatively safe subset of the language.

In this article, I will show how to use clang-query and a simple script to restrict some unsafe behaviors in unsafe block/namespace using simple commands:

#include "common.hpp"

struct X {
    int f: 2; // error: use of bit field without enclosing Unsafe
htfy96 / cdq.cpp
Last active Dec 19, 2018
Solution to CF Educational Round 56 Problem E, with CDQ divide-and-conquer (CDQ分治)
View cdq.cpp
#include <bits/stdc++.h>
Convert all modification and query into single-point events (t, x, y). Initially sort by t,
for each interval, recursively handle independent two parts. Then calc the interference
between part one and two: only mod in part 1 can affect result in part 2. Therefore, we can
sort part1 and 2 respectively by x, then process all mod event in part 1 and all query events in
part 2 in a sort-merge-like way. The Y-dimension is maintained with a fenwick tree.
In the end all elements will be sorted by x.
View discrete.cpp
#include <bits/stdc++.h>
using namespace std;
int main()
vector<int> a {1, 3, 3, 2, 5};
vector<int> b;
for (int i=0; i<a.size(); ++i)
htfy96 /
Created Sep 19, 2018
Proof of identication

I hereby claim:

  • I am the person who sends Wechat messages and moments at Sept 18 22:07 - 22:17 PDT from account @VicLuo96

To claim this, I sign this message with my pubkey 0x98809CA08BF5662A:

I hereby claim:

- I am the person who sends Wechat messages and moments at Sept 18 22:07 - 22:17 PDT from account @VicLuo96
View init.vim
set shell=/bin/bash
syntax on
if &term =~ '^\(xterm\|screen\)$' && $COLORTERM == 'gnome-terminal'
set t_Co=256
filetype on
filetype plugin on
set autoindent
set nolazyredraw
set number
htfy96 / A-small-attempt-3.out
Created Jul 29, 2018
GCJ Kickstart Round D Problem A: Solution and sample data
View A-small-attempt-3.out
Case #1: 13
Case #3: 2
Case #4: 386239
Case #8: 84609596512776
Case #9: 0
Case #10: 1155268877829
You can’t perform that action at this time.