Skip to content

Instantly share code, notes, and snippets.

View roachsinai's full-sized avatar
🌴
On vacation

RoachZhao roachsinai

🌴
On vacation
View GitHub Profile
@roachsinai
roachsinai / .vimrc
Last active April 19, 2024 12:19
minimal vimrc
"
" A (not so) minimal vimrc.
" https://github.com/mhinz/vim-galore/blob/master/static/minimal-vimrc.vim
"
" You want Vim, not vi. When Vim finds a vimrc, 'nocompatible' is set anyway.
" We set it explicitely to make our position clear!
set nocompatible
filetype plugin indent on " Load plugins according to detected filetype.
#!/usr/bin/env python
import sys
import subprocess
from pathlib import Path
result = subprocess.run(sys.argv[1:], capture_output=True)
result.stderr = result.stderr.lower()
#include <cstddef>
#include <cstdlib>
template <typename R, auto getter, auto setter, size_t (*offset)()>
struct property {
inline R *self() {
return reinterpret_cast<R *>(reinterpret_cast<size_t>(this) - offset());
}
inline operator auto() { return (self()->*getter)(); }
inline void operator=(auto t) { (self()->*setter)(t); }
[custom]
;解决DNS泄露,无分流群组
ruleset=🚀 节点选择,[]DOMAIN-SUFFIX,leetcode.cn
ruleset=🚀 节点选择,[]DOMAIN-SUFFIX,leetcode.com
ruleset=🚀 节点选择,[]DOMAIN-SUFFIX,xn--ngstr-lra8j.com
ruleset=🚀 节点选择,[]DOMAIN-SUFFIX,services.googleapis.cn
ruleset=🚀 节点选择,https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/Ruleset/GoogleCNProxyIP.list
ruleset=DIRECT,https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/LocalAreaNetwork.list
ruleset=DIRECT,https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/UnBan.list
ruleset=DIRECT,https://raw.githubusercontent.com/ACL4SSR/ACL4SSR/master/Clash/ChinaDomain.list
@roachsinai
roachsinai / How_rpath_works
Last active March 15, 2024 09:39 — forked from ardrabczyk/Makefile
Shared object with rpath set
all:
cc -shared -fPIC lib_one.c lib_one.h -o libone.so
cc -shared -fPIC lib_two.c lib_two.h -o libtwo.so -L. -lone -Wl,-rpath=libs
mkdir -p libs
mv libone.so libs
# -L. 是针对编译时的,使得链接器(ld)可以在 gcc 编译时找到 libtwo.so 让 name loopup 成功
# -rpath=. 是针对运行时的,使得在执行 main 时让动态链接器(ld.so)可以找到 main 依赖的 so
# Wl 表示后面的是一个链接器选项(针对 ld,而不是 gcc 的选项)
cc main.c -o main -L. -ltwo -Wl,-rpath=.
void PrintA(void);
void PrintB(void);
int main(int argc, char *argv[])
{
PrintA();
PrintB();
return 0;
}
@roachsinai
roachsinai / dlopen_LoadLibrary.sh
Last active February 2, 2023 06:36
use shared object by dlopen|LoadLibrary
# origin link: https://gist.github.com/roachsinai/faf8ac80860065a7e78adc0b25abb445
# compilation process: https://en.wikibooks.org/wiki/C%2B%2B_Programming/Programming_Languages/C%2B%2B/Code/Compiler/Linker
# Shared library concept: http://ehuss.com/shared/
# 1. Creating the shared library
# Command reference: https://www.oreilly.com/library/view/c-cookbook/0596007612/ch01s05.html
g++ -dynamiclib -fPIC shared.cpp -o shared.so # MacOS
g++ -fPIC -shared shared.cpp -o shared.so # Linux
#!/bin/bash
# This script is used to complete the output of the docker stats command.
# The docker stats command does not compute the total amount of resources (RAM or CPU)
# Get the total amount of RAM, assumes there are at least 1024*1024 KiB, therefore > 1 GiB
#HOST_MEM_TOTAL=$(grep MemTotal /proc/meminfo | awk '{print $2/1024/1024}')
DOCKER_MEM_TOTAL=$(docker info | grep Memory | awk '{print $3}' | grep -o '[0-9]*\.[0-9]*')
# Get the output of the docker stat command. Will be displayed at the end
@roachsinai
roachsinai / mkdir_p.c
Created June 30, 2022 07:55 — forked from ChisholmKyle/mkdir_p.c
Simple recursive mkdir in C
/* recursive mkdir based on
http://nion.modprobe.de/blog/archives/357-Recursive-directory-creation.html
*/
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#define PATH_MAX_STRING_SIZE 256