golang 排序

golang 排序 Go 的排序思路和 C 和 C++ 有些差别。 C 默认是对数组进行排序, C++ 是对一个序列进行排序, Go 则更宽泛一些,待排序的可以是任何对象, 虽然很多情况下是一个 slice (分片, 类似于数组),或是包含 slice 的一个对象。 排序(接口)的三个要素: 待排序元素个数 n ; 第 i 和第 j 个元素的比较函数 cmp ; 第 i 和 第 j 个元素的交换 swap ; 乍一看条件 3 是多余的, c 和 c++ 都不提供 swap 。 c 的 qsort 的用法: qsort(data, n, sizeof(int), cmp_int); data 是起始地址, n 是元素个数, sizeof(int) 是每个元素的大小, cmp_int 是一个比较两个 int 的函数。 c++ 的 sort 的用法: sort(data, data+n, cmp_int); data 是第一个元素的位置, data+n 是最后一个元素的下一个位置, cmp_int 是比较函数。 ...

2020-03-04 · 1 min · 159 words · -

golang read docx

golang read docx https://github.com/unidoc/unioffice

2020-03-03 · 1 min · 4 words · -

Maven Dependency Version 依赖版本自动升级

Maven Dependency Version 依赖版本自动升级 [1.15.0,2.0.0) x>=1.15.0 && x<2.0.0 依赖调节是为了解决版本不一致的问题(multiple versions),并采取就近原则(nearest definition)。 举例来说,A项目通过依赖传递依赖了两个版本的D: A -> B -> C -> ( D 2.0 ) , A -> E -> ( D 1.0 ) 复制代码那么最终A依赖的D的version将会是1.0,因为1.0对应的层级更少,也就是更近。 除了我们常用的1.1.0,在声明依赖版本的时候,可以通过表达式灵活地配置版本号。 例如配置jar包x的标签支持如下几种语法: 1.0: 推荐依赖版本,此版本号可能会被覆盖。 复制代码还可以控制依赖的版本范围: (,1.0]: x <= 1.0 [1.2,1.3]: 1.2 <= x <= 1.3 [1.0,2.0): 1.0 <= x < 2.0 [1.5,): x >= 1.5 复制代码同时声明多个版本范围也是可以的,只要用逗号分隔即可: (,1.0],[1.2,): x <= 1.0 或者 x >= 1.2 ...

2020-03-03 · 1 min · 83 words · -

各种胎压,气压 – 小米充气宝

各种胎压,气压 – 小米充气宝 小米平衡车 plus 轮胎标注 35 psi = 2.413bar 官网建议 45~50 Psi 小宝的皮球 19 psi 有点硬下次试试 15 psi 高尔夫 2.5 bar = 36.26psi

2020-03-01 · 1 min · 24 words · -

firewall 防火墙

firewall 防火墙 device 物理设备 context 物理设备上的虚拟防火墙, 类似于虚拟机的概念 每个 context 可以被看作是一个独立的防火墙实例。每个 context 拥有自己的配置文件、策略和规则集,使得单个物理设备能够同时作为多个独立的防火墙进行操作。 VRF VRF(Virtual Routing and Forwarding) VRF 和 Context 是独立的概念 VRF 是一种在同一物理设备上创建多个虚拟路由表的方法,使得不同的网络流量可以在相同的物理接口上保持逻辑隔离。VRF 主要用于以下场景: 多租户环境:在服务提供商或大型企业网络中,VRF 允许不同的客户或部门共享相同的物理网络设备而保持独立的路由表。 安全隔离:VRF 可以将不同的业务流量在逻辑上隔离开,确保不同业务之间的安全性和隐私性。 灵活性和可扩展性:通过使用 VRF,可以在不增加额外硬件的情况下,灵活地管理和扩展网络。

2020-03-01 · 1 min · 30 words · -

java 开发环境

java 开发环境 jdk wiloon.com/jdk 安装 maven https://maven.apache.org/download.cgi apache-maven-3.6.3-bin.zip 安装 idea https://www.jetbrains.com/idea/download/#section=windows https://download.jetbrains.8686c.com/idea/ideaIC-2019.3.3.exe 安装 eclipse https://www.eclipse.org/downloads/packages/ Eclipse IDE for Java Developers, Windows 64-bit subclipse https://github.com/subclipse/subclipse/wiki Help>Install New Software>Add latest: https://dl.bintray.com/subclipse/releases/subclipse/latest/

2020-02-28 · 1 min · 29 words · -

JAVA 奇偶数

JAVA 奇偶数 int val=//一个数字 if(val%2==0) System.out.println("偶数"); else System.out.println("奇数"); https://blog.csdn.net/x369201170/article/details/8611485

2020-02-26 · 1 min · 9 words · -

番茄工作法, 番茄钟, Pomodoro

‘番茄工作法, 番茄钟, Pomodoro’ 简单来说,就是把工作时间划分为多个番茄时间。一个番茄时间包含两个部分: 25分钟的工作学习和5分钟的休息。

2020-02-24 · 1 min · 5 words · -

Golang,Signal

Golang,Signal https://colobu.com/2015/10/09/Linux-Signals/ 信号(Signal)是Linux, 类Unix和其它POSIX兼容的操作系统中用来进程间通讯的一种方式。一个信号就是一个异步的通知,发送给某个进程,或者同进程的某个线程,告诉它们某个事件发生了。 当信号发送到某个进程中时,操作系统会中断该进程的正常流程,并进入相应的信号处理函数执行操作,完成后再回到中断的地方继续执行。 如果目标进程先前注册了某个信号的处理程序(signal handler),则此处理程序会被调用,否则缺省的处理程序被调用。 signals := make(chan os.Signal) signal.Notify(signals, os.Interrupt, os.Kill, syscall.SIGTERM) // ... for s := range signals { if s == os.Interrupt || s == os.Kill || s == syscall.SIGTERM { break } } signal.Stop(signals) Go中的Signal发送和处理 有时候我们想在Go程序中处理Signal信号,比如收到SIGTERM信号后优雅的关闭程序(参看下一节的应用)。 Go信号通知机制可以通过往一个channel中发送os.Signal实现。 首先我们创建一个os.Signal channel,然后使用signal.Notify注册要接收的信号。 package main import “fmt” import “os” import “os/signal” import “syscall” func main() { // Go signal notification works by sending os.Signal // values on a channel. We’ll create a channel to // receive these notifications (we’ll also make one to // notify us when the program can exit). sigs := make(chan os.Signal, 1) done := make(chan bool, 1) // signal.Notify registers the given channel to // receive notifications of the specified signals. signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) // This goroutine executes a blocking receive for // signals. When it gets one it’ll print it out // and then notify the program that it can finish. go func() { sig := <-sigs fmt.Println() fmt.Println(sig) done <- true }() // The program will wait here until it gets the // expected signal (as indicated by the goroutine // above sending a value on done) and then exit. fmt.Println(“awaiting signal”) <-done fmt.Println(“exiting”) } go run main.go执行这个程序,敲入ctrl-C会发送SIGINT信号。 此程序接收到这个信号后会打印退出。 ...

2020-02-24 · 2 min · 368 words · -

Go SOCKS5 proxy, http proxy

golang SOCKS5 proxy, http proxy https://segmentfault.com/a/1190000038247560 https://github.com/wiloon/pingd-proxy https://golangnote.com/topic/258.html

2020-02-23 · 1 min · 8 words · -

golang http

golang http get resp, err := http.Get("http://example.com/") http post func httpPostForm() { // params:=url.Values{} // params.Set("hello","fdsfs") //这两种都可以 params= url.Values{"key": {"Value"}, "id": {"123"}} resp, _:= http.PostForm("http://baidu.com", body) defer resp.Body.Close() body, _:= ioutil.ReadAll(resp.Body) fmt.Println(string(body)) } proxy https://www.flysnow.org/2016/12/24/golang-http-proxy.html package main import ( "bytes" "fmt" "io" "log" "net" "net/url" "strings" ) func main() { log.SetFlags(log.LstdFlags | log.Lshortfile) l, err := net.Listen("tcp", ":8080") if err != nil { log.Panic(err) } for { client, err := l.Accept() if err != nil { log.Panic(err) } go handleClientRequest(client) } } func handleClientRequest(client net.Conn) { if client == nil { return } defer client.Close() log.Println(client.RemoteAddr()) var b [1024]byte n, err := client.Read(b[:]) if err != nil { log.Println(err) return } var method, host, address string fmt.Sscanf(string(b[:bytes.IndexByte(b[:], '\n')]), "%s%s", &method, &host) hostPortURL, err := url.Parse(host) if err != nil { log.Println(err) return } if hostPortURL.Opaque == "443" { //https访问 address = hostPortURL.Scheme + ":443" } else { //http访问 if strings.Index(hostPortURL.Host, ":") == -1 { //host不带端口, 默认80 address = hostPortURL.Host + ":80" } else { address = hostPortURL.Host } } //获得了请求的host和port,就开始拨号吧 server, err := net.Dial("tcp", address) if err != nil { log.Println(err) return } if method == "CONNECT" { fmt.Fprint(client, "HTTP/1.1 200 Connection established\r\n\r\n") } else { server.Write(b[:n]) } //进行转发 go io.Copy(server, client) io.Copy(client, server) } https://segmentfault.com/a/1190000013262746

2020-02-23 · 1 min · 206 words · -

Shell 判断进程是否存在

Shell 判断进程是否存在 #! /bin/bash function check(){ count=`ps -ef |grep $1 |grep -v "grep" |wc -l` #echo $count if [ 0 == $count ];then nohup python /runscript/working/$1 & fi } ———————————————— 版权声明: 本文为CSDN博主「栎枫」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。 原文链接: https://blog.csdn.net/superbfly/article/details/52513765

2020-02-19 · 1 min · 38 words · -

hyphen、en dash 和 em dash

hyphen、en dash 和 em dash https://cherysunzhang.com/2016/08/using-hyphen-and-dash-correctly/ 在 Unicode 中 hyphen-minus 与 hyphen 和 minus 都是不同的符号,但是在 ASCII 中则是用 hyphen-minus 来同时替代 hyphen 和 minus,所以这就是其名称的来源。 为了适应早期的打字机和计算机,不得不作出妥协。除了用 hyphen-minus 这个符号来代替 hyphen 和 minus,以前经常还会用它直接代替 en dash。 因为大部分的编程语言都限制只能够使用 ASCII,所以在编写代码时所使用的表示负数或数字相减的符号即是 hyphen-minus,以及在变量名称中使用的连接符号。 另外,Unicode 中还有一个类似的 full hyphen-minus (-) 。

2020-02-18 · 1 min · 39 words · -

golang init

golang init init函数的主要作用: 初始化不能采用初始化表达式初始化的变量。 程序运行前的注册。 实现sync.Once功能。 其他 init函数的主要特点: init函数先于main函数自动执行,不能被其他函数调用; init函数没有输入参数、返回值; 每个包可以有多个init函数; 包的每个源文件也可以有多个init函数,这点比较特殊; 同一个包的init执行顺序,golang没有明确定义,编程时要注意程序不要依赖这个执行顺序。 不同包的init函数按照包导入的依赖关系决定执行顺序。 golang程序初始化 golang程序初始化先于main函数执行,由runtime进行初始化,初始化顺序如下: 初始化导入的包(包的初始化顺序并不是按导入顺序(“从上到下”)执行的,runtime需要解析包依赖关系,没有依赖的包最先初始化,与变量初始化依赖关系类似,参见golang变量的初始化); 初始化包作用域的变量(该作用域的变量的初始化也并非按照“从上到下、从左到右”的顺序,runtime解析变量依赖关系,没有依赖的变量最先初始化,参见golang变量的初始化); 执行包的init函数;

2020-02-18 · 1 min · 19 words · -

word basic

word basic 英文破折号、连接号、连字符、负号的区别 Hyphen (-) Hyphen 的 Unicode 编码是 U+2010,在 MS Word 里可以先输入 2010 再按 Alt +x。 不过在 ASCII 编码系统中,hyphen 被编为45号字符「hyphen-minus」,也就是我们电脑键盘上「0」和「=」之间的那个「-」。在通常情况下我们直接使用这个符号就可以了。 MS Word 中 hyphen后面跟数字, 在换行时会被拆开显示。 · En dash (–) En dash 的 Unicode 编码是 U+2013,在 MS Word 里可以先输入 2013 再按 Alt + x,更简便的方法是利用 MS Word 的自动更正功能: 按空格,按两下「-」,再按空格,例如输入「this is - atest」,将转换为「this is – a test」 (当然,要注意 en dash 前后一般是不留空格的) 。 En dash 在 Windows 里可以用 Alt + 0150 (即按下 Alt 键的同时依次按下 0150) 来输入,在 Mac 里可以用⌥+ - 来输入,在 TeX 里可以用 - 输入,在 HTML 里可以用 – 来输入。 ...

2020-02-18 · 1 min · 192 words · -

chrome os, crostini, 开发环境

chrome os, crostini, 开发环境 crostini 的Debian 对snap 支持不全, 不能使用snap 应用 terminal https://snugug.com/musings/developing-on-chrome-os/ terminal, tilix crostini默认的terminal在使用oh my zsh时,光标显示不正常。 安装tilix,从chromeos启动tilix使用terminal sudo pacman -S tilix # 在chromeos中启动tilix使用shell 或者使用Secure Shell App idea 慢的问题 File->Settings->Plugins. Click marketplace, search for “Choose Runtime” Install official Choose Runtime addon from JetBrains Wait for install and click to restart IDE. Once back in project, press shift twice to open the search window Search for Runtime. Select “Choose Runtime” Change to “jbrsdk-8u-232-linux-x64-b1638.6.tar.gz”, which should be the very last one at the bottom of the list. ...

2020-02-17 · 1 min · 93 words · -

xxd

xxd, 以 16进制查看文件 xxd 命令用于使用二进制或十六进制格式显示文件内容,可以将指定文件或标准输入以十六进制转储,也可以把十六进制转储转换成原来的二进制形式。 command xxd -b file xxd file

2020-02-14 · 1 min · 11 words · -

tr command

tr command # 转大写 echo 'hello' | tr '[:lower:]' '[:upper:]' # 转小写 echo 'HELLO' | tr '[:upper:]' '[:lower:]' # 删除文本中的换行符 tr -d '\n' < input.txt > output.txt # 删除空行 cat file | tr -s "\n" > new_file tr -s "[\012]" < plan.txt tr -s ["\n"] < plan.txt 什么是 tr 命令? tr, translate 的简写 \NNN character with octal value NNN (1 to 3 octal digits) \\ backslash \a audible BEL \b backspace \f form feed \n new line \r return \t horizontal tab \v vertical tab CHAR1-CHAR2 all characters from CHAR1 to CHAR2 in ascending order [CHAR*] in SET2, copies of CHAR until length of SET1 [CHAR*REPEAT] REPEAT copies of CHAR, REPEAT octal if starting with 0 [:alnum:] all letters and digits [:alpha:] all letters [:blank:] all horizontal whitespace [:cntrl:] all control characters [:digit:] all digits [:graph:] all printable characters, not including space [:lower:] all lower case letters [:print:] all printable characters, including space [:punct:] all punctuation characters [:space:] all horizontal or vertical whitespace [:upper:] all upper case letters [:xdigit:] all hexadecimal digits [=CHAR=] all characters which are equivalent to CHAR https://blog.csdn.net/jeffreyst_zb/article/details/8047065 通过使用tr,您可以非常容易地实现 sed 的许多最基本功能。您可以将 tr 看作为 sed的 (极其) 简化的变体: 它可以用一个字符来替换另一个字符,或者可以完全除去一些字符。您也可以用它来除去重复字符。这就是所有 tr所能够做的。 ...

2020-02-14 · 5 min · 1054 words · -

golang unsigned shift, 无符号右移

‘golang unsigned shift, 无符号右移’ int32 转 uint32 再右移 https://stackoverflow.com/questions/33336336/go-perform-unsigned-shift-operation func Test10(t *testing.T) { x1 := -100 result := uint32(x1) >> 2 fmt.Println(result) }

2020-02-11 · 1 min · 23 words · -

golang interface

golang interface interface 是一种类型 type foo interface { Get() int } 首先 interface 是一种类型,从它的定义可以看出来用了 type 关键字,更准确的说 interface 是一种具有一组方法的类型,这些方法定义了 interface 的行为。 go 允许不带任何方法的 interface ,这种类型的 interface 叫 empty interface。 如果一个类型实现了一个 interface 中所有方法,我们说类型实现了该 interface,所以所有类型都实现了 empty interface,因为任何一种类型至少实现了 0 个方法。go 没有显式的关键字用来实现 interface,只需要实现 interface 包含的方法即可。 ‘golang 获取interface{} 的数据类型’ https://blog.csdn.net/xia_xing/article/details/49423771 interface{} 可以接受任何类型的对象值 获取interface{}队形的数据类型,可以使用断言,或者 switch type 来实现 // Assertion project main.go package main import ( “fmt” ) type Bag struct { Key string } type Bag2 struct { Key int } func main() { ...

2020-02-11 · 1 min · 183 words · -