Skip to content

Instantly share code, notes, and snippets.

@zorchp
zorchp / useful_snippets.tex
Last active December 2, 2023 12:33
Some useful snippets for LaTeX typewriting including Article, Beamer, TikZ Picture and so on.
%%%%%%%%%%%%%%%%%%% 参考文献 %%%%%%%%%%%%%%%%%%%%%%
% 自定义新命令\upcite, 使参考文献引用以上标出现
\newcommand{\upcite}[1]{\textsuperscript{\cite{#1}}}
% 参考文献样式
\bibliographystyle{data/gbt7714-2005}
%%% 目录设置
\usepackage{tocloft}
\setcounter{tocdepth}{2} % 目录层级数
@zorchp
zorchp / useful-alias-in-shell.sh
Created May 8, 2023 02:42
`Alias` when I use Ubuntu
# Ubuntu Linux
alias vi=nvim
alias cl=clear
alias vb='vi ~/.bashrc'
alias sb='source ~/.bashrc'
# for net
func_tcp() { firewall-cmd --zone=public --add-port=$1/tcp --permanent && iptables -I INPUT -ptcp --dport $1 -j ACCEPT; }
alias addtcp='func_tcp'
alias addudp='func_udp() { firewall-cmd --zone=public --add-port=$1/udp --permanent && iptables -I INPUT -pudp --dport $1 -j ACCEPT; };func_udp'
@zorchp
zorchp / alias-and-brew-on-MacOS-zsh.sh
Last active August 11, 2023 11:44
Alias and Brew config for MacOS with zsh
export PATH="/usr/local/texlive/2023/bin/universal-darwin:$PATH"
export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH"
# brew git mirrors: update for brew 4.0.0
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles"
export HOMEBREW_API_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles/api"
@zorchp
zorchp / C++STL-IO.cpp
Last active May 16, 2023 09:25
C++ print 1d 2d vector and other containers by template and operator<< overload
// all container which support range-for-loop
template <typename T, template <typename> class Container>
ostream &operator<<(ostream &os, const Container<T>& v) {
for (auto i : v) os << i << " ";
return os << endl;
}
// ========================== vector ==============================
template <typename T>
ostream &operator<<(ostream &os, const vector<T>& v) {
@zorchp
zorchp / math-function.cpp
Created May 19, 2023 04:10
some useful math function written by C++.
// calc factorial
auto f=[](int n) {
int ans{1};
while (n > 1) ans*= n, --n;
return ans;
};
// calc combination number
auto comb = [](int n, int k) {
int ans{1};
for (int i{}; i < k; ++i) ans = ans * (n - i) / (i + 1); // can not `ans *= `
@zorchp
zorchp / time-spent-for-cpp.cpp
Last active August 11, 2023 11:17
for-record-time-spent
#include <chrono>
using namespace std;
using namespace std::chrono;
auto start = system_clock::now();
// do something...
@zorchp
zorchp / text-process.sh
Created August 22, 2023 11:22
文本处理的 Linux 工具使用
### 查找指定文件中包含某关键字的指定行(显示行号)
# -n 显示行号
grep -n "home" /etc/passwd
# 需要先打印模式匹配然后打印行号, 比较麻烦
sed -ne '/home/p' -e '/home/=' /etc/passwd
### 查找某些特定文件(例如通过扩展名)中出现的关键字的对应文件名和行号
grep -rn "process" --include='*.cpp' .
@zorchp
zorchp / centos-bashrc.sh
Created August 28, 2023 02:17
centos bashrc with useful alias etc.
############### for proxy accelerate network ############################
# start_clash.sh: (may stdout in screen, you should use `nohup`)
: '
#!/bin/bash
./clash -d . &
'
alias vpn='cd ~/opt/clash && ./start_clash.sh && cd -'
alias uvpn='pkill -9 clash'
@zorchp
zorchp / cxx-print-type.cpp
Last active October 6, 2023 15:28
print-type-with-clang-and-gcc-use-cxxabi
#include <cxxabi.h>
#include <iostream>
#if __cplusplus < 202002
#define print_type(x) \
std::cout << #x << typeid(x).name() << " => " \
<< abi::__cxa_demangle(typeid(x).name(), NULL, NULL, NULL) \
<< std::endl
#else
@zorchp
zorchp / wrap-ghidra-into-MacOS-app-bundle.py
Last active November 30, 2023 11:07
A worked way to bundle ghidra installed from homebrew to MacOS `.app` format.
#!/opt/homebrew/bin/python3
import os
import re
import subprocess as sp # for get command return value(stdout)
base_path = "/Applications"
app_name = "Ghidra"
exec_file = "ghidraRun"