从 shell 发送飞书(Lark)机器人消息

#!/bin/sh
WEBHOOK=YOUR_WEBHOOK_HERE
if [ "$*" == "--help" ] ; then
echo "Usage: lark_msg <msg>..."
exit 0
fi
msg="$*"
echo "sending:" "$*" | systemd-cat -t lark_msg -p info
json=$(jq -n --arg msg "$msg" '{"msg_type":"text","content":{"text": $msg}}')
ret=$(curl -s -X POST -H "Content-Type: application/json" -d "$json" "$WEBHOOK" )
if [ "$( echo "$ret" | jq .StatusCode )" != "0" ] ; then
echo "failed:" "$ret" | systemd-cat -t lark_msg -p warning
fi
view raw lark_msg hosted with ❤ by GitHub

自动备份服务器数据到 NextCloud

2024-02-28 更新:使用 zstd 压缩(.tar.gz -> .tar.zsttar czvf -> tar cavf

突发奇想:在 NextCloud 创建一个 File drop 分享,然后写一个打包上传脚本,就可以把它当备份服务器用啦。

功能/特点:

  • 分别备份多个源目录到 tar 文件并上传到 NextCloud share;
  • 每周上传完整备份,每天上传增量备份(利用 tar 增量备份);
  • 只需要 NextCloud 的 File drop 链接,由于 File drop 只能用于上传,禁止列出/下载文件,脚本泄露不会造成其它数据的泄露。
Full post >

使用 Btrfs 作为虚拟磁盘文件的底层存储

(2022-05-12 更新)

将虚拟磁盘文件存储在 Btrfs 文件系统中具有几个优点:

  • Btrfs 的数据透明压缩功能可以节省硬盘空间;
  • Btrfs 的 reflink(共享数据块) 和 subvolume snapshot(子卷快照)可用于给虚拟磁盘创建快照;
  • Btrfs 的 Copy-on-Write (CoW) transaction 机制和可保证虚拟磁盘文件的一致性,在大量随机写入时可以免除频繁的硬盘 flush 操作。
Full post >

网站更新了!

(2022 年又双叒叕更新了:修改首页布局、添加 About 页面、添加代码高亮……)

更新了网站样式(疯狂滥用卡片)。

首页支持分页(其实并不是分“页”,参数是 post id 而不是页数)。

后端代码太菜了。前端部分没有混淆,按 F12 就能看到。

因为此网站基于 ASP.NET Core 默认模板,所以diuren地使用了 jQuery 和 Bootstrap,以后也许会把这两个依赖去掉……

Yuuza.net 前端

如何在 JavaScript (web) app 中添加多语言支持

通过 @yuuza/webfx 中的 I18n class,可以简单地实现多语言支持(逃

2021 年 10 月更新:现有独立的包 @yuuza/i18n

JavaScript / TypeScript:

import { i18n, I } from "@yuuza/webfx";

i18n.add2dArray([
    ['en', 'zh'],
    ['Hello!', '你好!'],
    ['My name is {0}.', '我的名字是 {0}。']
]);

const name = 'Yuuza';
['en', 'zh'].forEach((lang) => {
    i18n.curLang = lang;
    console.log(I`Hello!`);
    console.log(I`My name is ${name}.`);
});

// Hello!
// My name is Yuuza.
// 你好!
// 我的名字是 Yuuza。