>> 首页 / Notes / Dev, Tips

开发技巧收藏

发布于: , 最后更新时间: , 阅读时间: 7 min
快速导航

收集开发相关的技巧,比如中国需要的镜像服务等。

镜像服务🔗

Github🔗

  • Fastgit - Github 国内镜像

  • Download: https://download.fastgit.org/org/repo/xxx

  • Clone git clone https://github.com/org/repo

  • Clone with ssh git clone git@ssh.fastgit.org:theowenyoung/gatsby-theme-primer-wiki.git

Rust🔗

Docker🔗

  • 阿里云公网: https://registry.cn-hangzhou.aliyuncs.com
  • 腾讯云: https://mirror.ccs.tencentyun.com

sudo vim /etc/docker/daemon.json

{ "registry-mirrors": ["https://mirror.ccs.tencentyun.com"] }
sudo systemctl restart docker

解决方案🔗

Bash Tips🔗

Get bash script parent dir absolute path🔗

workspace="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/../" &> /dev/null && pwd )"

Get bash script dir path🔗

workspace="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

Bash Dotenv🔗

导出.env 文件到当前执行环境

set -o allexport; source .env; set +o allexport

Deno Tips🔗

Dirname🔗

const __dirname = new URL(".", import.meta.url).pathname;

Docker Tips🔗

Docker compose exec bin🔗

docker-compose exec service-name /bin/sh

Stop All contains and remove🔗

sudo docker stop $(sudo docker ps -a -q)
sudo docker rm $(sudo docker ps -a -q)

Clean all🔗

sudo docker system prune --volumes
sudo docker image prune -a

Git Tips🔗

Generate ssh key🔗

Reference: Generating a new SSH key and adding it to the ssh-agent - GitHub Docs

ssh-keygen -t ed25519 -C "your_email@example.com"
# Start the ssh-agent in the background.
eval "$(ssh-agent -s)"
# Add your SSH private key to the ssh-agent
ssh-add ~/.ssh/id_ed25519

Add ssh key to Github:

cat .ssh/id_ed25519.pub

SSH Keys Setting

获取首次提交时间🔗

提交消息的模版🔗

合并上游的时候不弹出确认框🔗

git pull upstream main --commit --no-edit

对所有的冲突上游的更新🔗

git checkout --theirs .

首次更新子 repo submodule🔗

git submodule update --init --recursive

Later

git submodule update --recursive

Gitignore 忽略所有,除了文件夹🔗

folder/*
!folder/.gitkeep

Go Template Tips🔗

  • Parent Variable, {{$.XX}}
  • URL encode, urlquery "https://test.com"

开源许可证🔗

License Comparison

By 如何选择开源许可证?

Linux Common Commands🔗

View current system info🔗

lsb_release -a

Output:

Distributor ID:	Debian
Description:	Debian GNU/Linux 10 (buster)
Release:	10
Codename:	buster

View all users🔗

cat /etc/passwd | grep -v nologin|grep -v halt|grep -v shutdown|awk -F":" '{ print $1"|"$3"|"$4 }'|more

Get Publish IP🔗

hostname -I

Change user group🔗

usermod -g groupname username

Get user group🔗

id -g -n

Remove apt ppa🔗

sudo add-apt-repository --remove ppa:qbittorrent-team/qbittorrent-stable

Get current shell🔗

echo "$SHELL"

Get current cpu arch🔗

arch

or

dpkg --print-architecture

Unzip tar.gz🔗

tar -xf x.tar.gz

See also here

Tar to specific directory

tar -xf x.tar.gz -C ./xxx

Unzip .gz🔗

gzip -d file.gz

Stdout to File🔗

command &> file

Overwrite:

command >| file.txt 2>&1

Download/Upload file by SSH SCP🔗

Download to local:

scp root@ip:/path ~/Downloads

Remove node_modules🔗

find . -name 'node_modules' -type d -prune -exec rm -rf '{}' +

Remove target🔗

find . -name 'target' -type d -prune -exec rm -rf '{}' +

Find and replace string🔗

sed -i 's/old-text/new-text/g' input.txt
ln -s source_file target_file

Create User🔗

useradd -m USERNAME

Note: with home directory

Get all shells🔗

cat /etc/shells

Last n lines in file🔗

tail -3 file.txt

Linux find a biggest directory in ./🔗

sudo du -a ./ 2>/dev/null | sort -n -r | head -n 20

Linux find a biggest file in ./🔗

find ./ -type f -printf '%s %p\n' | sort -nr | head -10

Linux view systemctl log:🔗

sudo journalctl -f -u service-name.service

See who connect with Me🔗

See: here

ss -tun state connected

Sort by ip connect with 443🔗

netstat -tn 2>/dev/null | grep -E '\s[0-9.]+:443\s' | awk '{print $5}' | cut -d : -f 1 | sort | uniq -c | sort -nr

Ban🔗

See here

sudo systemctl status firewalld
sudo firewall-cmd --permanent --add-rich-rule="rule family='ipv4' source address='202.61.254.136' reject"
sudo firewall-cmd --reload
sudo firewall-cmd --list-all

Kill tcp🔗

tcpkill host <ip>

Nodejs Tips🔗

Delete node_modules folder recursively from a specified path using command line🔗

Delete node_modules folder recursively from a specified path using command line - Stack Overflow

find . -name 'node_modules' -type d -prune -exec rm -rf '{}' +

Get NPM Token🔗

npm token create

Check NPM modules updates🔗

npx npm-check-updates

Update to the latest version:

npx npm-check-updates -u

Postgresql Tips🔗

0. Enter psql🔗

psql

Show all databases🔗

\l

Enter Database🔗

\c database_name

Show all Tables🔗

\d

Show Table structure🔗

\d table_name

Pretty print table🔗

\x on

Alter table🔗

See https://www.postgresql.org/docs/current/sql-altertable.html

Upsert🔗

See https://stackoverflow.com/questions/61494958/postgres-on-conflict-do-update-only-non-null-values-in-python

Export Schema🔗

 pg_dump database_name -s --no-owner > schema.sql

Export Only data🔗

 pg_dump database_name -a --no-owner > data.sql

Delete or Drop or Remove Database🔗

psql
drop database database_name;

Create Database🔗

psql
CREATE DATABASE name;

Import Database🔗

psql database_name < data.sql

CSS🔗

Smart word break in CSS🔗

From Smarter word break in CSS? - Stack Overflow

body {
  overflow-wrap: break-word;
  word-wrap: break-word;
  -ms-word-break: break-all;
  word-break: break-word;
  -ms-hyphens: auto;
  -moz-hyphens: auto;
  -webkit-hyphens: auto;
  hyphens: auto;
}

Vim Tips🔗

Resources🔗

Tips🔗

  • Delete all words: 1,$d

  • Current line end: $

  • Replace all string: s/string/replace_string/g

VS Code Tips🔗

Open command palette: ⇧⌘P🔗

Select current line: cmd+L🔗

Quick Switch Windows🔗

Also see here

Added the following shortcut to keybindings.json

{
  "key": "alt+tab",
  "command": "workbench.action.quickSwitchWindow"
}

Read more:🔗

Robots.txt🔗

# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow: /

📝 帮我完善这个页面?🔗

回应区🔗

你有对这篇文章写回应吗? 你可以在这里提交你的文章网址,或者你也可以通过邮件 owen@owenyoung.com 和我讨论。