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 / .cpp
Created May 6, 2024 12:45 — forked from DongHeZheng/.cpp
One method of scaling, rotating and cropping image by using OpenCV
void imageScaleAndRotate(const cv::Mat &src, cv::Mat &out, double scale, double roll) {
// scaling
cv::Mat imSmall;
cv::resize(src, imSmall, cv::Size(), scale, scale);
// prepare for rotating
int width = imSmall.cols, height = imSmall.rows;
int diagonal = int(sqrt(height * height + width * width));
int offsetX = (diagonal - width) / 2, offsetY = (diagonal - height) / 2;
@roachsinai
roachsinai / .vimrc
Last active June 12, 2024 08:30
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]
;https://github.com/ACL4SSR/ACL4SSR/blob/master/Clash/config/ACL4SSR_Online_Full_Google.ini
;不要随意改变关键字,否则会导致出错
;acl4SSR规则
;去广告:支持
;自动测速:支持
;微软分流:支持
;苹果分流:支持
;增强中国IP段:支持
@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