Instantly share code, notes, and snippets.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
#include<atomic> | |
#include<cassert> | |
#include<iostream> | |
#include<memory> | |
#include<mutex> | |
#include<thread> | |
#include<vector> | |
template<classT> | |
structHazardPointer { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
#include<list> | |
#include<unordered_map> | |
classLRUCache { | |
public: | |
LRUCache(int capacity) : capacity_(capacity) {} | |
intget(int key) { | |
auto it = used_.find(key); | |
if (it == used_.end()) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
// Need C++ 11 | |
#include<functional> | |
#include<iostream> | |
classA { | |
public: | |
template<classF> | |
autooperator-(const F &func) ->typename std::result_of<F()>::type { | |
returnfunc(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
#include<assert.h> | |
#include<dlfcn.h> | |
#include<fcntl.h> | |
#include<stdio.h> | |
#include<string.h> | |
#include<unistd.h> | |
staticbool is_hook =false; | |
intmain() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
#include<arpa/inet.h> | |
#include<ctype.h> | |
#include<errno.h> | |
#include<fcntl.h> | |
#include<stdio.h> | |
#include<stdlib.h> | |
#include<string.h> | |
#include<sys/epoll.h> | |
#include<unistd.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<stdint.h> | |
#include<vector> | |
extern"C"voidswap_context(void *,void *) asm("swap_context"); | |
asm(R"( | |
swap_context: | |
mov 0x00(%rsp), %rdx | |
lea 0x08(%rsp), %rcx | |
mov %r12, 0x00(%rdi) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
#include<atomic> | |
#include<cassert> | |
#include<iostream> | |
usingnamespacestd; | |
template<classT> | |
classMutableRef; | |
template<classT> | |
classImmutableRef; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
/* | |
* Switch to Specific Input Source for macOS | |
* Author: SF-Zhou<sfzhou.scut@gmail.com> | |
* To English: g++ -framework Foundation -framework Carbon -std=c++11 -O2 change-input-source.cpp -o switch-to-english | |
* To Pinyin: g++ -framework Foundation -framework Carbon -std=c++11 -O2 change-input-source.cpp -D PINYIN -o switch-to-pinyin | |
*/ | |
#include<string> | |
#include<Carbon/Carbon.h> | |
#include<ApplicationServices/ApplicationServices.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
{ | |
"$schema":"http://json-schema.org/draft-04/schema#", | |
"title":"LRSchedulerConfigs", | |
"description":"LR Scheduler Configs for PyTorch", | |
"type":"array", | |
"items": { | |
"$ref":"#/definitions/LRSchedulerConfig" | |
}, | |
"definitions": { | |
"LRSchedulerConfig": { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
#include<iostream> | |
template<classT> | |
classSharedPtr { | |
public: | |
SharedPtr(T *rep =nullptr) : rep_(rep), count_ptr_(newint32_t(1)) {} | |
SharedPtr(const SharedPtr &obj) : count_ptr_(obj.count_ptr_), rep_(obj.rep_) { | |
increse(); | |
} |
NewerOlder