Skip to content

Instantly share code, notes, and snippets.

@yougg
Created April 4, 2022 12:53
Show Gist options
  • Save yougg/55bfd0e1c464373733e3cd808d97bf41 to your computer and use it in GitHub Desktop.
Save yougg/55bfd0e1c464373733e3cd808d97bf41 to your computer and use it in GitHub Desktop.
Command Note

Command Note

@yougg
Copy link
Author

yougg commented Apr 4, 2022

编程语言

Go

单元测试

盖率报告
go test -cover -coverprofile=cover.out -covermode=count
go tool cover -html cover.out -o cover.html
测试包
# 测试当前包
go test .
# go test会在GOROOT和GOPATH下查找这个包并执行包的测试
go test fmt
# 测试整个包
go test github.com/yougg/pool/...

静态链接

引用了net包的程序, 编译时默认会动态链接

CGO_ENABLED=0 go build -installsuffix cgo yourcode.go
# 首先需要静态链接标准库中的net包
go install -tags netgo -a -v std
# 然后再编译自己的程序
CGO_ENABLED=0 go build yourcode.go

使用gccgo静态编译引用了cgo代码的程序

# static cgo
go build --ldflags '-extldflags "-static"' yourcode.go
# gccgo
go build -compiler gccgo --gccgoflags "-static" yourcode.go

Python

域名解析

#!/usr/bin/env python
#coding=utf8

import socket
import traceback

def resolv(url):
    try:
        while True:
            socket.getaddrinfo(url, 80, 0, socket.SOCK_STREAM)
            s = socket.socket()
            s.connect((url, 80))
            s.close()
    except Exception as e:
        print "Exception: %s\n" % e
        traceback.print_exc()

resolv("domain.example.com")

@yougg
Copy link
Author

yougg commented Apr 4, 2022

Tool/Software/Middleware

MySQL

启用用户远程连接权限

grant all privileges on *.* to ${username}@${IP} identified by '${pwd}' with grant option;
flush privileges;

超级权限

grant super on *.* to 'my_user'@'localhost';
revoke super on *.* from 'my_user'@'localhost';

连接数据库

mysql -h ${IP} -P ${Port} -D ${database} -u ${user} -p${pwd}

本地MySQL调试

docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=pa55w0rd --name DB mysql
docker exec -it DB bash
mysql -u root -ppa55w0rd

Docker

从镜像复制文件到其他镜像

COPY --from=ochinchina/supervisord:latest /usr/local/bin/supervisord /usr/local/bin/supervisord

列出镜像ID、摘要

docker images -f=reference='registry.example.com/*/*' --format "table {{.Repository}}:{{.Tag}}\t{{.Digest}}\t{{.CreatedSince}}"

docker image ls --format "table {{.Repository}}:{{.Tag}}\t{{.Digest}}\t{{.CreatedSince}}" registry.example.com/group*/*
docker image ls --format "{{.Repository}}:{{.Tag}}" registry.example.com/group*/*

IDE/Editor

编译Webkit版本的LietIDE

sudo apt install qt4-qmake libqt4-dev libqtwebkit-dev
go get github.com/visualfc/gotools
cd ${SRC}/liteide/build/
chmod +x build_linux_qt4_webkit.sh
./build_linux_qt4_webkit.sh
cp -rf liteide ~/

Emacs Shortcut

image
image
image

Git

切换远程仓库路径

git remote set-url origin https://github.com/user/FORK.git

添加子模块

cd parent_project
git submodule add https://github.com/username/subproject.git external/src
git submodule update --init --recursive external/src
cd external/src
git checkout -b develop origin/develop
cd ..
git add .
git commit -m 'Add submodule'
git push

同步子模块

git submodule update --init --force --recursive

删除子模块

  1. Delete the relevant section from the .gitmodules file.
git config -f .gitmodules --remove-section submodule.src

Stage the .gitmodules changes git add .gitmodules

  1. Delete the relevant section from .git/config.
git config --remove-section submodule.src
  1. Delete submodule and folder
git rm --cached path_to_submodule
rm -rf .git/modules/path_to_submodule
git commit -m "Removed submodule <name>"
  1. Delete the now untracked submodule files
rm -rf path_to_submodule

git克隆保存用户/密码

git clone http://username:password@github.com/user/project.git

git指定提交时的作者和邮箱

GIT_AUTHOR_NAME="some one" GIT_AUTHOR_EMAIL="someone@email.com" GIT_COMMITTER_NAME="some one" GIT_COMMITTER_EMAIL="someone@email.com" git commit -m 'message'
git push -f --set-upstream origin master

配置git diff使用vimdiff

git config --global diff.tool vimdiff
git config --global difftool.prompt false
git config --global alias.d difftool

使用方式

git difftool
git d

如果执行报错

Can't locate Error.pm in @inc ......

则执行如下方式后再操作

cpan Error.pm

或者

sudo perl -MCPAN -e 'install Error'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment