275篇 Default中的文章

为localhost一步生成自签名证书

为localhost一步生成自签名证书

openssl req -x509 -days 365 -out localhost.crt -keyout localhost.key \
  -newkey rsa:2048 -nodes -sha256 \
  -subj '/CN=localhost' -extensions EXT -config <( \
   printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")
More ~

go可变参数传数组值

在https://github.com/qiniu/qmgo 中 有个方法是传排序参数,通常是一个或多个。

func (q *Query) Sort(fields ...string) QueryI {
	if len(fields) == 0 {
		// A nil bson.D will not correctly serialize, but this case is no-op
		// so an early return will do.
		return q
	}

	var sorts bson.D
	for _, field := range fields {
		key, n := SplitSortField(field)
		if key == "" {
			panic("Sort: empty field name")
		}
		sorts = append(sorts, bson.E{Key: key, Value: n})
	}
	newQ := q
	newQ.sort = sorts
	return newQ
}

若需传递多个fields, fields是个可变参数, 传值是你可能想支持多个,但对于参数个数也清楚, 那要先定义个字符串数组。

More ~

golang proxy

export GOPROXY=https://mirrors.aliyun.com/goproxy/
// or 
go env -w GOPROXY=https://mirrors.aliyun.com/goproxy
export GOPROXY=https://goproxy.io,direct

有时goproxy.io不好用时可以用阿里的。

More ~

使用iptables进行端口转发

使用iptables进行端口转发,如下,需要访问原主机的27017端口,但是没开放,只开放了5000-6000之间的端口,因此 需要映射 一个5027端口去访问27017 这个mongodb。

iptables -t nat -A PREROUTING  -p tcp --dport 5027 -j DNAT --to-destination :27017

列表:

iptables -t nat --list

删除
PREROUTING 后跟的index 索引从1开始

iptables -t nat --delete PREROUTING 2
More ~

flask: serve static file

Send a file from a given directory with :func:send_file. This
is a secure way to quickly expose static files from an upload folder or something similar.

from flask import Flask, request, send_from_directory

# set the project root directory as the static folder, you can set others.
app = Flask(__name__, static_url_path='')

@app.route('/js/<path:path>')
def send_js(path):
    return send_from_directory('js', path)

if __name__ == "__main__":
    app.run()
More ~

iTerm2批量删除主题

一次导入太多主题了,试了又用不上,想删了界面只提供单个删除。

还好装Xcode了,可以open ~/Library/Preferences/com.googlecode.iterm2.plist 用Xcode打开,定位到Custom Color Presets下面的主题名称上,长按住删除键即可很快删完。

20210112224451.png

More ~