个人
2023-06-11
假发
近日有新闻讨论香港法官至今保留原宗主国戴假发的传统(陋习)。
先说一下我对这个司法假发的一点了解。
16 世纪,欧洲贵族社会性病流行,其中症状之一就是脱发严重。于是,随着时间的流逝,上层社会戴假发的习俗慢慢演化成了地位的象征。
医疗技术发展起来之后,带假发的这种习俗就迅速消亡了,谁会喜欢没事带着这么个劳什子呢,想想都不舒服嘛。
不过,因为英国有立法,规定法律从业人士的着装要求,其中就包括必须戴假发(WTF)。
一种长发及肩,用在刑法庭,一种短些,用在民法庭。

PS:可以搜索一下带假发的法官图片,简直丑的一批,我想应该是没有人会喜欢这玩意儿吧。
PS:美国第三任总统托马斯·杰斐逊:“(英国法官)像躲在棉絮下面向外窥视的老鼠”。
因为英国到处侵略与殖民,将本国的法律推及到很多地方,包括中国香港。
所以,部分地区的司法界保留了这个传统直到近代。
根据维基百科的信息,英国、加拿大、澳大利亚、新西兰已经部分废除了假发在法庭中的使用。但香港司法界至今坚持必须戴假发上庭。
我对司法制度不了解,但是这个假发就是一个配饰,完全无关司法精神吧,为什么必须用法律法规来强制佩戴呢?
这个和清朝遗民舍不得辫子是何其相识!
辫子

说到辫子,不禁想起了《建党大业》中,辜鸿铭的经典台词:“我的辫子长在脑后,笑我的人,辫子长在心头。老夫头上的辫子是有形的,而诸公心中的辫子却是无形的。”
这句话说的其实也挺在理的,因为比人家弱,就什么都要跟人家学习,觉得自己家什么都是糟粕,这何尝不是辫子长在心头呢!
辫子就是不自信,就是觉得自己低人一头,就是外国的月亮比较圆。
假发是外在的辫子,皇民心态是内在的辫子。而我们希望他们能彻底抹除原宗主国的痕迹,有没有一点辫子的意味呢?
我的意思是,从发展的眼光看问题,他们这顶可笑的假发早晚是会消失的,但我们是否过于着急了,这种心态是不是对于过去的屈辱历史过于耿耿于怀了,算不算文化上的不自信呢?
参考资料与拓展阅读
Email
2023-06-10
看到科技爱好者周刊推荐的一篇文章,介绍了自托管邮件服务的一些现状,主要是 Gmail 这样的主流邮箱服务提供商(MSP)拒收来自自托管邮件服务的邮件(或标记成垃圾邮件),导致自托管邮件服务的运营遇到很大的困难。
电子邮件在因特网没有出现之前就已经诞生,简单、开放,易于开发和使用,人人都能成为 Email 网络中的一个节点。实际上,大部分人都是使用的一些大 MSP 的服务,但也有部分人(或者组织)使用的是自己部署的邮件服务。他们会发现哪怕所有应该做的都做了,比如 SPF,DKIM,DMARC,他们的邮件还是经常无法正常投递出去(被拒、限流等),或者在收件人的垃圾文件夹中。
在一定程度上,MSP 的做法也是可以理解的,垃圾邮件泛滥成灾,确实防不胜防。因为邮件服务本身是毫无门槛。除非上一个手机实名制这样的严格管控,或许能解决这个问题。
文章提出的主要价值点是,什么情况下我们有必要自建邮箱服务?
- 准备好投入很多时间和精力来维护这套系统
- 搭建系统
- 留意 SPF 和 DMARC 报告
- 有服务器管理能力(Linux,Docker)
- ISP 支持开放 25、143、465、587、993 端口
- 静态 IP + rDNS 配置权限
- 一个合适的域名
Golang
2023-05-30
gotip 是官方推出的,从最新的开发分支下拉代码,编译生成 go 运行时的工具。
如果希望体验最新特性,可以在编译成功之后,可以直接用 gotip 取代 go 命令用来执行 go 程序。
gotip 就可以理解为开发版的 go。
go install golang.org/dl/gotip@latest
gotip
gotip: not downloaded. Run 'gotip download' to install to C:\Users\nosch\sdk\gotip
gotip download
Cloning into 'C:\Users\nosch\sdk\gotip'...
...
Building Go cmd/dist using C:\Program Files\Go. (go1.20.5 windows/amd64)
Building Go toolchain1 using C:\Program Files\Go.
Building Go bootstrap cmd/go (go_bootstrap) using Go toolchain1.
Building Go toolchain2 using go_bootstrap and Go toolchain1.
Building Go toolchain3 using go_bootstrap and Go toolchain2.
Building packages and commands for windows/amd64.
成功的时候:
---
Installed Go for windows/amd64 in C:\Users\nosch\sdk\gotip
Installed commands in C:\Users\nosch\sdk\gotip
Success. You may now run 'gotip'!
失败的时候:
# runtime/cgo
gcc_libinit_windows.c: In function '_cgo_beginthread':
gcc_libinit_windows.c:143:27: error: implicit declaration of function '_beginthread'; did you mean '_cgo_beginthread'? [-Werror=implicit-function-declaration]
143 | thandle = _beginthread(func, 0, arg);
| ^~~~~~~~~~~~
| _cgo_beginthread
cc1: all warnings being treated as errors
go tool dist: FAILED: C:\Users\nosch\sdk\gotip\pkg\tool\windows_amd64\go_bootstrap install std: exit status 1
Success. You may now run 'gotip'!
Golang
2023-05-29
Go 并没有支持集合类型,我们需要自己实现:
https://go.dev/play/p/uVDCiN4Cbpt
package main
import "fmt"
type Set map[string]bool
func (s Set) Add(item string) {
s[item] = true
}
func (s Set) Remove(item string) {
delete(s, item)
}
func (s Set) Contains(item string) bool {
_, exists := s[item]
return exists
}
func main() {
mySet := make(Set)
mySet.Add("apple")
mySet.Add("banana")
mySet.Add("orange")
for item := range mySet {
fmt.Println(item)
}
fmt.Println(mySet.Contains("apple")) // 输出: true
fmt.Println(mySet.Contains("grape")) // 输出: false
mySet.Remove("banana")
fmt.Println(mySet.Contains("banana")) // 输出: false
}
注意:
- 使用 map 做底层存储,因此实现的 set 也是无序的
- map 不是线程安全的,如果有并发操作,需要加锁
- 如果真的要使用集合类型,应该再扩充一下交集,差集等方法
改进
参考 https://github.com/deckarep/golang-set 的设计:
https://go.dev/play/p/BKWT84lXfuz
package main
import "fmt"
type Set[T comparable] map[T]struct{}
func (s Set[T]) Add(item T) {
s[item] = struct{}{}
}
func (s Set[T]) Remove(item T) {
delete(s, item)
}
func (s Set[T]) Contains(item T) bool {
_, exists := s[item]
return exists
}
func main() {
mySet := make(Set[string])
mySet.Add("apple")
mySet.Add("banana")
mySet.Add("orange")
for item := range mySet {
fmt.Println(item)
}
fmt.Println(mySet.Contains("apple")) // 输出: true
fmt.Println(mySet.Contains("grape")) // 输出: false
mySet.Remove("banana")
fmt.Println(mySet.Contains("banana")) // 输出: false
}
优化点:
- 空结构体不占空间
- 泛型让代码复用性更好
文学 阅读
2023-05-27

计算机网络
2023-05-20
There’s more than one way to write an IP address 介绍了 IP 地址的另外几种不常用表示方法。
SSH
2023-05-19
Closing a stale SSH connection(关闭过时的 SSH 连接)中介绍了利用 SSH 转义序列来关闭失去响应的 SSH 连接。
也就是说在 SSH 终端输入 ~. 会直接中断 SSH 连接。
经过试验,确实有效(使用 SSH 代理建立的连接就没效)。
所有 SSH 转义序列:
[root@dell ~]# ~?
Supported escape sequences:
~. - terminate connection (and any multiplexed sessions)
~B - send a BREAK to the remote system
~C - open a command line
~R - request rekey
~V/v - decrease/increase verbosity (LogLevel)
~^Z - suspend ssh
~# - list forwarded connections
~& - background ssh (when waiting for connections to terminate)
~? - this message
~~ - send the escape character by typing it twice
(Note that escapes are only recognized immediately after newline.)
低代码 Frappe
2023-05-08

Frappe Framework 是一个基于 Python 的开源 Web 应用框架,定位于低代码业务平台,强调通过元数据驱动快速构建企业级系统。其核心抽象是 DocType(数据模型),开发者通过定义数据结构即可自动生成数据库表、表单界面、列表视图及基础 API,大幅降低 CRUD 类系统开发成本。框架内置权限控制、工作流引擎、报表系统和 REST 接口,支持多租户架构,适合 SaaS 化部署。
在 UI 层,Frappe 采用“后端驱动 + 自动生成”的模式,基于 DocType 自动生成标准后台界面(Form、List、Report 等),多数中后台场景无需手写前端代码。同时也提供分层扩展能力:通过 Client Script 实现表单交互与校验,通过 Custom Page 构建自定义页面,或在需要时完全接管前端,采用 Vue/React 等框架调用其 REST API,实现 Headless 架构。
后端方面,开发者可基于 Python 扩展业务逻辑(如 hooks、controller、scheduler),并通过模块化 App 机制进行功能解耦与复用。Frappe 提供完整的开发与运维工具链(如 Bench),支持插件化扩展,生态中典型应用包括 ERPNext 等。总体来看,Frappe 更接近一个“可编程业务平台”,适用于中后台系统、流程驱动型应用以及需要快速迭代的企业级场景。
授权协议:Frappe 框架是 MIT 协议,官方提供的应用都是 GPLv3 或者 AGPLv3 协议。
架构

依赖
- 后端
- Python 3.10+
- MariaDB / Postgres
- Redis 6
- Nginx
- cron
- 前端
- Node.js 16
- BootStrap
- jQuery
安装
sudo apt install -y git python-dev python-pip redis-server
sudo apt install -y mariadb-server mariadb-client
pip3 install frappe-bench
bench --version
➜ type bench
bench is /home/catroll/.python/bin/bench
➜ cat /home/catroll/.python/bin/bench
#!/home/catroll/.python/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from bench.cli import cli
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(cli())
➜ bench --help
WARN: Command not being executed in bench directory
Usage: [OPTIONS] COMMAND [ARGS]...
Options:
--version
--use-feature TEXT
-v, --verbose
--help Show this message and exit.
Commands:
app-cache View or remove items belonging to bench...
backup-all-sites Backup all sites in current bench
config Change bench configuration
disable-production Disables production environment for the bench.
download-translations Download latest translations
drop
exclude-app Exclude app from updating
find Finds benches recursively from location
get Clone an app from the internet or filesystem...
get-app Clone an app from the internet or filesystem...
include-app Include app for updating
init Initialize a new bench instance in the...
install Install system dependencies for setting up...
migrate-env Migrate Virtual Environment to desired Python...
new-app Create a new Frappe application under apps folder
pip For pip help use `bench pip help [COMMAND]` or...
remote-reset-url Reset app remote url to frappe official
remote-set-url Set app remote url
remote-urls Show apps remote url
remove Completely remove app from bench and re-build...
remove-app Completely remove app from bench and re-build...
renew-lets-encrypt Sets Up latest cron and Renew Let's Encrypt...
restart Restart supervisor processes or systemd units
retry-upgrade Retry a failed upgrade
rm Completely remove app from bench and re-build...
set-mariadb-host Set MariaDB host for bench
set-nginx-port Set NGINX port for site
set-redis-cache-host Set Redis cache host for bench
set-redis-queue-host Set Redis queue host for bench
set-redis-socketio-host Set Redis socketio host for bench
set-ssl-certificate Set SSL certificate path for site
set-ssl-key Set SSL certificate private key path for site
set-url-root Set URL root for site
setup Setup command group for enabling setting up a...
src Prints bench source folder path, which can be...
start Start Frappe development processes
switch-to-branch Switch all apps to specified branch, or...
switch-to-develop Switch frappe and erpnext to develop branch
update Performs an update operation on current bench.
validate-dependencies Validates that all requirements specified in...
bench init
➜ sudo mkdir -p /opt/frappe
➜ sudo chown catroll:catroll /opt/frappe
➜ cd /opt/frappe
bench init helloworld --skip-redis-config-generation --version version-15 --frappe-path https://gitee.com/mirrors/frappe
# 通过 Git 克隆一个 Frappe 项目到本地,
# git clone https://gitee.com/mirrors/frappe --branch version-16 --depth 1 --origin upstream
# 创建 Python 虚拟环境并安装 Python 依赖,
# uv pip install --quiet --upgrade -e helloworld/apps/frappe --python helloworld/env/bin/python
# 然后使用 yarn 安装 Node 依赖,
# yarn install --check-files
# 还有就是编译多语言文件(MO 文件)。
# --skip-redis-config-generation
# 默认 Redis Server 在本地安装,会执行本地命令获取 Redis 版本号等操作。
# 跳过 Redis 配置,后面在 common-site-config 中手动配置。
# --version version-15
# 默认使用主干开发分支,我这里制定一个稳定版本。
# 而且 16/17 要求 Python 3.14 以上,而我本地安装的是 Python 3.12,懒得折腾。
# --frappe-path https://gitee.com/mirrors/frappe
# 使用国内镜像,稍微提提速。
cd helloworld
bench start
➜ tree -L 2
.
├── Procfile
├── apps
│ └── frappe
├── config
│ └── pids
├── env
│ ├── CACHEDIR.TAG
│ ├── bin
│ ├── lib
│ ├── lib64 -> lib
│ ├── pyvenv.cfg
│ └── share
├── logs
│ └── bench.log
├── patches.txt
└── sites
├── apps.json
├── apps.txt
├── assets
└── common_site_config.json
13 directories, 8 files
默认生成的 helloworld/sites/common_site_config.json 文件:
{
"background_workers": 1,
"file_watcher_port": 6787,
"frappe_user": "catroll",
"gunicorn_workers": 41,
"live_reload": true,
"rebase_on_pull": false,
"redis_cache": "redis://127.0.0.1:13000",
"redis_queue": "redis://127.0.0.1:11000",
"redis_socketio": "redis://127.0.0.1:13000",
"restart_supervisor_on_update": false,
"restart_systemd_on_update": false,
"serve_default_site": true,
"shallow_clone": true,
"socketio_port": 9000,
"use_redis_auth": false,
"webserver_port": 8000
}
Frappe Products
Business Apps
-
ERPNext
Manage accounting, inventory, and operations
-
Frappe HR
Handle employees, attendance, payroll, and HR processes
-
Learning(在线课程 LMS)
Create, manage, and deliver structured online courses
-
Insights(BI)
Analyze data and create interactive dashboards and reports
-
CRM
Track leads, contacts, deals, and customer interactions
-
Helpdesk
Deliver customer support through tickets and workflows
-
Lending(金融借贷)
Manage loans, repayments, and borrower accounts
Developer Tools
Productivity Tools
-
Gameplan(项目管理)
Plan work, share updates, and track progress across teams
-
Drive(类似 Google Drive 的文件系统)
Store, share, and collaborate on documents
Infrastructure
Libraries
-
Bench(开发与运维工具)
Command-line tool for managing multi-tenant Frappe deployments
-
Datatable(表格库)
JavaScript library for building interactive data tables
-
Charts(图表库)
JavaScript library for creating interactive charts and visualizations
-
Gantt(甘特图库)
Gantt chart library for creating interactive project timelines
AI
2023-05-05
体验
获得 ChatGPT 4 的资格(购买 Pro)之后,就可以看到左边页面多了一个 Model 选项,选中了 GPT 4
如果 Model 选择 Plugin 那一项,右边又会多出来一个 Plugins 选项


右边的 Plugins 选项一直往下拖,最下面一栏是 Plugin store,点击进入。

上面的插件可以选中体验体验。
安装
可以看到下方有 Install an unverified plugin,Develop your own plugin 两项。
我们开发的插件就是服务器端 API + 相关声明文件,如果就只是放在自己的服务器上,那就算 unverified plugin。
第一选项就是用来安装这样未经验证的插件,可以在 https://www.gptplugins.app/ 找一个试一下。
输入域名,ChatGPT 自动去获取声明文件 https://域名/.well-known/ai-plugin.json。

第二项是用来注册插件到 ChatGPT,也可以用来调试本地插件。
如果是注册插件就填域名好了,如果是调试就输入 localhost:3000 这样的地址。
我用局域网 IP,似乎是不行的,可能只支持 localhost 这个主机名。

使用
现阶段最多能够同时勾选三个插件。
聊天过程中,ChatGPT 自动判断是否需要触发插件的使用。

开发
经过我的体验,开发非常简单,除了原本的服务之外,需要的额外工作就两项:清单文件,OpenAPI(如果原本没有的话)。
清单文件:
{
"schema_version": "v1",
"name_for_model": "todo",
"name_for_human": "Todo Plugin",
"description_for_model": "Simple task management, task description, task date, task completion. Supports adding, deleting, and querying.",
"description_for_human": "Simple task management.",
"auth": {
// 本地测试 Auth Type 必须是 none
"type": "none"
},
"api": {
"url": "http://localhost:8080/.well-known/openapi.yaml",
"has_user_authentication": true,
"type": "openapi"
},
"logo_url": "http://localhost:8080/.well-known/logo.png",
"contact_email": "hello@contact.com",
"legal_info_url": "hello@legal.com"
}
Redis
2023-04-30
我一两年前设计的一个通过 Redis ZSet 做事件广播的方案,刚用 Python 写了一个示例代码贴出来。
- 这是一个 Push / Pull 方式的广播机制。
- 推送方将消息推送到一个 zset key 中,score 为毫秒时间戳。
- key 名为 xxx:timestamp//10,也就是精确到 10 秒的时间戳。
也就是说每 10 秒一个 key,通过 TTL(5 分钟)实现历史数据自动清除,也避免 event 太多导致大 key 的问题。
- 拉取方用上一次拉取时间和当前时间做 score range,从最近的三个 zset 中读到这个时间段内的事件。
import logging
import threading
import time
import redis
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(name)s %(message)s')
redis_host = '127.0.0.1'
redis_port = 6379
redis_db = 1
redis_password = None
redis_prefix = 'broadcast:'
redis_conn = redis.StrictRedis(host=redis_host, port=redis_port, db=redis_db, password=redis_password)
def handle_broadcast(data):
# 这里是处理收到的广播请求数据的函数
# 你需要根据具体需求来实现这个函数
logging.info(f'处理广播请求数据:{data} ===== ===== ===== =====')
def event_broadcast(data):
now = time.time()
now_ms = int(now * 1000)
now_10s = int(now) // 10
key = redis_prefix + str(now_10s)
score = now_ms
pipeline = redis_conn.pipeline()
pipeline.zadd(key, {data: score})
pipeline.expire(key, 300)
pipeline.execute()
# function event_broadcast(data) {
# const now = Date.now();
# const now_ms = now;
# const now_10s = Math.floor(now / 10000);
#
# const key = redis_prefix + now_10s;
# const score = now_ms;
#
# const pipeline = redis_conn.pipeline();
# pipeline.zadd(key, score, data);
# pipeline.expire(key, 300);
# pipeline.exec();
# }
last_score = 0
def event_fetch():
global last_score
now = time.time()
now_ms = int(now * 1000)
now_10s = int(now) // 10
keys = [
redis_prefix + str(now_10s - 2),
redis_prefix + str(now_10s - 1),
redis_prefix + str(now_10s),
]
pipeline = redis_conn.pipeline()
for key in keys:
logging.info('%s %20s %20s', key, last_score, now_ms)
pipeline.zrangebyscore(key, last_score, now_ms, withscores=True)
results = pipeline.execute()
for data_list in results:
for data, _ in data_list:
handle_broadcast(data.decode('utf-8'))
last_score = now_ms
def broadcast_loop():
i = 0
while True:
i += 1
data = f'广播请求数据 {i}'
event_broadcast(data)
logging.info(f'广播请求:{data}')
time.sleep(0.5)
def main():
broadcast_thread = threading.Thread(target=broadcast_loop, daemon=True)
broadcast_thread.start()
while True:
event_fetch()
time.sleep(5)
main()