西维蜀黍

【Golang】Panic and Recover

  ...


【Golang】Exit Code

os.Exit()

Use os.Exit to immediately exit with a given status.

package main

import (
    "fmt"
    "os"
)

func main() {
    defer fmt.Println("!") // never called

    os.Exit(3)
}
  • Conventionally, code zero indicates success, non-zero an error
  • defers will not be run when using os.Exit, so this fmt.Println will never be called.
  • For portability, the status code should be in the range [0, 125].
  ...


【Golang】使用 - context

Background

Many people who have worked with Go, would have encountered it’s context library. Most use context with downstream operations, like making an HTTP call, or fetching data from a database, or while performing async operations with go-routines. It’s most common use is to pass down common data which can be used by all downstream operations. However, a lesser known, but highly useful feature of context is it’s ability to cancel, or halt an operation mid-way.

This post will explain how we can make use of the context libraries cancellation features, and go through some patterns and best practices of using cancellation to make your application faster and more robust.

  ...


【Python】SimpleHTTPServer

Python2

$ python -m SimpleHTTPServer
# or
$ python2 -m SimpleHTTPServer

Python3

$ python3 -m http.server
  ...


【IoT】大陆以外使用石头拖扫机器人T7S Plus

  ...


【IoT】获取米家设备 token

获取access token

[Better] XIAOMI CLOUD TOKENS EXTRACTOR

Manual run in python

$ git clone https://github.com/PiotrMachowski/Xiaomi-cloud-tokens-extractor.git

$ virtualenv Xiaomi-cloud-tokens-extractor -p python2.7

$ cd Xiaomi-cloud-tokens-extractor

$ source bin/activate

Install dependencies:

$ pip3 install pycryptodome pybase64 requests

Download and run script:

$ python3 token_extractor.py
  ...


【IoT】Home Assistant 集成 Aqara 空调伴侣

Model ID Model number Product name Shape
acpartner.v3 KTBL11LM Aqara Air Conditioning Companion square
lumi.acpartner.mcn02 KTBL03LM Xiaomi Air Conditioning Companion 2 square

Aqara Air Conditioning Companion

米家 App 中设置

  • 约克空调,ID 3203,第3个设置
  ...


【TrueNAS】ZFS 管理

列出当前所有所有的 Pool

$ zpool list
NAME        SIZE  ALLOC   FREE  CKPOINT  EXPANDSZ   FRAG    CAP  DEDUP    HEALTH  ALTROOT
SWPool     16.4T  2.35T  14.0T        -         -     0%    14%  1.00x    ONLINE  /mnt
SWPoolSSD  1.86T   142G  1.72T        -         -     0%     7%  1.00x    ONLINE  /mnt
boot-pool   103G  1.18G   102G        -         -     0%     1%  1.00x    ONLINE  -
  ...


【OpenWrt】树莓派上使用 AX88179 USB 网卡

安装 AX88179 Driver

AX88189驱动

opkg update && opkg install kmod-usb-net-asix-ax88179 
reboot

After next reboot, you should see your USB Ethernet interface initialized:

1...
2[    7.159985] usbcore: registered new interface driver r8152
3[    7.370114] r8152 2-2:1.0 eth1: v1.10.11
4[   10.665622] IPv6: ADDRCONF(NETDEV_CHANGE): eth1: link becomes ready
5[   10.673312] r8152 2-2:1.0 eth1: carrier on
6...
  ...


【OpenWrt】树莓派安装OpenWrt

  ...