View hazard_pointer.cc
This file contains 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 <class T> | |
struct HazardPointer { |
View lru.cc
This file contains 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> | |
class LRUCache { | |
public: | |
LRUCache(int capacity) : capacity_(capacity) {} | |
int get(int key) { | |
auto it = used_.find(key); | |
if (it == used_.end()) { |
View main.cpp
This file contains 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> | |
class A { | |
public: | |
template <class F> | |
auto operator-(const F &func) -> typename std::result_of<F()>::type { | |
return func(); | |
} |
View hook_write.cc
This file contains 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> | |
static bool is_hook = false; | |
int main() { |
View epoll.c
This file contains 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> |
View coroutine.cpp
This file contains 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" void swap_context(void *, void *) asm("swap_context"); | |
asm(R"( | |
swap_context: | |
mov 0x00(%rsp), %rdx | |
lea 0x08(%rsp), %rcx | |
mov %r12, 0x00(%rdi) |
View rust-like.cpp
This file contains 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> | |
using namespace std; | |
template <class T> | |
class MutableRef; | |
template <class T> | |
class ImmutableRef; |
View set_input_source.cpp
This file contains 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> |
View lr_scheduler.schema.json
This file contains 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": { |
NewerOlder