Skip to content

Instantly share code, notes, and snippets.

@erbanku
Created July 21, 2023 01:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erbanku/6b88f7e7a32203e6f9ccb644aaecdedd to your computer and use it in GitHub Desktop.
Save erbanku/6b88f7e7a32203e6f9ccb644aaecdedd to your computer and use it in GitHub Desktop.
[OrangeX4's Cheatsheets](https://ch.orangex4.cool/)

[OrangeX4's Cheatsheets]

Source: OrangeX4's Cheatsheets

Develop

Commit

Commit Types

- feat:新功能(feature)
- fix:修补bug
- docs:文档(documentation)
- style: 格式(不影响代码运行的变动)
- refactor:重构(即不是新增功能,也不是修改bug的代码变动)
- test:增加测试
- chore:构建过程或辅助工具的变动

Conda

# 查看环境中已安装包
conda list

# 列出所有环境
conda env list

# 创建环境
conda create -n <env_name> <package_name> python=X.X

# 激活环境
conda activate <env_name>

language

C++

Install Eigen

sudo apt-get install libeigen3-dev
cd /usr/local/include/
sudo ln -sf eigen3/Eigen Eigen
sudo ln -sf eigen3/unsupported unsupported

Javascript

React Query

function getQuery(search) {
  const result = {}
  if (search.length > 1) {
      const query = search.substring(1)
      const vars = query.split("&")
      for (let i = 0; i < vars.length; i++) {
          let pair = vars[i].split("=")
          if (pair.length === 2) {
            result[pair[0]] = pair[1]
          }
      }
  }
  return result
}
const search = window.location.search
const query = getQuery(search)

Download File

function downloadFile(filename, text) {
    const elementA = document.createElement('a')

    // 文件的名称为时间戳加文件名后缀
    elementA.download = filename
    elementA.style.display = 'none'

    // 生成一个blob二进制数据,内容为文本数据
    const blob = new Blob([text])

    //生成一个指向blob的URL地址,并赋值给a标签的href属性
    elementA.href = URL.createObjectURL(blob)
    document.body.appendChild(elementA)
    elementA.click()
    document.body.removeChild(elementA)
}

Server

Linux

Process

# 后台执行
nohup <command> &

# 查找进程
ps aux | grep <command>

File

# 给文件设置可执行权限
chmod 777 run.sh

User

# 新建用户
useradd -m <user>

# 设置密码
passwd <user>

# 删除用户
userdel <user>

# 删除用户及用户文件夹
userdel -r <user>

# 赋予 root 权限
vim /etc/sudoers
# <user> ALL=(ALL) ALL

Server

# 开启黑白棋
nohup python3 ./reversi/main.py &
nohup python3 ./reversi/network.py &
cd /home/ubuntu/reversi/templates
nohup sudo http-server --port=80 -s &

# 开启数据库
cd /usr/local/mongodb/bin
./mongod --bind_ip "0.0.0.0" --dbpath /var/lib/mongo --logpath /var/log/mongodb/mongod.log --fork --config /usr/local/mongodb/bin/mongod.cfg --auth
# 停止数据库
./mongod --dbpath /var/lib/mongo --logpath /var/log/mongodb/mongod.log --shutdown

# 星移服务器端
cd /home/ubuntu/reversi
git pull
mvn package
nohup java -jar target/todos-0.0.1-SNAPSHOT.jar > /dev/null &

# RssHub 服务
sudo docker rm rsshub
sudo docker run -d --rm --name rsshub -p 1200:1200 -e CACHE_EXPIRE=30 -e GITHUB_ACCESS_TOKEN=<token> diygod/rsshub

VS Code

commit_id=c722ca6c7eed3d7987c0d5c3df5c45f6b15e77d1

# Download url is: https://update.code.visualstudio.com/commit:${commit_id}/server-linux-x64/stable
# curl -sSL "https://update.code.visualstudio.com/commit:${commit_id}/server-linux-x64/stable" -o vscode-server-linux-x64.tar.gz

scp /home/orangex4/Downloads/vscode-server-linux-x64.tar.gz orangex4@www.runoob.com:/home/orangex4/vscode-server-linux-x64.tar.gz

mkdir -p ~/.vscode-server/bin/${commit_id}
# assume that you upload vscode-server-linux-x64.tar.gz to /tmp dir
tar zxvf /home/orangex4/vscode-server-linux-x64.tar.gz -C ~/.vscode-server/bin/${commit_id} --strip 1
touch ~/.vscode-server/bin/${commit_id}/0

Software

- Latte
- 火焰截图
- Edge
- Yakuake
- Weylus
- Seafile
- drawio
- GeoGebra
- Icalingua
- WPS
- VS Code
- Wemeet
- Peek
- SimpleScreenRecorder
- LaTeX
- docker
- git, vim, python3, node, java, go, rust

Proxy

Git Proxy

# 使用 Socks5,推荐
git config --global http.proxy 'socks5://127.0.0.1:7890'
git config --global https.proxy 'socks5://127.0.0.1:7890'

# 使用 HTTP,似乎无效
git config --global http.proxy http://127.0.0.1:7890
git config --global https.proxy http://127.0.0.1:7890

# 取消代理
git config --global --unset http.proxy
git config --global --unset https.proxy

Pip Proxy

# 设置代理
export http_proxy='http://127.0.0.1:7890'
export https_proxy='http://127.0.0.1:7890'

# 临时设置: 
pip install -r requirements.txt --proxy=127.0.0.1:7890

Pip Source

# 南大源
pip config set global.index-url http://mirrors.nju.edu.cn/pypi/web/simple/
# 清华源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
# 阿里源
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
# 腾讯源
pip config set global.index-url http://mirrors.cloud.tencent.com/pypi/simple
# 豆瓣源
pip config set global.index-url http://pypi.douban.com/simple/

# 临时使用
pip install markdown -i http://mirrors.nju.edu.cn/pypi/web/simple/

NPM Proxy

# 设置代理
npm config set proxy=http://127.0.0.1:7890
npm config set registry=http://registry.npmjs.org

# 查看代理
npm config get proxy

# 取消代理
npm config delete proxy

NPM Source

# 临时使用
npm --registry https://registry.npm.taobao.org install express

# 持久使用
npm config set registry https://registry.npm.taobao.org

# 查看源
npm config get registry

Website

Hexo

# 新建 Hexo Repo
hexo init blog

# Hexo 热更新预览
hexo s

Cloudflare

# 初始化
wrangler init --site blog

# 修改 wrangler.toml 后
wrangler config

Desktop

sheet

Search Folders

# 查找超过 1 GiB 的目录并排序
du -h --max-depth=1 | grep G | sort -n

# 查找超过 1 MiB 的目录并排序
du -h --max-depth=1 | grep M | sort -n

# 显示大容量软件包
dpigs -H --lines=20

# 显示硬盘分析
baobab

# 显示 pip 包
pip list | awk 'NR > 2 {print $0}' | awk '{print $1}' | xargs pip show | grep -E 'Location:|Name:' | cut -d ' ' -f 2 | paste -d ' ' - - | awk '{print $2 "/" tolower($1)}' | xargs du -sh 2> /dev/null | sort -n | grep 'M'

Clean Space

# Apt 清理
sudo apt autoremove
sudo apt autoclean
sudo apt clean

# 删除本机部分无用文件
rm -rf ~/.local/share/Kingsoft/PDF
rm -rf ~/.cache/vscode-cpptools/ipch
rm -rf ~/.cache/pip
rm -rf ~/.config/Code/CachedExtensionVSIXs
rm -rf ~/.config/Code/CachedData
rm -rf ~/.config/Code/User/workspaceStorage

# 清理 journal
journalctl --vacuum-time=1w

# 清理配置文件
dpkg --list | grep "^rc" | cut -d " " -f 3 | xargs sudo dpkg --purge

# danger: 清理旧内核, 请先用 uname -r 确认
dpkg --list | grep linux-image | awk '{ print $2 }' | sort -V | sed -n '/'`uname -r`'/q;p' | xargs sudo apt-get -y purge

Screenshot OCR

#!/bin/bash 
# Dependencies: tesseract-ocr imagemagick scrot xsel

select tesseract_lang in eng rus equ ;do break;done
# quick language menu, add more if you need other languages.

SCR_IMG=`mktemp`
trap "rm $SCR_IMG*" EXIT

scrot -s $SCR_IMG.png -q 100    
# increase image quality with option -q from default 75 to 100

mogrify -modulate 100,0 -resize 400% $SCR_IMG.png 
#should increase detection rate

tesseract $SCR_IMG.png $SCR_IMG &> /dev/null
cat $SCR_IMG.txt | xsel -bi

exit

Install OpenCV2

sudo apt install libopencv-dev
sudo apt install python-opencv
pip install opencv-python
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment