Pinned Post

Recent Posts

似乎用 Asciidoctor 来写文档也不错?
AsciiDoc 标记语言中文文档: https://asciidoctor.cn/docs

隐藏或删除 linux 中的 history

go test 时 go 程序中通过 os.Getwd() 获取到的路径错误,暂未想到较好解决方案,临时通过环境变量解决:

	if v, has := os.LookupEnv("ENV"); has && v == "test" {
		fmt.Println("运行于TEST模式")
		AppRootPath = "/Users/jetking/my-path" //todo
		InitLogger("go-test")
	}

然后在 VSCODE 配置文件 settings.json 中添加配置以便在 VSCODE 中点击 run test 时自动添加环境变量:

    "go.testEnvVars": {
        "ENV": "test"
    },

通过 SSH 隧道进行端口流量转发

通过 SSH-L-R 参数可在管道内部建立一个有向隧道:

  • 使用 -L(Local) 参数建立一个由本地到远程的隧道(正向隧道);
  • 使用 -R(Remote) 参数建立一个由远程到本地的隧道(反向隧道)。

.ssh/config 配置批量管理服务器

通过配置 ~/.ssh/config 简化 SSH 连接:

Host myhost 
    HostName 123.123.123.123
    User jetking
    IdentityFile ~/.ssh/id_rsa
    Port 22

然后 ssh myhost 即可快捷连接。
如果批量管理上千台服务器时,可使用以下方式处理:

Host *
    HostName %h.ssh.xhb.ltd
    User jetking
    IdentityFile ~/.ssh/id_rsa
    Port 22

这样我们就可以通过执行 ssh ser1 连接到 ser1.ssh.xhb.ltd 服务器了。

Jetbrains系列产品2019.3.3最新激活方法[持续更新] https://zhile.io/2018/08/17/jetbrains-license-server-crack.html

猫喵网提供的 可免费商用中文字体下载大全一览表: http://www.maoken.com/all-fonts
(图文版: http://www.maoken.com/all-fonts-imgs

macunzip 解压文件失败:error: cannot create ...[乱码的文件名]...
改用 ditto

ditto -V -x -k --sequesterRsrc --rsrc file.zip to_path

相关参数说明:
> -V print a line of status for every file copied
> -x src(s) are archives
> -k archives are PKZip > –sequesterRsrc copy resources via polite directory (PKZip only)

Cax ,HTML5 Canvas 2D Rendering Engine - 小程序、小游戏以及 Web 通用 Canvas 渲染引擎

Go 程序编译时添加相关版本信息

通过 go build -ldflags "-X 'path/packageName.vername=value'" 的方式在编译时向程序中添加版本相关信息。

如:

app/version/version.go:

package version

var (
	BuildTime   = "N/A"
	GitCommitID = "N/A"
	GitBranch   = "N/A"
)

func GetVersion() map[string]string {
	return map[string]string{
		"build_time":    BuildTime,
		"git_commit_id": GitCommitID,
		"git_branch":    GitBranch,
	}
}

router.go:


import(
  "myshop/app/version"
)

// ...
func init() {
  service := instance.APIService()
	service.GET("version", func(c *gin.Context) {
		ver := version.GetVersion()
		data := make(map[string]interface{})
		for k, v := range ver {
			data[k] = v
		}
		ctr := api.Controller{}
		ctr.Succeed(c, data)
	})
}

build.sh:

#!/bin/bash

gitBranch=`git rev-parse --abbrev-ref HEAD`
gitCommit=`git log --pretty=format:"%h" -1`
buildTime=`date +%FT%T%z`
ldflags="-X 'myshop/app/version.BuildTime=${buildTime}' -X 'myshop/app/version.GitCommitID=${gitCommit}' -X 'myshop/app/version.GitBranch=${gitBranch}'"

binPath="bin/myshop_linux_amd64"

echo "start.."
GOOS=linux GOARCH=amd64 go build -o $binPath -ldflags "${ldflags}"
echo "compile completed."
echo "commit id: ${gitCommit}"
echo "branch: ${gitBranch}"
echo "buildTime: ${buildTime}"

echo "upx:"
upx -7 $binPath

git log --pretty 参数

%H: commit hash
%h: 缩短的commit hash
%T: tree hash
%t: 缩短的 tree hash
%P: parent hashes
%p: 缩短的 parent hashes
%an: 作者名字
%aN: mailmap的作者名字 (.mailmap对应,详情参照git-shortlog(1)或者git-blame(1))
%ae: 作者邮箱
%aE: 作者邮箱 (.mailmap对应,详情参照git-shortlog(1)或者git-blame(1))
%ad: 日期 (--date= 制定的格式)
%aD: 日期, RFC2822格式
%ar: 日期, 相对格式(1 day ago)
%at: 日期, UNIX timestamp
%ai: 日期, ISO 8601 格式
%cn: 提交者名字
%cN: 提交者名字 (.mailmap对应,详情参照git-shortlog(1)或者git-blame(1))
%ce: 提交者 email
%cE: 提交者 email (.mailmap对应,详情参照git-shortlog(1)或者git-blame(1))
%cd: 提交日期 (--date= 制定的格式)
%cD: 提交日期, RFC2822格式
%cr: 提交日期, 相对格式(1 day ago)
%ct: 提交日期, UNIX timestamp
%ci: 提交日期, ISO 8601 格式
%d: ref名称
%e: encoding
%s: commit信息标题
%f: sanitized subject line, suitable for a filename
%b: commit信息内容
%N: commit notes
%gD: reflog selector, e.g., refs/stash@{1}
%gd: shortened reflog selector, e.g., stash@{1}
%gs: reflog subject
%Cred: 切换到红色
%Cgreen: 切换到绿色
%Cblue: 切换到蓝色
%Creset: 重设颜色
%C(...): 制定颜色, as described in color.branch.* config option
%m: left, right or boundary mark
%n: 换行
%%: a raw %
%x00: print a byte from a hex code
%w([[,[,]]]): switch line wrapping, like the -w option of git-shortlog(1).

使用示例:

git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative

为了方便使用可以把它命名为 git 别名:

git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"

docsify , https://docsify.js.org/#/zh-cn/quickstart 快速、简单的文档网站生成工具。
在本地使用 node.js 创建好文档站点后,将静态文件发布即可。
支持本地化多语言、模板、插件、全文搜索。

免费音乐素材下载 https://icons8.com/music

需要快速了解一门编程语言?
试试这个:
”Learn X in Y minutes“ https://learnxinyminutes.com

tmux

tmux 是 Linux 下的一款终端复用工具, 类似 screen,但功能比 screen 强大很多。

安装

  • Ubuntu: sudo apt-get install tmux
  • CentOS7: sudo yum install -y tmux
  • CentOS6: 官网 下载安装

常用操作

  • 创建会话:tmux new [-s session_name][ -d],(-d 指定在后台运行)如:创建一个名为 spider 的后台会话 tmux new -s spider -d
  • 查看会话列表: tmux ls
  • 登入某个会话: tmux attach -t session_name ,也可将 attach 简写为 atmux a -t session_name
  • 在某个会话中返回出来(会话中的操作并不会中止): ctrl+b - d
  • 销毁某个会话: tmux kill-session -t session_name
  • 重命名会话: tmux rename -t name_1 name_2

当进入某个会话时, 可先按下 ctrl+b 激活控制台快捷键,然后按下相应键进行相关操作:

快捷键 说明
系统类操作:
? 列出所有快捷键,按 q 退出
d 脱离当前会话,脱离后可用 attach 重新进入
D 选择要脱离的会话,多会话时适用
ctrl+z 挂起当前会话
s 选择并切换会话, 多会话时适用
: 进入命令行模式
窗口类操作:
c 创建窗口
& 关闭当前窗口
数字 切换到指定窗口
p 切换至上一窗口
n 切换至下一窗口
l 在前后两个窗口间互相切换
w 通过窗口列表切换窗口
f 在所有窗口中查找指定文本
面板类操作:
" 将当前面板上下平分切割
% 将当前面板左右平分切割
x 关闭当前面板
! 将当前面板放入一个新打开的窗口
ctrl+方向键 以1个单元格为单位调整当前面板大小
alt+方向键 以5个单元格为单位调整当前面板大小
space 依次切换使用预置面板布局
o 选中当前窗口的下一面板
方向键 选择面板
alt+o 逆时针旋转当前窗口的面板
ctrl+o 顺时针旋转当前窗口的面板
  • 查看当前进程列表: show processlist;

  • 当前运行的事务: SELECT * FROM information_schema.INNODB_TRX;

  • 当前的锁: SELECT * FROM information_schema.INNODB_LOCKs;

  • 锁的对应关系: SELECT * FROM information_schema.INNODB_LOCK_waits;

  • 批量终止事务:

    select concat('KILL ',id,';') from information_schema.processlist p inner
    join information_schema.INNODB_TRX x on p.id=x.trx_mysql_thread_id where db='DB_NAME';
    +------------------------+
    | concat('KILL ',id,';') |
    +------------------------+
    ————————————————
    

根据 MySQL 表结构、JSON 生成 Go Struct

根据 mysql 表结构生成 golang struct 的几个项目:

gohouse/converter

go 编写的,可通过命令行执行(需带连接dsn): https://github.com/gohouse/converter

Shelnutt2/db2struct

https://github.com/Shelnutt2/db2struct
也是 go 写的,命令行执行。如:

db2struct --host=localhost --database=mydb\
  --user=user1 --password=mypwd --package=model --gorm  \
  --target=user.go  --table=users --struct=User

idoubi/sql2struct

Chrome 插件形式,直接复制 SQL 表结构到转换窗口: https://github.com/idoubi/sql2struct

一个在线转换工具

http://sql2struct.atotoa.com/

根据 JSON 生成 Go 结构体

JSON-to-Go: 在线使用 https://mholt.github.io/json-to-go/ , code: https://github.com/mholt/json-to-go

将 Go 应用注册为 linux 系统服务

将 Go 应用注册为系统服务

vim /etc/systemd/system/my-web.service

[Unit]
Description=My Web Service

[Service]
ExecStart=/data/web/my-web/go-whisper
WorkingDirectory=/data/web/my-web/
Restart=always
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=something-web-service
User=ubuntu

[Install]
WantedBy=multi-user.target

启用服务:sudo systemctl enable my-web.service 开始服务:sudo systemctl status my-web.service

Marp 是一个使用 Markdown 创建幻灯片的方案。支持多种导出格式(PPT、PDF、HTML等)。
官网: https://marp.app/
github: https://github.com/marp-team/marp

卸载阿里云盾

卸载

wget http://update.aegis.aliyun.com/download/uninstall.sh
chmod +x uninstall.sh
./uninstall.sh
wget http://update.aegis.aliyun.com/download/quartz_uninstall.sh
chmod +x quartz_uninstall.sh
./quartz_uninstall.sh

删除残余文件

pkill aliyun-service
rm -fr /etc/init.d/agentwatch /usr/sbin/aliyun-service
rm -rf /usr/local/aegis*

屏幕云盾IP

iptables -I INPUT -s 140.205.201.0/28 -j DROP
iptables -I INPUT -s 140.205.201.16/29 -j DROP
iptables -I INPUT -s 140.205.201.32/28 -j DROP
iptables -I INPUT -s 140.205.225.192/29 -j DROP
iptables -I INPUT -s 140.205.225.200/30 -j DROP
iptables -I INPUT -s 140.205.225.184/29 -j DROP
iptables -I INPUT -s 140.205.225.183/32 -j DROP
iptables -I INPUT -s 140.205.225.206/32 -j DROP
iptables -I INPUT -s 140.205.225.205/32 -j DROP
iptables -I INPUT -s 140.205.225.195/32 -j DROP
iptables -I INPUT -s 140.205.225.204/32 -j DROP