1. Proxy setting
Windows
set HTTP_PROXY=http://user:password@127.0.0.1:10809 or set HTTP_PROXY=http://127.0.0.1:10809
set HTTPS_PROXY=http://user:password@127.0.0.1:10809 or set HTTPS_PROXY=http://127.0.0.1:10809
python pip
pip install -r ./requirements.txt -i https://pypi.douban.com/simple --trusted-host=pypi.douban.com
pip3 install numpy -i https://pypi.douban.com/simple
Go download
go env -w GOPROXY=https://goproxy.cn
Note: If Makefile set GOPROXY by export GOPROXY ?= https://proxy.golang.org
, Be sure comment it.
conda download
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
npm download
npm config get registry
npm config set registry https://registry.npm.taobao.org
npm config set registry https://registry.npmjs.org (Note: used for set back)
git bash download
git config --global https.proxy "https://127.0.0.1:10808"
download video
2. Useful command
Change suffix
rename ‘s/.csv/.txt/’ *
Vi delete a line
dd
Linux convert all the .md file to .html file
for i in *.md ; do echo “$i” && pandoc -s $i -o $i.html ; done
Linux rename multiple files
for example: rename aro_tty-mIF-45875564pmo_opt
to aro_tty-mImpFRA-45875564pmo_opt
for file in aro_tty-mIF-*_opt;do mv -i "${file}" "${file/-mIF-/-mImpFRA-}";done
ref:
- https://unix.stackexchange.com/questions/102647/how-to-rename-multiple-files-in-single-command-or-script-in-unix
Nmap scan port
nmap 192.168.1.1 -p1-65535
vi copy a line
yy
vi past a line
p
add and remove library from executable file
patchelf --remove-needed libhello.so.1 hello
patchelf --add-needed ./libhello.so.1 hello
Linux lists all open files
lsof
Show Files Accessed by Network Connections
sudo lsof -i
Linux show all used tcp and udp port
sudo netstat -tunlp
Install specifical gem package
sudo gem install rack -v “2.2.4”
vi append just after the current cursor position
a
Linux edit hosts file
sudo vi /etc/hosts
clone a specific directory from Github
- Replace
tree/master
withtrunk
, so download https://github.com/torvalds/linux/tree/master/net/mac80211 would be:svn checkout https://github.com/torvalds/linux/trunk/net/mac80211
- Replace
tree/v5.13
withtags/v5.13
, so download https://github.com/torvalds/linux/tree/v5.13/net/mac80211 would be:svn checkout https://github.com/torvalds/linux/tags/v5.13/net/mac80211
gcc link openssl
gcc XXX.c -lcrypto -lssl
gcc not show warning
gcc XXX.c -w
Ruby 3 encode url
str = URI.encode_www_form_component(str)
ref:
Ruby 3 Encoding
string.force_encoding(Encoding::UTF_8)
ref:
C language convert integer to string
sprintf(string, “%04d”, integer);
Linux not delete all the .txt files
rm !(*.txt)
windows powershell processing all the file in a directory
foreach($file in (Get-ChildItem .\subdirectory).Fullname) {echo $file}
windows find exe file link library
dumpbin /dependents nm.exe
windows find dll library info
dumpbin /headers nm.dll
windows exports symbol from library
- static lib
DUMPBIN /SYMBOLS static.lib
- shared dll or import lib
DUMPBIN /EXPORTS shared.dll/import.lib
Note: If not display symbols, the lib may not export symbols when creating.
Linux check OpenCV version
pkg-config opencv4 --modversion
Path With Spaces in PowerShell
Use Single Quotes ‘ ‘ to Deal With Spaces in the Path in PowerShell
Ubuntu install specific version package
apt list --all-versions package_name
sudo apt install package_name=package_version
Run PowerShell script
- set-ExecutionPolicy RemoteSigned
- powershell.exe sh.ps1
ref:
windows edit sql .dat file
https://sqliteexpert.com/download.html
crack rar file (6 digit number)
- .\rar2john.exe file.rar
- .\hashcat.exe -a 3 -m 13000 –force ‘$rar5$16$bebb59a9f3408812c93cd3c9d074278b$15$3d7fdb029cd967b7342f13bdcfa94938$8$f1cc239aa078d2d2’ ?d?d?d?d?d?d
Linux Create Files Of A Certain Size
- truncate -s 5M ostechnix.txt (data format)
- yes > file.txt; truncate -s 1M file.txt (ASCII format)
- dd if=/dev/urandom of=ostechnix.txt bs=5MB count=1 (random data)
ref:
Linux display binary file
hd file
Linux add content to file header
sed -i ‘1s/^/This is my header\n/’ filename
Windows: Equivalent to linux time command
Measure-Command {start-process yourCommand.exe -argumentlist "argument1 argument2" -wait}
git clone a tag to repo
git clone -b <tagname> --single-branch <repository> .
git remote set-url origin [new-url]
git branch <new-branch>
git push origin heads/<new-branch>
ref:
- https://www.techiedelight.com/clone-specific-tag-with-git/
- https://komodor.com/learn/how-to-fix-fatal-remote-origin-already-exists-error/
- https://www.git-tower.com/learn/git/faq/create-branch
Windows set env only affects current shell
set PATH=%PATH%;C:\your\path\here\
Windows Powershell show env
echo $Env:PATH
ref:
Check Disk Space in Linux
df -h
ref:
Linux set time
sudo timedatectl set-time "YYYY-MM-DD HH:MM:SS"
Linux enable ssh service
sudo systemctl enable ssh.service
sudo systemctl is-enabled ssh.service
Linux show battery info
upower -i /org/freedesktop/UPower/devices/battery_BAT0
Linux allow port through firewall
1. sudo apt-get install ufw
2. sudo ufw allow 22
3. sudo ufw enable
4. sudo ufw status
5. sudo ufw allow to 192.168.1.0/24
6. sudo ufw allow from 192.168.1.0/24 to any port 22
ref:
Linux get all files size of directory
du -sh /path/to/directory
Windows create directory link
mklink /j linkDir TargetDir
VSCode multiline selection
shift + alt
ref:
- https://superuser.com/questions/1503953/vscode-multiline-select-how-to-delete-without-removing-blank-lines
Windows restore ESP partition to EFI
diskpart
list disk
select disk 0
list partition
select partition 1
set id=C12A7328-F81F-11D2-BA4B-00A0C93EC93B
Linux sort all directories and files based on their size
du -sh -- * | sort -rh
ref:
- https://unix.stackexchange.com/questions/106330/sort-all-directories-based-on-their-size
Windows Linux sort all directories and files based on their size
Package Management for MINGW64
Start MING64
open git bash as admin
Finding a package
pacman -Ss <name or part of the name of the package>
Installing a package
pacman -S <name of the package>
Uninstalling a package
pacman -R <name of the package>
Update to fix problem(invalid or corrupted package)
pacman -Syu
ref:
- https://www.msys2.org/docs/package-management/
MINGW64 use cmake
install cmake
pacman -S cmake
check generator
cmake -E capabilities
install generator
pacman -S ninja
build
mkdir build && cd build
cmake -G Ninja <path-to-source> -DCMAKE_BUILD_TYPE=Release
cmake --build .
ref:
- https://www.msys2.org/docs/cmake/
Copy all deps to a directory
ldd exe | grep "c/vcpkg" | awk '{print $3}' | xargs cp -t ./package
Linux show GPU VRAM
sudo dmesg | grep drm
Linux display memory usage
free -m
Fix Python UnicodeEncodeError: ‘gbk’ codec can’t encode character
str.encode('utf-8').decode('gbk')
(first convert string to byte string(utf-8), then convert back to string(gbk))
Curl download multiple files
curl -O https://example.com/file[1-10].png
ref:
- https://unix.stackexchange.com/questions/243134/curl-download-multiple-files-with-brace-syntax
Download youtube video
.\yt-dlp.exe -v --write-auto-subs --sub-langs en -I 12:14 https://www.youtube.com/watch?v=AsygBRaRnUA
- max quality:
-S "res:1080"
- only audio:
-x
ref:
- https://github.com/yt-dlp/yt-dlp
VLC subtitle shortcuts
- H (if dialogue comes later) to delay the subtitles by 50 ms
- G (if dialogue comes first) to forward the subtitles by 50 ms
VLC forwarding shortcuts
- Shift + Right arrow: Forward by 3 seconds
- Alt + Right arrow: Forward by 10 seconds
- Ctrl + Right arrow: Forward by a minute
Run pip in ComfyUI
python -m pip list
Useful code
convert from int
to the string
in C++
#include <string>
std::string s = std::to_string(42);
int i = std::stoi("45");
ref:
write lines to a file in C++
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main (){
ofstream myfile("CSC2134.txt");
if(myfile.is_open())
{
string str;
do{
getline(cin, str);
myfile<<str<< endl;
}while(str!="");
myfile.close();
}
else cerr<<"Unable to open file";
return 0;
}
windows call dll in C++
#include <windows.h>
#include <iostream>
/* Define a function pointer for our imported
* function.
* This reads as "introduce the new type f_funci as the type:
* pointer to a function returning an int and
* taking no arguments.
*
* Make sure to use matching calling convention (__cdecl, __stdcall, ...)
* with the exported function. __stdcall is the convention used by the WinAPI
*/
typedef int (__stdcall *f_funci)();
int main()
{
HINSTANCE hGetProcIDDLL = LoadLibrary("path/to/dll");
if (!hGetProcIDDLL) {
std::cout << "could not load the dynamic library" << std::endl;
return EXIT_FAILURE;
}
// resolve function address here
f_funci funci = (f_funci)GetProcAddress(hGetProcIDDLL, "setup");
if (!funci) {
std::cout << "could not locate the function" << std::endl;
return EXIT_FAILURE;
}
std::cout << "funci() returned " << funci() << std::endl;
FreeLibrary(hGetProcIDDLL);
return 0;
}
ref:
- https://stackoverflow.com/questions/8696653/dynamically-load-a-function-from-a-dll
call python in C++
#include "Python.h"
// c++ call python example
Py_SetPythonHome(L"path/to/python3_x64-windows/tools/python3");
Py_Initialize();
PyRun_SimpleString("import os");
PyRun_SimpleString("print ('Python example')");
// call this function will destory all python context
Py_Finalize();
Predefined C/C++ macros for cross-platform development
#if defined(__linux__)
#include <unistd.h>
#elif _WIN32
#include <windows.h>
// fix windows min, max macro
#ifdef max
#undef max
#endif
#ifdef min
#undef min
#endif
#endif
ref:
- https://dev.to/tenry/predefined-c-c-macros-43id
Cross-platform development
#if defined(__linux__)
sleep(dt);
#elif _WIN32
Sleep(dt*1000);
#endif
Useful link
music link
- https://music.163.com/#/playlist?id=2945028696
- https://music.163.com/#/playlist?id=2748492595
- https://music.163.com/#/playlist?id=7581120144
English dictionary link
- https://www.collinsdictionary.com/dictionary/english/refuge
- https://dict.youdao.com/result?word=umbrage&lang=en
neural network link
- https://github.com/glouw/tinn
- https://hackaday.com/2018/04/08/tiny-neural-network-library-in-200-lines-of-code/
- http://neuralnetworksanddeeplearning.com/
free mail
File sharing and storage platform
build, test and debug regex
Download pdf and book
- find doi link by https://www.researchgate.net
- download pdf by https://sci-hub.usualwant.com/
- download book by https://libgen.rs