Skip to content

Instantly share code, notes, and snippets.

@zorchp
zorchp / tiny.vimrc
Last active July 18, 2024 11:56
My tiny vimrc config for base usage.
" syntax highlight
syntax on
" show line number and relative number
set number
set relativenumber
" indent when newline
set smartindent
#!/usr/bin/env bash
if [ $# -ne 1 ]; then
echo "USAGE: $0 disk"
echo " e.g.: $0 Archlinux.qcow2"
exit 1
fi
if [ ! -f $1 ]; then
echo "could not open $1 : no such file"
@zorchp
zorchp / get-wechat-img.py
Last active October 8, 2023 06:03
get WeChat Public Platform title page image by Python
import re
import sys
import requests
def main():
argv = sys.argv
n = len(argv)
if n != 2:
@zorchp
zorchp / nvim-one-key-to-run.lua
Created October 7, 2023 13:44
one file compile on nvim by using one key, such as `F7` and `F8`.
local function CodeRunner()
--[===[========================== Global ===========================]===]
vim.api.nvim_create_autocmd({ "InsertLeave" }, {
callback = function()
vim.fn.execute("silent! write")
-- vim.notify("Autosaved!", vim.log.levels.INFO, {})
end,
})
--[===[========================== Static ===========================]===]
@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"
@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 / 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 / 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 / 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 / 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 *= `