lxgw

在 PaperMod 博客中设置自定义字体

下载字体 下载你需要的字体,并存储在 static/fonts 导入字体 @font-face { font-family: "LXGWWenKai-Regular"; src: url("/fonts/lxgw-wenkai/LXGWWenKai-Regular.ttf") format("truetype"); } 应用字体 body { font-family: LXGWWenKai-Regular; } 在 PaperMod 中应用 把你自己的 css 文件文件放在 assets/css/extended/custom_fonts.css 导入多字重的字体文件 @font-face { font-family: "LXGWWenKai"; src: url("/fonts/lxgw-wenkai/LXGWWenKai-Light.ttf") format("truetype"); font-weight: lighter; font-style: normal; } @font-face { font-family: "LXGWWenKai"; src: url("/fonts/lxgw-wenkai/LXGWWenKai-Regular.ttf") format("truetype"); font-weight: normal; font-style: normal; } @font-face { font-family: "LXGWWenKai"; src: url("/fonts/lxgw-wenkai/LXGWWenKai-Bold.ttf") format("truetype"); font-weight: bold; font-style: normal; } 使用 CDN @import url('https://cdn.jsdelivr.net/npm/[email protected]/css/jetbrains-mono.min.css'); code { font-family: 'JetBrains Mono'; } 参考链接 Sulv’s Blog - Hugo博客自定义字体 PaperMod - FAQs StackOverflow - Using custom fonts using CSS? StackOverflow - Multiple font-weights, one @font-face query GitHub - lxgw/LxgwWenKai

2023年3月2日 · Aimer Neige
go banner

如何给 Go 的结构体添加多个 tag

本来很简单的东西,但是老忘,干脆写个博客吧 错误写法 type Page struct { PageId string `bson:"pageId",json:"pageId"` Meta map[string]interface{} `bson:"meta",json:"pageId"` } 正确写法 type Page struct { PageId string `bson:"pageId" json:"pageId"` Meta map[string]interface{} `bson:"meta" json:"pageId"` } 很多 Tag Items []Item `gorm:"column:items,type:varchar(255);comment:'sample column'" json:"items"` 参考链接 StackOverflow - How to define multiple name tags in a struct

2023年2月26日 · Aimer Neige
Golang Context

Golang Context

前言 有时我们要通过第三方服务获取数据,它可以是外部提供的 API,也可以是微服务的接口等等,总之,它们有相同的问题:“获取数据可能需要大量时间”。如果在代码中同步地获取这些数据,程序就会花时间等待这些服务响应,而这些等待会严重影响程序的运行效率,而且一旦这些服务崩溃,我们的程序就会陷入无休止的等待中,那么如何解决这个问题呢?可以使用 Go 的 context 包。 问题 我们用这个函数来替代那些第三方服务。我们直接使用 time.Sleep() 函数来模拟一个耗时过程,在现实场景中,它可能是在执行一个非常复杂的 SQL 查询,也可以是调用一个人工智能服务接口。当然,这个耗时是不确定的,甚至有可能是无穷大(卡死)。 func fetchThirdPartyStuffWhichCanBeSlow() (int, error) { time.Sleep(time.Millisecond * 500) return 64, nil } 如果我们不做任何处理,直接调用这个函数,就像这样: func foo() { // some code here ... val, err := fetchThirdPartyStuffWhichCanBeSlow() if err != nil { log.Fatal(err) } // some code here ... } 上面的代码如果用在一些只执行一次的脚本、工具中,并不会带来严重后果,无非多等一下就好了,即使有问题也可以关掉程序检查一下第三方服务。但是如果上面的代码用在一个承载大流量的 web 服务中,程序在执行完耗时代码后还要继续执行一些重要的业务功能,那么这样直接调用而不加考虑的代码很可能是致命的。一旦第三方服务出现问题,程序没有任何机制检查和处理,而是直接陷入无休止的等待。这显然是不合理的。 解决方案 要解决上述的问题,比较常见的思路是引入一个主动停止耗时服务的功能,这样如果耗时函数花了太多时间执行,程序就可以感知到,并主动干预。 在后文中,我们假设我们要使用用户的 ID 访问用户的数据,且调用三方服务的代码被单独封装为 fetchUserData()。 使用 Channel 如果不使用本文要介绍的 Context,传统的思路是使用 Channel + Select 来处理: type Response struct { value int err error } func fetchUserData(userID int) (int, error) { stop := make(chan bool) respch := make(chan Response) go func() { val, err := fetchThirdPartyStuffWhichCanBeSlow() respch <- Response{ value: val, err: err, } }() go func() { time.Sleep(time.Millisecond * 200) stop <- true }() for { select { case <-stop: return 0, fmt.Errorf("fetching data from third party took to long") case resp := <-respch: return resp.value, resp.err } } } 这里我们使用 stop 这个 Channel 来发送停止信号,在程序执行超过指定时间时关掉终止等待并报错,而 respch 用来接受返回值。在程序的最后,使用 select 来接受 Channel 的信号,当检测到超时或执行完成时返回结果。 ...

2023年2月3日 · Aimer Neige
Minecraft Java Edtion

如何搭建 Minecraft Mod 服务器

使用 PaperMC 安装 PaperMC 下载 PaperMC 提供的 jar 包,存储在恰当位置即可。 启动 PaperMC java -Xms2G -Xmx2G -jar paper.jar --nogui 下面是官方提供的优化后的启动脚本: java -Xms10G -Xmx10G -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 -Dusing.aikars.flags=https://mcflags.emc.gs -Daikars.new.flags=true -jar paper.jar --nogui 安装 datapack 关掉已启动的服务器,将 datapack 存储在 papermc/world/datapacks 文件夹下,重启服务器即可。(如果不存在就新建一个) 安装插件 关掉已启动的服务器,将下载好的插件存储在 papermc/plugins 文件夹下,重启服务器即可。(如果不存在就新建一个) 配置服务器 PaperMC 提供了非常多的服务器修改配置,具体请查阅 官方文档。 对于 mod 的说明 PaperMC 并不兼容 Fabric 的 mod。如果需要使用 Fabric 的 mod,请参考下面的内容使用 Fabric 服务器。 ...

2023年1月26日 · Aimer Neige
Desktop File

如何编写 .desktop 文件

前言 在 Linux 系统中,经常会遇到一些软件只提供了可执行文件,而并没有提供可以通过包管理安装的途径,常见于 AppImage 封装的软件,这时候每次需要运行软件都需要通过终端来执行,非常麻烦。不过这个问题可以通过手动编写 .desktop 文件来解决,这样这些可执行文件就可以和其他软件一样拥有桌面图标。 用法 使用 vim 或其他文本编辑器直接编写 .desktop 文件后将其置于如下路径之一即可: /usr/share/applications/ /usr/local/share/applications/ ~/.local/share/applications/ 示例 来自 Arch Linux Wiki 的示例 [Desktop Entry] # The type as listed above Type=Application # The version of the desktop entry specification to which this file complies Version=1.0 # The name of the application Name=jMemorize # A comment which can/will be used as a tooltip Comment=Flash card based learning tool # The path to the folder in which the executable is run Path=/opt/jmemorise # The executable of the application, possibly with arguments. Exec=jmemorize # The name of the icon that will be used to display this entry Icon=jmemorize # Describes whether this application needs to be run in a terminal or not Terminal=false # Describes the categories in which this entry should be shown Categories=Education;Languages;Java; 其中,Type 和 Name 是必须的,其他都是可选项。 ...

2023年1月25日 · Aimer Neige
Minecraft Java Edtion

如何搭建你自己的 Minecraft 服务器

阅前须知 本文章面向具有一定运维经验的用户,不面向小白 本文章介绍的 Minecraft 是 Java 版本的 Minecraft 本文章只介绍纯净服的搭建,不会说明如何安装 mod 如非特殊说明,本文中出现的 “我的世界” 均指代 Minecraft 的中文翻译,而不是由网易代理的 “我的世界” 准备 可供外部连接的服务器 基础 Linux 知识 安装 首先要确定你的服务器是否可以被外部连接 有公网 IP 如果你有公网 IP,可以直接使用你的主机作为服务器,相当于你有一台私有的云服务器。 没有公网 IP 如果你没有公网 IP,你需要购买一台云服务器,这样,你就拥有了一个可供外部连接的公网 IP。 如果你对服务器配置要求较高,本地也有闲置主机可以用来跑 Minecraft 服务器,可以通过 frp 将本地的主机穿透出去,以供外部连接。这样云服务器的配置就可以很低,只负责转发网络数据。 如果你对服务器的配置要求不高,也不想本地 24 小时开着一台机器,可以直接使用云服务器来跑 Minecraft 服务器。 至于你需要多高的配置来运行 Minecraft 服务器,可以参考 Wiki 的内容: 确保服务器可以被外部连接后,安装 Minecraft 下载服务器文件 在 官网 下载服务器运行所需的 jar 文件。 官方只提供最新版的文件,如果你需要历史版本,使用官方启动器下载。 运行服务器 直接使用官网的示例指令运行 jar 文件: java -Xmx1024M -Xms1024M -jar minecraft_server.1.19.3.jar nogui 如果你有更高的内存,可以修改 -Xmx1024M -Xms1024M 这一部分。 第一次执行后,需要同意用户协议才可以继续执行,修改 eula.txt 这个文件,将 eula=false 改为 eula=true。 ...

2023年1月12日 · Aimer Neige
Ubuntu qBittorrent-nox

在 Ubuntu 服务器上安装 qBittorrent-nox

在 Ubuntu 服务器上安装 qBittorrent-nox 更新系统 sudo apt update && sudo apt upgrade -y 导入 qBittorrent-nox 稳定版本的源 sudo add-apt-repository ppa:qbittorrent-team/qbittorrent-stable -y 导入 qBittorrent-nox 非稳定版本的源(每夜版) sudo add-apt-repository ppa:qbittorrent-team/qbittorrent-unstable -y 更新源 sudo apt update 安装 qBittorrent-nox sudo apt install qbittorrent-nox -y 创建用户和用户组 sudo adduser --system --group qbittorrent-nox # on fedora sudo groupadd qbittorrent-nox 将你添加到用户组中 sudo adduser your-username qbittorrent-nox # on fedora sudo usermod -aG qbittorrent-nox your-username 创建 service 文件 sudo vim /etc/systemd/system/qbittorrent-nox.service [Unit] Description=qBittorrent Command Line Client After=network.target [Service] Type=forking User=qbittorrent-nox Group=qbittorrent-nox UMask=022 ExecStart=/usr/bin/qbittorrent-nox -d --webui-port=8080 Restart=on-failure [Install] WantedBy=multi-user.target 重载 systemctl sudo systemctl daemon-reload 启动 qBittorrent-nox sudo systemctl start qbittorrent-nox 开启开机自启动 qBittorrent-nox sudo systemctl enable qbittorrent-nox 检查 qBittorrent-nox 是否启动 systemctl status qbittorrent-nox 登录到 qBittorrent-nox Item Value username admin password adminadmin 如何删除 qBittorrent-nox # Remove qBittorrent Stable sudo add-apt-repository --remove ppa:qbittorrent-team/qbittorrent-stable # Remove qBittorrent Unstable (Nightly) sudo add-apt-repository --remove ppa:qbittorrent-team/qbittorrent-unstable -y # Remove qBittorrent sudo apt autoremove qbittorrent-nox

2022年11月11日 · Aimer Neige
Fedora WeChat

在 Fedora 系统上安装微信

在 Fedora 系统上运行微信 安装 wine sudo dnf install wine 调整缩放比例 输入下面的指令打开 winecfg winecfg 在 Graphics 一栏中调整合适的 dpi 以保证有舒适的使用体验。(4k 屏幕,192 dpi) 下载并配置字体 依次执行如下指令即可 sudo dnf install cabextract sudo dnf install winetricks winetricks corefonts gdiplus riched20 riched30 下载并安装微信 直接下载官方的 exe 安装包(在网页下载也是一样的) wget https://dldir1.qq.com/weixin/Windows/WeChatSetup.exe 使用 wine 启动微信 wine ./WeChatSetup.exe 接下来按照 Windows 的安装逻辑点击下一步安装好微信 安装结束后可以删除安装包 修改语言设置 修改这个文件 vim ~/.local/share/applications/wine/Programs/WeChat/WeChat.desktop 调整 Exec 这一部分,添加如下环境变量 env LC_ALL="zh_CN.UTF8" 最终结果应该是这样(注意路径) [Desktop Entry] Name=WeChat Exec=env LC_ALL="zh_CN.UTF8" env WINEPREFIX="/home/aimer/.wine" wine C:\\\\ProgramData\\\\Microsoft\\\\Windows\\\\Start\\ Menu\\\\Programs\\\\WeChat\\\\WeChat.lnk Type=Application StartupNotify=true Path=/home/aimer/.wine/dosdevices/c:/Program Files (x86)/Tencent/WeChat Icon=E03C_WeChat.0 StartupWMClass=wechat.exe 启动微信 安装过程中会自动添加 desktop 文件,直接打开即可。 ...

2022年11月10日 · Aimer Neige
Golang embed

Golang embed

前言 在写项目的时候,有时候不可避免地要处理静态文件,如果将源码直接作为软件提供问题不大,使用相对路径读取这些静态文件就可以了。但是如果项目作为库向外公布显然不可行,使用相对路径是读取不到文件的,而使用绝对路径却会带来更大的问题:因为不同的人使用,路径绝对不可能完全一致的。如果要求用户在指定路径下放置这些依赖的静态文件,虽然可行但是会给用户带来很大的困扰,而且这样的实现方式显然不够优雅。这时候,将这些静态文件一起打包进可执行文件似乎是一个完美的解决方案,那么如何实现呢?最简单的方法是硬编码,将静态文件以文本或字节数组的形式直接编入源代码,go 也有一些库帮你自动生成代码,比如 go-bindata。很明显,这个库已经终止维护了,这是因为在 go 1.16 版本,官方发布了 embed 完美地解决了这个问题。本文简要介绍 embed 的一些基础用法。 embed 假设我们有一个文件 hello.txt Hello World! Hello go embed! 我们要写一个程序读取其中的内容并输出到终端: // file: main.go package main import ( "fmt" "os" ) func main() { s, err := os.ReadFile("./hello.txt") if err != nil { panic(err) } fmt.Println(string(s)) } 很简单,不是吗? ➜ tree . . ├── go.mod ├── hello.txt └── main.go 0 directories, 3 files ➜ go build main.go ➜ ./main Hello World! Hello go embed! 但是如果 hello.txt 这个文件不存在的话,我们再次运行程序: ...

2022年8月13日 · Aimer Neige
go image processing

Go 图像处理基础

前言 Go 语言的官方包 image 和 image/color 定义了非常多的类型,涵盖了很多的图像处理基础内容,本文简单介绍这些库中的基本概念和使用方法。 常见类型介绍 Colors Colors 是一个接口,它的代码如下: type Color interface { // RGBA returns the alpha-premultiplied red, green, blue and alpha values // for the color. Each value ranges within [0, 0xffff], but is represented // by a uint32 so that multiplying by a blend factor up to 0xffff will not // overflow. // // An alpha-premultiplied color component c has been scaled by alpha (a), // so has valid values 0 <= c <= a. RGBA() (r, g, b, a uint32) } 简单来说,它定义了一个函数,它将任意类型的颜色转化为 rgba 值。这个转化过程可能是有损失的,比如转化 CMYK 或 YCbCr 颜色空间的颜色。 ...

2022年8月12日 · Aimer Neige