Refactoring my blog using Astro.js

Foreword About four and a half years ago, I migrated the blog system from Typecho to Hexo. Hexo is a static site generator. It does not need to connect MySQL, PostgreSQL and other databases to generate pages dynamically, but generates all HTML pages at one time according to a given Markdown article file. Compared with dynamic schemes such as WordPress and Typecho, the server does not need to support dynamic languages such as PHP to generate static web pages in advance, which puts less pressure on the server's performance. But Hexo itself is not new. Its first version was released in July 2013. At that time, the single page application framework headed by React had just been released (React: May 2013), and the framework necessary for modern front-end processes such as Webpack did not exist (Webpack: February 2014). Therefore, Hexo naturally did not use these tools, but stayed in the era of splicing HTML strings. Several theme template systems commonly used by Hexo, such as EJS and Pug, are template systems based on string splicing. The absence of a modern front-end process means that I need to manually handle all the details of splicing HTML. Every time I modify the template, it reminds me of a good time to write PHP

 NixOS series (V): Illustrations for making DD disk images of small memory VPS

NixOS series (V): create DD disk image of small memory VPS

NixOS series article directory: NixOS series (I): Why do I love NixOS series (II): Basic configuration, Nix Flake, Recommended reading for mass deployment: Beginner's Guide to NixOS and Nix Flakes, by Ryan Yin NixOS Series (III): Software Packaging, From Getting Started to Abandoning NixOS Series (IV): "Stateless" Operating System NixOS Series (V): Making DD Disk Images for Small Memory VPS Black Friday has passed. I believe some readers have bought some new VPS ECS, etc., and want to install NixOS on VPS. However, because the popularity of NixOS is not as good as that of CentOS, Debian, Ubuntu and other old Linux distributions, few VPS service providers provide disk images with preinstalled NixOS. Users can only manually install NixOS using one of the following methods: self mount the installation ISO image of NixOS, and then manually install the disk. Because you can freely operate VPS hard disks in the NixOS installation image environment, this method has the highest degree of freedom. You can partition the hard disk and specify the file system format at will. However, before using this method, your host company needs to meet any of the following three prerequisites:

 Illustrations of implementing Nix trigonometric function library from scratch

Implementation of Nix trigonometric function library from scratch

(The picture is from Wikipedia - trigonometric function) Because I want to calculate the network delay between all my VPS nodes and write the delay into the configuration of the Bird BGP server, so that the data between nodes can be forwarded through the path with the lowest delay. However, as of today, there are 17 nodes in my network. I don't want to manually ping the delay between nodes. So I thought of a method: mark the longitude and latitude of the physical location of all nodes, calculate the physical distance according to the longitude and latitude, and then divide the distance by half of the speed of light to obtain the approximate delay. I randomly sampled several pairs of nodes, and found that the routes between them are relatively straight without serious detours. At this time, the physical distance is an approximate value that can meet my requirements. Because my nodes use NixOS and use the Nix language to manage the configuration, I need to find a way to calculate this distance in Nix. A commonly used method to calculate the distance according to longitude and latitude is the Haverine Formula, which approximates the earth to a sphere with a radius of 6371 kilometers, and then uses the following formula to calculate the distance between longitude and latitude: Reference: Wikipedia - Semivector Formula h=h a v (d r)=(h a v (φ 2 − φ 1)

 Illustration to solve the problem of Pipewire being SIGKILL

Solve the problem of Pipewire being SIGKILL

Symptoms I frequently encounter the sudden stop of the Pipewire audio framework: the problem usually occurs when my laptop is connected/disconnected from the power supply, and my computer will get stuck for a short time due to switching performance modes; Systemctl -- user status pipewire.service can only see that the Pipewire process is terminated by the SIGKILL signal, and there is no other useful log information; Coredumpctl and dmesg also cannot find the record of Coredump memory dump events. Cause Pipewire process has real-time priority when running, and its scheduling requirements are met first, so as to process audio data in time and avoid audio jam. Pipewire improves the process priority through its libpipewire module rt module requesting the RTKit (Realtime Kit) service running with root privileges in the system, and then RTKit modifies the process priority with privileges. However, if a process with real-time priority has a bug and enters an endless loop, it will consume all CPU resources. Most other processes on the system (including but not limited to the SSH server, Xorg, and your shell) cannot get any CPU time slice and process any task because of their lower priority

 Illustration of how to detonate DN42 network (updated on May 12, 2023)

How to detonate DN42 network (updated on May 12, 2023)

DN42 is a testing network, and everyone is helping everyone. Even if you accidentally mess up, no one will blame you. You can ask for help on DN42's IRC channel, mailing list or unofficial Telegram group. Because DN42 is an experimental network, many novices and Xiaobai also participate in it. At this time, there will be novice configuration errors, which will affect the entire DN42 network, or even blow up the entire network. Now, as an elder (x), I will teach you how to blow up DN42 and how to prevent him from blowing you up if you are Xiaobai's neighbor (referring to Peer relationship). Note: You should not actually perform these operations in the DN42 network. You should pay more attention to the defense against damage. Malicious damage will cause you to be kicked out of the DN42 network. The information in this article is adapted from the real tragedies in Telegram group and IRC. Update record 2023-05-12: Add the contents of loop caused by modifying BGP Localref. 2020-08-27: format modification, addition of complete IRC logs, Chinese translation of some contents, addition of another section of address mask incorrectly filled, and ASN missing one bit. 2020-07-13:...

NVIDIA virtual machine graphics card pass through on Optimus MUXed notebook (update 2023-05)

A year ago, in order to be able to use Arch Linux to browse web pages, write code, and use Windows to run games and other tasks that cannot be easily completed on Linux, I tried to use my Lenovo R720 game book for a video card pass through. However, because the computer is Optimus MUXless architecture (described in the previous article), that is, there is no output port for the single display, and the screen is displayed by the core display, the application of that configuration was greatly hindered, and I finally gave up. But now, I have a new computer. The HDMI output interface of this computer is directly connected to the NVIDIA independent graphics card, that is, Optimus MUXed architecture. Under this architecture, there is a way for the virtual machine to recognize a "display on the sole display", so that most functions can be enabled normally. As a result, I can finally configure a set of graphics card pass through configuration that can be used for a long time. Update log 2023-05-08: Update some contents for the new version of Looking Glass B6. 2022-01-26: PCIe power-saving patch is invalid. Preparation Before proceeding according to this article, you need to be ready: a laptop with Optimus MUXed architecture. My computer model is HP OMEN 17t-ck000 (i7-11800H, RTX 3070)

Modify APN to solve the problem that China Telecom cannot roam 4G on AOSP ROM

As my one plus 8T official system maintenance cycle is coming to an end, I painted my phone with Nameless OS, a third-party Android ROM based on Lineage OS. But after swiping in, I found that my China Telecom mobile phone card could not connect to the local operator's 4G network for international roaming, only 2G or 3G signals. As the local operator is withdrawing 2G and 3G from the network recently, the roaming signal of the mobile phone is very poor, and there is a great delay in sending and receiving SMS messages, and it is also unable to connect to VoLTE for normal calls. I tested other third-party ROMs based on Lineage OS and found similar problems. After many attempts, I found that the problem seemed to be the APN settings of the phone. I said "it seems" because the APN modification solved my problem, but I don't understand why it works, nor am I sure this is the right solution. My steps to solve the problem are as follows: go to Phone Settings - SIM Card - China Telecom - APN Settings. Click "China Telecom NET Settings" (ctnet) to enter the detailed settings. Modify the APN Type to default, supl, dun, ims. The original values are default, supl, dun. Click the menu at the top right corner and select Save

Notes on NAS+Soft Routing Configuration of Old HP Workstations

I bought an old HP workstation and used the author's NAS+soft route. This article briefly records the configuration process of this workstation. The choice of NAS hardware mainly includes: finished NAS (such as Qunhui) Advantages: out of the box. Disadvantages: The price is expensive, to the extent of "buying system and sending hardware". And compared with various Linux distributions, the original NAS system is difficult to customize. Advantages of second-hand servers: they are cheap. After the warranty period, most of these servers are treated as waste products by the data center, and then recycled at a very low cost. After renovation, they are sold for the second time. Stable. These servers are designed for long-term operation, and have been operating in the data center with stable temperature and humidity and no dust. Disadvantages: It is noisy. You need to modify the system configuration to reduce the fan speed, replace the silent fan, or install a fan speed reduction line. Large volume (mainly for rack servers). Special accessories. The server manufacturer will customize various accessories for specific models. If you have expansion needs, you need to purchase these special accessories at an extra price. Advantages of second-hand workstations: cheap, stable, the same as second-hand servers. The noise is low. After all, the workstation is placed beside the desk, not used in the computer room. Disadvantages: special accessories

 NixOS Series (IV): Illustrations of "Stateless" Operating Systems

NixOS Series (IV): "Stateless" Operating System

NixOS series article directory: NixOS series (I): Why do I love NixOS series (II): Basic configuration, Nix Flake, Recommended reading for mass deployment: Beginner's Guide to NixOS and Nix Flakes, by Ryan Yin NixOS Series (III): Software Packaging, From Getting Started to Abandoning NixOS Series (IV): "Stateless" operating system NixOS Series (V): Creating DD disk image update records for small memory VPS: 2023-02-18: In the section "Moving Nix Daemon's Temporary Folder", Fix the problem that the configuration does not work for the root user. One of the most well-known features of NixOS is that most software settings of the system are generated and managed by configuration files in Nix language. Even if these software modify their own configuration files during operation, NixOS will overwrite the configuration files again when switching Nix configurations or restarting the system next time. For example, if you run ls - alh/etc on a computer running NixOS, you can see that most configuration files are just soft links to/etc/static: # Omit some irrelevant lines lrwxrwxrwx 1 root root 18 Jan 13 03:

 NixOS series (III): software packaging, illustrations from entry to abandonment

NixOS series (III): software packaging, from entry to abandonment

NixOS series article directory: NixOS series (I): Why do I love NixOS series (II): Basic configuration, Nix Flake, Recommended reading for mass deployment: Beginner's introduction to NixOS and Nix Flakes, by Ryan Yin NixOS series (3): software packaging, from entry to abandonment of NixOS series (4): "stateless" operating system NixOS series (5): creating DD disk image of small memory VPS NixOS is characterized by:, All binary programs and library files of the system are in the/nix/store directory and managed by the Nix package manager. This also means that NixOS does not comply with the FHS standard of Linux. There is no library file dynamic loader like ld-linux-x86-64. so. 2 in its/lib or/lib64 directory, let alone library files like libc.so. Therefore, binary files compiled for other Linux systems cannot run under NixOS unless they are statically linked. Therefore, to use the software that does not exist in the Nixpkgs warehouse on NixOS, the best solution is to write a packaging script in Nix language, package the software, and then add the packaging definition to configuration.nix to install it on the system