The GNU Build System, also known as the Autotools, is a suite of programming tools designed to assist in making source code packages portable to many Unix-like systems.

一切操作的前提是服务的高可用性,高效性。

  1. 更新操作之前要有应对突发事件的准备(例如:更新失败,网络错误,硬件故障等等意想不到的能导致服务失败的可能性)
  2. 确保相关人员在更新操作后2个小时内能够及时响应。(建议周一—–周四,上午 10.00,下午 15.00,其他时间不推荐更新操作)
  3. 确保服务程序可以回退到更新前的版本,保证高可用性
  4. 多台服务,先更新一台,然后验证功能是否正常,确认无误后可以更新其他服务(要准备相关验证脚本或工具)
  5. 更新操作过程尽可能原子化 (推荐使用更新脚本或其他工具,后台执行,避免操作端出现意外故障导致更新操作处于中间状态)
  6. 要熟悉每个服务的相关指令和参数,加强岗位技能
  7. 只做必要操作(和本次更新无关的操作禁止执行)
  8. 针对每项服务要有更新流程清单。(记录每一步需要的操作和注意事项)

yum -y install docker
#启动 Docker 后台服务
service docker start
#测试运行 hello-world,由于本地没有hello-world这个镜像,所以会下载一个hello-world的镜像,并在容器内运行。
docker run hello-world

when I deploy some application on linux platform I found some application can run
in file manager through double click, but my application can’t. So I do some research.

short answer:

app has mime type:

  • application/x-executable
  • application/x-sharedlib

that x-executable file manager recognize it you can double click to run it.
but x-sharedlib has some security advantage, so x-sharedlib is recommended

long answer

you can use file --mime-type app see app’s mime type, also file app is working too.

gcc now defaults to building with PIE (Position Independent Executable) enabled on x86 Debian systems for security reasons.
The behavior is occurring because newer ubuntu distros set GCC default link flag -pie,
which marks e_type as ET_DYN on the binary file. Consequently, the Operating System recognizes as Shared Library.

-pie allows for some extra security protections that are fundamentally incompatible with -no-pie.

Qt project:
QMAKE_LFLAGS += -no-pie

目前支持以下功能

Use POST Request

获取接口列表 Get Reques

http://47.100.193.211:49911/api/v1.0/help

error return

{
“ErrorMsg”: “opcode not found”
}

parse tx string

http://47.100.193.211:49911/api/v1.0/tx2json/
{“coinType”:”primecoin”,”tx”:”01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0f03bad82a02780200062f503253482fffffffff0140b1b02b00000000232103a0c8d5d706a7f1d7b19ac2dcc25905d5fbb77a3e65a5b5160be972955593e3efac00000000”}
support coin type: primecoin|bitcoin
return

{
"Version": "1",
"Vin Count": "1",
"Vin": [
{
"RefBlock Hash": "0000000000000000000000000000000000000000000000000000000000000000",
"RefTxOut Index": "ffffffff",
"Data Length": "11",
"Data": "51013100062f503253482f",
"Sequence": "ffffffff"
}
],
"Vout Count": "1",
"Vout": [
{
"Amount": "2038000000",
"Script Length": "35",
"Locking Script": {
"Hex": "21037c9e467f50b27358ddd94788d716f96235541dd76ec377cbfb97bc5ed81043b8ac",
"Asm": "037c9e467f50b27358ddd94788d716f96235541dd76ec377cbfb97bc5ed81043b8 OP_CHECKSIG",
"Type": "P2PK",
"Address": [
"AZCmTX1BrevDXvfeJGUs3mUQa99goGDYFf"
],
"P2SH": ""
}
}
],
"Locking Value": "0"
}

convert little endian to big endian

http://47.100.193.211:49911/api/v1.0/l2b/
{“data”:”123456”}

return

{"data":"563412"}

use gitignore file exclusive files and folders

Note: gitignore only exclusive un-tracking file

globle config

git config --global core.excludesfile ~/.gitignore_global

locale config

In Terminal, navigate to the location of your Git repository.

touch .gitignore

example

# OS X
.DS_Store

ref

There are currently three address formats in use:
P2PKH which begin with the number 1, eg: 1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2.
P2SH type starting with the number 3, eg: 3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy.
Bech32 type starting with bc1, eg: bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq.

Misconceptions

Address reuse

Addresses are not intended to be used more than once, and doing so has numerous problems associated. See the dedicated article on address reuse for more details.

33b210fc.png

List of address prefixes

31dc90c3.png

Conversion from ECDSA public key to Bitcoin address

6a42dc8e.png

cannot import main package.
you can put code in one package for other package use.

包管理工具 dep

go get -u github.com/golang/dep/cmd/dep

下载二进制文件
https://github.com/golang/dep/releases

将dep-windows-amd64.exe放入GOPATH/bin下,修改名称为dep

初始化

  1. 切换到工程目录下cd %GOPATH%/src/github.com/xxx/dep-demo
  2. 初始化dep init

添加

预先添加到vendor中
dep ensure -add github.com/foo/bar github.com/baz/quux

更新

dep ensure -update

同步

四种情况:工程中引入包、移除包、Gopkg.toml规则修改、不确定情况

dep ensure

查看状态
运行
dep status
结果解释
CONSTRAINT为Gopkg.toml中限定的版本;
VERSION为当前vendor中的版本;
REVISION为当前vendor中的修订号;
LATEST为CONSTRAINT限定下github中能满足要求的最新版本。
修改限定版本并同步
修改Gopkg.toml中的CONSTRAINT,若使得LATEST低于当前vendor中的版本,则运行dep ensure后,vendor中的版本降低到能满足要求的最新版本;
若使得LATEST高于vendor中的版本,则运行dep ensure后,vendor中的版本不变,可使用dep ensure -update更新vendor到LATEST版本。

作者:gisxiaowei
链接:https://www.jianshu.com/p/e3c9f9039542
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

https://github.com/antonholmquist/jason

parsing json

must be predefined a struct.

var s Serverslice
str := `{"servers":[{"serverName":"Shanghai_VPN","serverIP":"127.0.0.1"},{"serverName":"Beijing_VPN","serverIP":"127.0.0.2"}]}`
json.Unmarshal([]byte(str), &s)
fmt.Println(s)
type response2 struct {
Page int `json:"page"`
Fruits []string `json:"fruits"`
}

res := response2{}
json.Unmarshal([]byte(str), &res)

json.Decoder vs json.Unmarshal

Go json.Decoder Considered Harmful
short answer is :
Do not use json.Decoder if you are not dealing with JSON streaming.

Use json.Unmarshal:

  • if you don’t know what Go JSON streams are
  • if you are working with a single JSON object at a time
  • if there is a remote possibility that the API may return malformed JSON

arbitrary json operate

package main

import (
"log"
"fmt"
"encoding/json"
"reflect"
)

func main() {
b := []byte(`{"name": "tom", "favNum": 6, "interests": ["knives", "computers"], "usernames": {"github": "TomNomNom", "twitter": "@TomNomNom"}}`)
var f interface{}
err := json.Unmarshal(b, &f)
if err != nil {
log.Fatal("Failed to parse JSON")
}

m := f.(map[string]interface{})

printStruct("", m)

}

func printStruct(prefix string, m map[string]interface{}) {
for k, v := range m {
switch vv := v.(type) {
case string:
fmt.Println(prefix, k, "is string", vv)
case float64:
fmt.Println(prefix, k, "is number", vv)
case []interface{}:
fmt.Println(prefix, k, "is an array:")
for i, u := range vv {
fmt.Println(prefix, i, u)
}
case map[string]interface{}:
fmt.Println(prefix, k, "is a map:")
printStruct(prefix + " ", vv)
default:
fmt.Println(prefix, k, "is a type we can't handle", vv)
}
}
}



//ref: http://michaelheap.com/golang-encodedecode-arbitrary-json/ 18/8/15

// Using some hand crafted JSON. This could come from a file, web service, anything
str2 := `{
"foo": {
"baz": [
1,
2,
3
]
},
"flag": true,
"list": [
"one",
2,
true,
"4",
{
"key": "value"
},
[
1,
true
]
]
}`

var y map[string]interface{}
json.Unmarshal([]byte(str2), &y)

fmt.Printf("%+v\n", y)
//# => map[foo:map[baz:[1 2 3]] flag:true list:[one 2 true 4 map[key:value] [1 true]]]
/*
As we’re un-marshalling into an interface, we need to inform go what data type
each key is before we can perform operations on it. Go provides a the "reflect"
package which we can use to process arbitrarily complex data structures:
*/

the_list := y["list"].([]interface{})
for n, v := range the_list {
fmt.Printf("index:%d value:%v kind:%s type:%s\n", n, v, reflect.TypeOf(v).Kind(), reflect.TypeOf(v))
}

//# =>
//index:0 value:one kind:string type:string
//index:1 value:2 kind:float64 type:float64
//index:2 value:true kind:bool type:bool
//index:3 value:4 kind:string type:string
//index:4 value:map[key:value] kind:map type:map[string]interface {}
//index:5 value:[1 true] kind:slice type:[]interface {}

map to json

// Marshal the map into a JSON string.
empData, err := json.Marshal(emp)
if err != nil {
fmt.Println(err.Error())
return
}

jsonStr := string(empData)