diff --git a/src/blog/post-1.md b/src/blog/post-1.md index f577048..0f19c45 100644 --- a/src/blog/post-1.md +++ b/src/blog/post-1.md @@ -65,7 +65,7 @@ bot.py是我们启动机器人后端的时候需要启动的程序,而针对 bot.py中我们一般如下配置 -``` +```python import nonebot from nonebot.adapters.qq import Adapter as QQAdapter from nonebot import logger @@ -97,7 +97,7 @@ Nonebot2提供一种非常方便的响应器:_on\_command()_ 上代码: -``` +```python from nonebot import on_command from nonebot.rule import to_me @@ -131,7 +131,7 @@ asnyc def get_weather(): 其实和on\_command()差不多。 -``` +```python from nonebot import on_command from nonebot.rule import to_me @@ -147,7 +147,7 @@ asnyc def get_weather(): 只要有用户对机器人发送消息,就会触发此响应器。我们一般将其用于处理用户的非规范输入。 -``` +```python from nonebot import on_message from nonebot.rule import Rule, to_me @@ -194,7 +194,7 @@ on\_message()此时接收到了消息,于是它调用check\_value\_in\_menu() 那我们上代码: -``` +```python from nonebot import on_command from nonebot.rule import to_me from nonebot.adapters import Message @@ -233,7 +233,7 @@ async def get_weather(args: Message = CommandArg()): 获取方式: -``` +```python from nonebot.adapters.qq import MessageEvent from nonebot.plugin import on_command from nonebot.rule import to_me @@ -254,7 +254,7 @@ async def test_method(message: MessageEvent): 在最开始的示例中我们可以看到它的基本用法: -``` +```python weather.send("天气是……") ``` @@ -266,7 +266,7 @@ weather.send("天气是……") 例如,使用send方法: -``` +```python from nonebot import on_command from nonebot.rule import to_me @@ -294,7 +294,7 @@ nonebot提供两种发送方式:发送本地图片和通过URL发送图片. 我们先来看看本地发送:使用MessageSegment.file\_image() -``` +```python from pathlib import Path from nonebot.rule import to_me from nonebot.plugin import on_command @@ -312,7 +312,7 @@ async def handle_function(): 发送URL图片同样简单:使用MessageSegment.image() -``` +```python from pathlib import Path from nonebot.rule import to_me from nonebot.plugin import on_command @@ -334,7 +334,7 @@ async def handle_function(): 仅需使用 -``` +```python MessageSegment.video(video_url) # 发送url链接的视频 MessageSegment.file_video(Path("path/to/your/video.mp4")) # 发送本地视频 @@ -344,7 +344,7 @@ MessageSegment.file_video(Path("path/to/your/video.mp4")) # 发送本地视频 有些时候,我们想像qq客户端一样,发送一条带图片的消息,这也非常好实现: -``` +```python from nonebot.rule import to_me from nonebot.plugin import on_command from nonebot.adapters.qq import MessageSegment @@ -371,7 +371,7 @@ async def handle_function(): 使用天气api来搭建一个查询天气的功能。 -``` +```python from nonebot.rule import to_me from nonebot.plugin import on_command from nonebot.adapters import Message diff --git a/src/blog/post-2.md b/src/blog/post-2.md index ac16d83..6cfd252 100644 --- a/src/blog/post-2.md +++ b/src/blog/post-2.md @@ -31,11 +31,11 @@ tags: ["树莓派", "Linux", "教程"] 进入安装包所在的目录,并在终端输入 -``` +```shell dpkg -i sunshine-debian-bookworm-arm64.deb ``` -``` +```shell dpkg -i sunshine-debian-bookworm-arm64.deb ``` @@ -43,11 +43,11 @@ dpkg -i sunshine-debian-bookworm-arm64.deb 如果出现缺少依赖的问题,输入 -``` +```shell sudo apt-get install -f ``` -``` +```shell sudo apt-get install -f ``` @@ -55,11 +55,11 @@ sudo apt-get install -f 终端输入 -``` +```shell sunshine ``` -``` +```shell sunshine ``` @@ -75,11 +75,11 @@ sunshine 确保树莓派的软件是全新的,运行以下命令: -``` +```shell sudo apt update && sudo apt full-upgrade -y ``` -``` +```shell sudo apt update && sudo apt full-upgrade -y ``` @@ -93,22 +93,22 @@ sudo apt update && sudo apt full-upgrade -y 那么首先修改启动配置: -``` +```shell sudo nano /boot/firmware/config.txt ``` -``` +```shell sudo nano /boot/firmware/config.txt ``` 打开启动配置文件,在最后面添加两行 -``` +```shell dtoverlay=vc4-fkms-v3d max_framebuffers=2 ``` -``` +```shell dtoverlay=vc4-fkms-v3d max_framebuffers=2 ``` @@ -117,11 +117,11 @@ max_framebuffers=2 之后,输入 -``` +```shell sudo raspi-config ``` -``` +```shell sudo raspi-config ``` @@ -137,11 +137,11 @@ sudo raspi-config 打开VNC远程桌面(切记不要用ssh终端),在终端中输入 -``` +```shell echo $XDG_SESSION_TYPE ``` -``` +```shell echo $XDG_SESSION_TYPE ``` @@ -155,11 +155,11 @@ echo $XDG_SESSION_TYPE 在终端中输入 -``` +```shell systemctl enable avahi-daemon ``` -``` +```shell systemctl enable avahi-daemon ``` @@ -169,11 +169,11 @@ systemctl enable avahi-daemon 在VNC远程桌面的终端输入 -``` +```shell sunshine ``` -``` +```shell sunshine ``` diff --git a/src/blog/post-3.md b/src/blog/post-3.md index ea5253b..fdd5f27 100644 --- a/src/blog/post-3.md +++ b/src/blog/post-3.md @@ -13,7 +13,7 @@ tags: ["算法", "操作系统", "学习笔记"] 先上伪代码: -``` +```c++ bool flag[2]; // 表示进入临界区意愿的数组,初始值都为false int turn = 0; // turn表示优先让哪个进程进入临界区 diff --git a/src/blog/post-4.md b/src/blog/post-4.md index 747dd2e..d9c9d77 100644 --- a/src/blog/post-4.md +++ b/src/blog/post-4.md @@ -43,7 +43,7 @@ tags: ["算法", "操作系统", "学习笔记"] semaphore rw = 1; // 读写锁,用于实现共享进程的互斥访问 int count = 0; // 记录有几个读进程在访问文件 semaphore mutex = 1; // count的读写锁,防止同时有两个读进程访问count导致其中一个死锁
writer () { while(1){ P(rw); // 给缓冲区上锁,进行P操作, rw-- 写文件; V(rw); // 解锁,进行V操作,rw++ } } reader () { while(1){ P(mutex); // 给count上锁,防止有两个读进程同时读到count==0,导致死锁。 if (count == 0){ P(rw); // 如果count为0,则检查缓冲区是否上锁,若上锁则等待,若无锁则为缓冲区上锁。 } count++; V(mutex); // 解除count锁 读文件; P(mutex); // 给count上锁,防止有两个进程同时读到count==0,导致rw+2产生异常 count--; if (count == 0){ V(rw); // 如果count为0,则代表这个进程为最后一个读进程,解除缓冲区的锁。 } V(mutex); } } -``` +```c++ semaphore rw = 1; // 读写锁,用于实现共享进程的互斥访问 int count = 0; // 记录有几个读进程在访问文件 semaphore mutex = 1; // count的读写锁,防止同时有两个读进程访问count导致其中一个死锁 @@ -93,7 +93,7 @@ reader () { semaphore rw = 1; int count = 0; semaphore mutex = 1; semephore w = 1; // 用于实现写优先 writer () { while (1) { P(w); // 写进程先给w锁上锁,上锁后后来的读进程都需等待这个写进程解锁。 P(rw); // 给缓冲区上锁 写文件; V(rw); V(w); // 解锁,允许读进程加入读队列。 } } reader () { while (1) { P(w); // 新的读进程加入时先检查w锁是否上锁,若已上锁则阻塞等待。若未上锁则先给它上锁 P(mutex); if (count == 0) P(rw); count++; V(mutex); V(w); // 读进程加入队列之后,将w锁解锁,保证加入队列操作的原子性。 读文件; P(mutex); count--; if (count == 0) V(rw); V(mutex); } } -``` +```c++ semaphore rw = 1; int count = 0; semaphore mutex = 1; diff --git a/src/blog/post-7.md b/src/blog/post-7.md index 103d4fa..ad660af 100644 --- a/src/blog/post-7.md +++ b/src/blog/post-7.md @@ -117,19 +117,19 @@ tags: ["操作系统", "NixOS"] 启动`wpa_supplicant`服务: -``` +```shell sudo systemctl start wpa_supplicant ``` 进入交互模式: -``` +```shell sudo wpa_cli ``` 在 命令行中依次输入: -``` +```shell > add_network 0 > set_network 0 ssid "你家 WIFI 的 名字" @@ -144,7 +144,7 @@ OK 如果出现类似如下输出 -``` +```shell <3>CTRL-EVENT-CONNECTED - Connection to 32:85:ab:ef:24:5c completed [id=0 id_str=] ``` @@ -154,7 +154,7 @@ OK 如果你不放心,可以ping一下这个博客 -``` +```shell ping blog.cloverta.top ``` @@ -164,7 +164,7 @@ ping blog.cloverta.top 众所周知,由于不可抗力,NixOS的官方源我们不一定连的上。 -``` +```shell sudo -i nix-channel --add https://mirrors.ustc.edu.cn/nix-channels/nixos-unstable nixos nix-channel --update # 更新并解包频道 @@ -178,13 +178,13 @@ nix-channel --update # 更新并解包频道 在命令行中输入 -``` +```shell lsblk ``` 你大概能得到一个类似这样的输出: -``` +```shell NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sda 8:0 1 57.3G 0 disk └─sda1 8:1 1 57.3G 0 part /run/media/cloverta/NIXOS-MINIM @@ -201,7 +201,7 @@ nvme0n1 259:0 0 953.9G 0 disk 如果你分区是在`nvme0n1`上进行的(很明显上述信息中两个分区的大小远小于硬盘总大小),那么输入 -``` +```shell cfdisk /dev/nvme0n1 ``` @@ -223,7 +223,7 @@ cfdisk /dev/nvme0n1 两个分区类型都选择`Primary`,建立好分区之后,再次输入`lsblk`查看分区情况,应该能看到这两个分区 -``` +```shell ❯ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sda 8:0 1 57.3G 0 disk @@ -243,19 +243,19 @@ nvme0n1 259:0 0 953.9G 0 disk 我们可以看到`nvme0n1p3`是我们计划作为boot分区使用的,那我们现在格式化它为FAT32格式 -``` +```shell mkfs.fat -F 32 -n boot /dev/nvme0n3 ``` 接着,我们将主分区格式化为btrfs格式 -``` +```shell mkfs.btrfs -L nixos /dev/nvme0n1p4 ``` 之后将这两个分区挂载到NixOS的文件系统上 -``` +```shell mount /dev/nvme0n1p4 /mnt mkdir -p /mnt/boot mount /dev/nvme0n1p3 /mnt/boot @@ -263,7 +263,7 @@ mount /dev/nvme0n1p3 /mnt/boot 接下来检查一下是否挂在成功 -``` +```shell ❯ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sda 8:0 1 57.3G 0 disk @@ -285,19 +285,19 @@ NixOS将所有的系统配置保存在一个名为`configuration.nix`的文件 现在,我们生成一个系统默认配置文件: -``` +```shell nixos-generate-config --root /mnt ``` 然后编辑配置 -``` +```shell vim /mnt/etc/nixos/configuration.nix ``` 你应该会看到一个类似这样的配置文件: -``` +```nix { config, lib, pkgs, ... }: {