Movatterモバイル変換


[0]ホーム

URL:


Skip to content
Search Gists
Sign in Sign up

Instantly share code, notes, and snippets.

@SF-Zhou
SF-Zhou /hazard_pointer.cc
Last activeMarch 24, 2023 03:37
Lock Free Double Buffer
#include<atomic>
#include<cassert>
#include<iostream>
#include<memory>
#include<mutex>
#include<thread>
#include<vector>
template<classT>
structHazardPointer {
@SF-Zhou
SF-Zhou /lru.cc
CreatedDecember 6, 2019 09:04
C++11 LRU Cache
#include<list>
#include<unordered_map>
classLRUCache {
public:
LRUCache(int capacity) : capacity_(capacity) {}
intget(int key) {
auto it = used_.find(key);
if (it == used_.end()) {
@SF-Zhou
SF-Zhou /main.cpp
CreatedNovember 20, 2019 03:05
C++ Code Block Magic
// Need C++ 11
#include<functional>
#include<iostream>
classA {
public:
template<classF>
autooperator-(const F &func) ->typename std::result_of<F()>::type {
returnfunc();
}
@SF-Zhou
SF-Zhou /hook_write.cc
CreatedOctober 19, 2019 03:37
Linux Sys Func Hook
#include<assert.h>
#include<dlfcn.h>
#include<fcntl.h>
#include<stdio.h>
#include<string.h>
#include<unistd.h>
staticbool is_hook =false;
intmain() {
@SF-Zhou
SF-Zhou /epoll.c
CreatedOctober 17, 2019 13:33
Linux Epoll IO Multiplexing
#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>
@SF-Zhou
SF-Zhou /coroutine.cpp
Last activeSeptember 26, 2019 08:56
Coroutine Demo (libco)
#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)
@SF-Zhou
SF-Zhou /rust-like.cpp
CreatedSeptember 10, 2019 05:20
Rust-like Ownership and Reference
#include<atomic>
#include<cassert>
#include<iostream>
usingnamespacestd;
template<classT>
classMutableRef;
template<classT>
classImmutableRef;
@SF-Zhou
SF-Zhou /set_input_source.cpp
CreatedMarch 10, 2019 08:34
Switch to Specific Input Source for macOS
/*
* 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>
@SF-Zhou
SF-Zhou /lr_scheduler.schema.json
CreatedMarch 2, 2019 14:58
JSON Schema of LR Scheduler
{
"$schema":"http://json-schema.org/draft-04/schema#",
"title":"LRSchedulerConfigs",
"description":"LR Scheduler Configs for PyTorch",
"type":"array",
"items": {
"$ref":"#/definitions/LRSchedulerConfig"
},
"definitions": {
"LRSchedulerConfig": {
@SF-Zhou
SF-Zhou /simple_shared_ptr.cpp
CreatedJanuary 25, 2019 14:16
Simple C++ Shared Ptr
#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

[8]ページ先頭

©2009-2025 Movatter.jp