owenyoung 13小时前
开发技巧收藏
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

本文收集了多种开发相关的技巧,包括中国需要的镜像服务、Fastgit、Rust、Docker等工具的国内镜像地址和使用方法,以及Bash、Deno、Docker、Git、Go Template等技术的实用技巧。此外,还涵盖了开源许可证的选择、Linux常见命令、Node.js和PostgreSQL的技巧,以及CSS、Vim和VS Code等技术的实用建议。这些技巧可以帮助开发者提高工作效率,解决常见问题。

🔗 镜像服务:Fastgit作为Github的国内镜像,提供了便捷的下载和克隆功能,支持https和ssh方式。Rust国内镜像使用rsproxy cn命令,Docker国内镜像可以配置到/etc/docker/daemon.json文件中。

🔗 Bash技巧:提供了获取bash脚本所在目录绝对路径的方法,以及将.env文件内容导入当前执行环境的方法。

🔗 Git技巧:涵盖了生成ssh key、添加ssh key到Github、获取首次提交时间、提交消息模版、合并上游时不弹出确认框、处理冲突更新、更新子repo submodule、忽略特定文件或文件夹等实用技巧。

🔗 Linux命令:提供了查看系统信息、查看所有用户、获取发布IP、改变用户组、获取用户组、移除apt ppa、获取当前shell、获取当前cpu架构、解压tar.gz和.gz文件、将命令输出重定向到文件、使用SCP下载/上传文件、删除node_modules和target目录、查找并替换字符串、创建软链接、创建用户、获取所有shell、显示文件最后n行、查找最大目录/文件、查看systemctl日志、查看连接到你的用户、按IP连接排序、禁止特定IP连接、杀死tcp连接等实用命令。

🔗 开源许可证:介绍了Unlicense、Coopcycle、Prosperity Public License等不同类型的开源许可证,以及如何选择合适的开源许可证。

🔗 其他技巧:还包括了Go Template的变量使用、URL编码、CSS的智能换行、Vim的常用操作、VS Code的快捷键和技巧、robots.txt的配置、systemd的linger功能等实用信息。

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

镜像服务🔗

Github🔗

Rust🔗

Docker🔗

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 --volumessudo 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-agentssh-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🔗

开源许可证 License🔗

By 如何选择开源许可证?

Linux Common Commands🔗

View current system info🔗

lsb_release -a

Output:

Distributor ID: DebianDescription:    Debian GNU/Linux 10 (buster)Release:  10Codename:   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

Soft Link🔗

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 firewalldsudo firewall-cmd --permanent --add-rich-rule="rule family='ipv4' source address='202.61.254.136' reject"sudo firewall-cmd --reloadsudo 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🔗

psqldrop database database_name;

Create Database🔗

psqlCREATE 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🔗

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.htmlUser-agent: *Disallow: /

Systemd🔗

stay active after your session is killed🔗

loginctl <userid> enable-linger

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

开发技巧 镜像服务 Git Linux命令 开源许可证
相关文章