• 冬日,微微寒风,太阳暖照,饭后散步,偶现路边花香蝶飞,掏出小米 14,记录那片阳光
    IMG_20231203_131641.jpg
    IMG_20231203_131644.jpg
    IMG_20231203_131623_1.jpg
    IMG_20231203_131627.jpg

  • 海尔智家

    已支持实体

    1. Switch
    2. Number
    3. Select
    4. Sensor
    5. Binary Sensor
    6. Climate (Beta)

    地址:https://github.com/banto6/haier

    美的美居

    地址:https://github.com/georgezhao2010/midea_ac_lan

  • Spring in Action, Fifth Edition

    Spring in Action, 5th Edition is the fully updated revision of Manning's bestselling Spring in Action. This new edition includes all Spring 5.0 updates, along with new examples on reactive programming, Spring WebFlux, and microservices. You'll also find the latest Spring best practices, including Spring Boot for application setup and configuration.

    开始阅读:Spring in Action, Fifth Edition

  • 查看

    1ifconfig
    

    查看当前所有端口的 mac

    1networksetup -listallhardwareports
    

    生成新的随机 mac 地址

    1openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//'
    

    断开当前无线网卡连接

    1sudo /System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -z
    

    修改

    1sudo ifconfig en0 ether 10:4A:7D:A8:03:54
    

    重新连接网卡

    1networksetup -detectnewhardware
    
  • 直接上 demo 代码

     1FROM golang:alpine as builder
     2WORKDIR /app
     3COPY . /app
     4RUN set -x \
     5    && sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
     6    && apk update \
     7    && apk --no-cache add tzdata upx \
     8    && go env -w GO111MODULE=on \
     9    && go env -w GOPROXY=https://goproxy.cn,direct \
    10    && go env -w CGO_ENABLED=0 \
    11    && go env -w GOOS=linux
    12RUN set -x \
    13    && go build -ldflags "-s -w" -o server_temp \
    14    && upx -9 server_temp -o server \
    15    && rm -f server_temp
    16FROM scratch as production
    17COPY --from=builder /app/server .
    18COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
    19EXPOSE 8080
    20CMD ["/server"]
    

    详细说明

    1. 分为构建和应用两部分,分开的后,最终实际只用到了构建的成品,所有构建前的源码以及构建过程产生的缓存包,还有构建环境其实都没有大的作用,docker 本身就用 go 写的,所有有个特性,可以直接打成 docker 底层包放到 docker 空镜像里使用。
    2. 国内源, go mod 就不多说了
    1sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
    
    1go env -w GO111MODULE=on \
    2go env -w GOPROXY=https://goproxy.cn,direct \
    
    1. 打包方式
      关闭 cgo,默认 cgo 为开启状态(1),在 cgo 开启状态下允许你在 Go 代码中调用 C 代码,go 部分包中有 c 语言的实现,开启状态下可能会有动态引用外部。具体可以看 go 的可移植性和 c 的比较
    1go env -w CGO_ENABLED=0
    

    GOOS 为 linux,可以指定编译的环境,可根据情况填写

    1GOOS=linux
    
    1. 编译,添加编译参数 -ldflags "-s -w" ,如果用变量加个-X,设置如下
    1go build -ldflags "-s -w" -o server_temp
    

    关于-ldflags 说明

    1-w 去掉DWARF调试信息,得到的程序就不能用gdb调试了。
    2-s 去掉符号表,panic时候的stack trace就没有任何文件名/行号信息了,这个等价于普通C/C++程序被strip的效果,
    3-X 设置包中的变量值
    
    1. 借助第三方工具再压缩 upx, upx 后面压缩值为-1~-9,1 压缩速度最快,9 压缩最小
    1upx -9 server_temp -o server
    
  • hexo-shortlink

    A Hexo plugin for generate static post link based on post file name.

    Install

    Add plugin to Hexo:

    1npm install hexo-shortlink --save
    

    Modify permalink in config.yml file:

    1permalink: :shortlink.html
    

    Sample

    The generated link will look like the following:

    1source: _posts/books/a-book.md
    2permalink: /books/261f97f7.html
    3
    4source: _posts/hello-word.md
    5permalink: /b1d4025b.html
    6
    7source: _posts/books/computer/a-book.md
    8permalink: /books/computer/261f97f7.html
    

    Customize permalink

    Set shortlink in front-matter, example:

    1---
    2title: 'hello word'
    3shortlink: myshortlink
    4---
    

    The permalink will look like the following:

    1/myshortlink.html
    2/books/myshortlink.html
    3/books/computer/myshortlink.html
    

    ThanksFor

    Rozbo sheetjs

  • 一.前言

    操作系统: win10+Hyper-V+CentOS-7-x86_64-Minimal-1511

    连接工具:Termuis

    二.环境依赖

    1. git
    2. wget/curl
    3. docker 和 docker-compose
    4. nodejs 和 npm
    5. python2.7 和 pip
    6. go
    7. gcc+ gcc-c++

    1.git 安装

    1yum install git -y
    

    2.wget/curlt 安装

    一般自带都有吧

    3.docker 和 docker-compose 安装

    docker 安装

    更改 docker 国内加速源:
    可以通过阿里云定制属于自己的加速源
    https://cr.console.aliyun.com/cn-shanghai/instances/mirrors

     1##创建目录
     2sudo mkdir -p /etc/docker
     3##创建文件
     4sudo tee /etc/docker/daemon.json <<-'EOF'
     5{
     6  "registry-mirrors": ["https://njai7mm6.mirror.aliyuncs.com"]
     7}
     8EOF
     9##载入配置项
    10sudo systemctl daemon-reload
    11##重启docker
    12sudo systemctl restart docker
    13##加入开机启动
    14systemctl enable docker
    

    docker-compose 安装 https://github.com/docker/compose/releases

    1curl -L https://github.com/docker/compose/releases/download/1.25.4/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
    2chmod +x /usr/local/bin/docker-compose
    

    如果报错:Cannot open self /usr/local/bin/docker-compose or archive /usr/local/bin/docker-compose.pkg,一般是由于下载文件不完整导致的,进入到 https://github.com/docker/compose/releases 下载对应版本的包 https://github.com/docker/compose/releases/download/1.25.4/docker-compose-Linux-x86_64 到/usr/local/bin/目录,然后重命名为 docker-compose 后赋权即可

    4.node 和 npm 安装

    通过 n 或者 nvm 安装,可以很好的控制版本,以 n 为例,先安装 n

    下载源码 https://github.com/tj/n/releases 解压到 /usr/local/n/目录,然后设置 n 的环境变量:

    1export PATH=$PATH:/usr/local/n/bin
    

    通过 n 命令安装 node:

    注意: nodejs 版本 >=8.9.4 <9.0 ,npm 版本 >=5.6.0 <6.0

    n 8.9.4

    更改 npm 源

    1npm config set registry https://registry.npm.taobao.org
    

    查看当前源

    1npm config get registry
    

    6.go 安装

    https://www.runoob.com/go/go-environment.html

    go 源改为国内源:

    https://github.com/goproxy/goproxy.cn/blob/master/README.zh-CN.md

    7.安装 gcc+ gcc-c++

    1yum install gcc+ gcc-c++
    

    三.Fabric 安装

    官方提供了一键安装脚本,执行改脚本会有三步 1.网络好的话可以选择全自动安装

    1.下载 fabric-sample

    下载文件

    1git clone https://github.com/hyperledger/fabric-samples
    

    检出指定版本

    git checkout v1.4.4

    或者直接下载对应版本资源代码

    https://github.com/hyperledger/fabric-samples/releases

    2.下载二进制文件

    在 fabric 资源文件页面 https://github.com/hyperledger/fabric/releases 下载对应的包,然后解压后,将 bin 和 cofing 文件夹移至 fabric-samples 中,并赋权

    1chmod +x bin/*
    

    设置环境变量

    1export PATH=$PATH:/app/fabric-samples/bin
    

    验证二进制文件及环境,出现版本信息则正确

    1peer version
    

    四.初始化环境

    进入 fabric-samples/fabcar/目录, 启动脚本配置网络下载容器

    1./startFabric.sh
    

    成功后进入 fabric-samples/fabcar/javascript 目录, 初始化 node 包资源

    1npm install
    

    一切资源初始化完后,就可以启动了

    五.启动网络

    1. fabcar 网络

    依次执行下面语句,第一句执行完正常应该显示“ Successfully enrolled admin user “admin” and imported it into the wallet ”

    1node enrollAdmin.js
    2node registerUser.js
    3node query.js
    

    最后语句执行完结果为一堆数组 json

    2.启动 first-network

    切换目录到 fabric-samples/first-network,关闭之前启动的网络

    1./byfn.sh down
    

    启动网络

    1./byfn.sh up
    

    一堆像之前安装的一样大大的“END”, 说明网络环境搭建成功

    参考资料:

    1. https://hyperledger-fabric.readthedocs.io/zh_CN/release-1.4/index.html
    2. https://blog.csdn.net/qq_27348837/article/details/92570917
  • 最近在做 Hyperledger fabric 国密改造,网上很多关于国密改造的,但是大多数都是对 fabric 进行改造,sdk 改造的很少。

    测试很多人改的,都没能测通,最后找到了 bolenzhang 改的 go sdk 国密zhangqcfabric 国密 才测通了,他们基于同济的国密算法 https://github.com/tjfoc/gmsm

    其中 sdk 中有一点小问题,有个包引用但是没有找到包文件,于是注掉了
    文件 internal/github.com/hyperledger/fabric/core/ledger 中一个引用包

    1"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/core/ledger/util/couchdb"
    

    改包没有找打,代码中也没有,索性就注掉了该包以及调用,大概 52 行左右的 StateDBConfig 结构体里

    1type StateDBConfig struct {
    2	// StateDatabase is the database to use for storing last known state.  The
    3	// two supported options are "goleveldb" and "CouchDB".
    4	StateDatabase string
    5	// CouchDB is the configuration for CouchDB.  It is used when StateDatabase
    6	// is set to "CouchDB".
    7	//CouchDB *couchdb.Config 
    8}
    

    还有另一个包兼容问题,我用的 beego,有个包 github.com/go-kit/kit ,fabric 中用的版本是 v0.8.0,而 beego 依赖包中使用的是 v0.9.0,而这两个版本中 github.com/go-kit/kit/metrics/statsd 的 SendLoop 方法 v0.8.0 版本是 3 个参数

    1(c <-chan time.Time, network, address string)
    

    而 v0.9.0 及以后版本是四个参数

    1(ctx context.Context, c <-chan time.Time, network, address string)
    

    怕更新包版本又影响别的地方,直接修改 sdk 源码,将包文件
    internal/github.com/hyperledger/fabric/core/operations/system.go 大概 227 行左右,原方法为:

    1go s.statsd.SendLoop(s.sendTicker.C, network, address)
    

    增加一个参数

    1go s.statsd.SendLoop(nil,s.sendTicker.C, network, address)
    

    大功告成,该 go sdk 是基于 v1.0.0-beta1 版本改的,目前官方已经发布了 v1.0.0-beta2,于是按着他这个改了一个基于 v1.0.0-beta2 的 fabric sdk go 国密版,fabric 也参考 gwanted 的基于 1.4.7 改了。

  • 1&,./test &
    

    一般在执行 shell 命令的时候我们在命令的后面加上一个‘&’,这样就可以使得该程序在后台运行,但是当程序运行起来之后依旧会再次在 shell 中输出打印信息,shell 依旧被占用,关闭 shell 则程序退出;这个时候我们可以使用 ctrl+z 命令,使得这个信息消失,可以做别的事情,但是关闭 shell 的时候程序依旧会退出

    1./test >> out.txt 2>&1 & 
    

    2>&1 是指将标准错误重定向到标准输出,于是标准错误和标准输出都重定向到指定的 out.txt 文件中,从此终端彻底清静了。

    1nohup ./test &
    2nohup ./test > myout.txt 2>&1 &
    3nohup -c ./test > myout.txt 2>&1 &
    

    nohup 打日志不实时,可以加-c 让日志实时写到文件

  • mysql5.7 字符集 utf8mb4 的默认排序规则为 utf8mb4_general_ci
    mysql8 字符集 utf8mb4 的默认排序规则为 utf8mb4_0900_ai_ci

    mysql5.7 升级为 mysql8 后更改字符集和排序规则方式有以下几种

    1. 只修改库字符集和排序规则
    1ALTER DATABASE database_name CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
    
    1. 只更改表字符集和排序规则
    1ALTER TABLE table_name CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
    
    1. 只更改字段字符集和排序规则
    1ALTER TABLE table_name CHANGE COLUMN column_name varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '字段备注';
    2
    
    1. 同时更改表和改表下所有字段字符集和排序规则
    1ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
    2