Skip to content

Instantly share code, notes, and snippets.

View cpusoft's full-sized avatar

cpusoft cpusoft

  • Beijing
View GitHub Profile
@cpusoft
cpusoft / golang x509 验证子证书
Created September 15, 2020 04:33
golang x509 验证子证书
https://play.golang.org/p/1BNLthzu5Tz
https://stackoverflow.com/questions/59383823/how-to-verify-a-certificate-against-an-issuing-chain-in-go
package main
import (
"crypto/x509"
"encoding/pem"
"log"
"time"
@cpusoft
cpusoft / 得到协程的返回值
Last active July 16, 2020 09:32
得到协程的返回值
// go routine 返回值,main一般是不能获取的
// 需要通过channel,打通通道,得到返回值
package main
import (
"fmt"
"net/http"
)
@cpusoft
cpusoft / 通过设置GOPROXY下载go依赖
Created April 22, 2020 03:00
通过设置GOPROXY下载go依赖
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.io,direct
# 设置不走 proxy 的私有仓库,多个用逗号相隔(可选)
go env -w GOPRIVATE=*.corp.example.com
@cpusoft
cpusoft / 通过代理下载golang.org
Created January 7, 2020 04:29
通过代理下载golang.org
@cpusoft
cpusoft / vi下显示回车换行符等特殊符号
Created December 23, 2019 07:47
vi下显示回车换行符等特殊符号
vi下显示回车换行符等特殊符号
在早期的打印机时代,开始新的一行要占用两个字符的时间。如果到了一行的结尾处,你要快速回到新的一行的开头,需要打印针头在纸面上飞快地掠过,常常会在纸面上留下污点。
解决这个问题的办法就是,用两个字符:一个字符<Return>来移到第一列,另一个字符<Line feed>来新增一行。计算机产生以后,存储较为昂贵,在如何解决回车换行这个老问题上,人们产生了不同的意见。
UNIX人认为在到达一行的结尾时新增一行<Line feed> (LF),而Mac人则认同<Return> (CR)的解决办法,MS则坚持古老的<Return><Line feed> (CRLF)的方法。这就意味着如果你将一个文件从一个系统转移到另一个系统,就面临着回车换行的问题。而Vim编辑器则会自动的认出这种文件格式方面的区别,并做出相应处理。
:set fileformats=unix,dos
@cpusoft
cpusoft / asn1 optional default
Last active November 29, 2019 14:49
asn1 optional default
type ROAIPAddress struct {
Address asn1.BitString `json:"address"`
MaxLength int `asn1:"optional,default:-1" json:"maxLength"`
}
@cpusoft
cpusoft / channel.md
Created November 29, 2019 06:42 — forked from xin053/channel.md
[go channel] go channel #go #channel

channel 重点

Operation A Nil Channel A Closed Channel A Not-Closed Non-Nil Channel
Close panic panic succeed to close (C)
Send Value To block for ever panic block or succeed to send (B)
Receive Value From block for ever never block (D) block or succeed to receive (A)

一个基于无缓存 channel 的发送操作将导致发送者 goroutine 阻塞, 直到另一个 goroutine 在相同的 channel 上执行接收操作, 当发送的值通过 channel 成功传输之后, 两个 goroutine 可以继续执行后面的语句, 反之,如果接收操作先发生, 那么接收者 goroutine 也将阻塞, 直到有另一个 goroutine 在相同的 channel 上执行发送操作

@cpusoft
cpusoft / rsync使用
Created September 24, 2019 01:07
rsync使用
rsync -Lrts --del --no-motd --include="*.roa" --include="*/" --exclude="*" /root/rpki/repo/repo /root/rpki/repo/repo-1
@cpusoft
cpusoft / shutdown.sh
Last active May 10, 2019 01:43
shutdown.sh
pid=`ps -ef|grep '/web/tomcat/'|grep -v grep|awk '{print $2}'`
echo "The current process id is $pid"
if [ "$pid" = "" ]; then
echo "pid is null"
else
kill -9 $pid
echo "shutdown success"
fi
@cpusoft
cpusoft / 查询RIR 根据ip得到AS数据
Last active May 6, 2019 09:57
查询RIR 根据ip得到AS数据
查询RIR 根据ip得到AS数据
whois -h whois.apnic.net 1.0.0.0
% [whois.apnic.net]
% Whois data copyright terms http://www.apnic.net/db/dbcopyright.html
% Information related to '1.0.0.0 - 1.0.0.255'
% Abuse contact for '1.0.0.0 - 1.0.0.255' is '[email protected]'