280篇 Default中的文章

ubuntu: Read-only file system

文件系统挂了,变成只读模式。supervisor无法启动,就连ping 域名时无法解析dns,想要修改/etc/resolve.conf,只读也写不进去。
试下往临时目录写也是这:

touch /tmp/aaa.txt
touch: cannot touch '/tmp/aaa.txt': Read-only file system
More ~

CRLF to LF

You can use vim programmatically with the option -c {command} :

Dos to Unix:

vim file.txt -c "set ff=unix" -c ":wq"

Unix to dos:

vim file.txt -c "set ff=dos" -c ":wq"

"set ff=unix/dos" means change fileformat (ff) of the file to Unix/DOS end of line format

":wq" means write file to disk and quit the editor (allowing to use the command in a loop)

More ~

git 找回已删除的文件

找出已删除文件的提交记录:

git rev-list -n 1 HEAD -- <file_path>

返回为commit id

使用提交记录ID检出文件, commit id后缀**^**:

git checkout <commit id>^ -- <file_path>

或者一行命令:

$file 是文件路径

git checkout $(git rev-list -n 1 HEAD -- "$file")^ -- "$file"
More ~

为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 ~