西维蜀黍

【OpenWrt】macOS 下小米红米路由器 AC2100 (Xiaomi Redmi Router AC2100) 刷 OpenWrt

Preparation

相关工具安装

$ brew install netcat
$ pip3 install scapy

下载 busybox 和固件

$ wget https://busybox.net/downloads/binaries/1.31.0-defconfig-multiarch-musl/busybox-mipsel -o busybox-mipsel

$ wget https://downloads.openwrt.org/snapshots/targets/ramips/mt7621/openwrt-ramips-mt7621-xiaomi_redmi-router-ac2100-squashfs-kernel1.bin -o openwrt-ramips-mt7621-xiaomi_redmi-router-ac2100-squashfs-kernel1.bin
$ wget https://downloads.openwrt.org/snapshots/targets/ramips/mt7621/openwrt-ramips-mt7621-xiaomi_redmi-router-ac2100-squashfs-rootfs0.bin -o openwrt-ramips-mt7621-xiaomi_redmi-router-ac2100-squashfs-rootfs0.bin

# download the latest version from https://downloads.openwrt.org/releases/, e.g., https://downloads.openwrt.org/releases/23.05.2/targets/ramips/mt7621/
  ...


【Golang】Golang 遍历 map 时 key 随机化问题(Interation Order)

Context

package main

import (
	"fmt"
)

func main() {
	x := make(map[int]int)
	for i := 0; i < 30; i++ {
		x[i] = i
	}

	for i := 0; i < 10; i++ {
		for k, v := range x {
			fmt.Println(k, v)
			break
		}
	}
}

// output 
18 18
29 29
2 2
2 2
2 2
16 16
28 28
1 1
0 0
4 4

可以看到,我们进行10次遍历 map,每次遍历都只print 出第一对key-value pair,而每次遍历 print 的结果都不同。

  ...


【hexo】使用 node 14 运行 hexo 报错

Situation

$ hexo g
FATAL Something's wrong. Maybe you can find the solution here: https://hexo.io/docs/troubleshooting.html
TypeError [ERR_INVALID_ARG_TYPE]: The "mode" argument must be integer. Received an instance of Object
    at copyFile (fs.js:1895:10)
    at tryCatcher (/SW/myBlog/node_modules/hexo-deployer-git/node_modules/bluebird/js/release/util.js:16:23)
    at ret (eval at makeNodePromisifiedEval (/usr/local/lib/node_modules/hexo-cli/node_modules/bluebird/js/release/promisify.js:184:12), <anonymous>:13:39)
    at /SW/myBlog/node_modules/hexo-deployer-git/node_modules/hexo-fs/lib/fs.js:144:39
    at tryCatcher (/SW/myBlog/node_modules/hexo-deployer-git/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/SW/myBlog/node_modules/hexo-deployer-git/node_modules/bluebird/js/release/promise.js:517:31)
    at Promise._settlePromise (/SW/myBlog/node_modules/hexo-deployer-git/node_modules/bluebird/js/release/promise.js:574:18)
    at Promise._settlePromise0 (/SW/myBlog/node_modules/hexo-deployer-git/node_modules/bluebird/js/release/promise.js:619:10)
    at Promise._settlePromises (/SW/myBlog/node_modules/hexo-deployer-git/node_modules/bluebird/js/release/promise.js:699:18)
    at Promise._fulfill (/SW/myBlog/node_modules/hexo-deployer-git/node_modules/bluebird/js/release/promise.js:643:18)
    at Promise._resolveCallback (/SW/myBlog/node_modules/hexo-deployer-git/node_modules/bluebird/js/release/promise.js:437:57)
    at Promise._settlePromiseFromHandler (/SW/myBlog/node_modules/hexo-deployer-git/node_modules/bluebird/js/release/promise.js:529:17)
    at Promise._settlePromise (/SW/myBlog/node_modules/hexo-deployer-git/node_modules/bluebird/js/release/promise.js:574:18)
    at Promise._settlePromise0 (/SW/myBlog/node_modules/hexo-deployer-git/node_modules/bluebird/js/release/promise.js:619:10)
    at Promise._settlePromises (/SW/myBlog/node_modules/hexo-deployer-git/node_modules/bluebird/js/release/promise.js:699:18)
    at Promise._fulfill (/SW/myBlog/node_modules/hexo-deployer-git/node_modules/bluebird/js/release/promise.js:643:18)
    at Promise._resolveCallback (/SW/myBlog/node_modules/hexo-deployer-git/node_modules/bluebird/js/release/promise.js:437:57)
    at Promise._settlePromiseFromHandler (/SW/myBlog/node_modules/hexo-deployer-git/node_modules/bluebird/js/release/promise.js:529:17)
    at Promise._settlePromise (/SW/myBlog/node_modules/hexo-deployer-git/node_modules/bluebird/js/release/promise.js:574:18)
    at Promise._settlePromise0 (/SW/myBlog/node_modules/hexo-deployer-git/node_modules/bluebird/js/release/promise.js:619:10)
    at Promise._settlePromises (/SW/myBlog/node_modules/hexo-deployer-git/node_modules/bluebird/js/release/promise.js:699:18)
    at Promise._fulfill (/SW/myBlog/node_modules/hexo-deployer-git/node_modules/bluebird/js/release/promise.js:643:18)
    at Promise._resolveCallback (/SW/myBlog/node_modules/hexo-deployer-git/node_modules/bluebird/js/release/promise.js:437:57)
    at Promise._settlePromiseFromHandler (/SW/myBlog/node_modules/hexo-deployer-git/node_modules/bluebird/js/release/promise.js:529:17)
    at Promise._settlePromise (/SW/myBlog/node_modules/hexo-deployer-git/node_modules/bluebird/js/release/promise.js:574:18)
    at Promise._settlePromise0 (/SW/myBlog/node_modules/hexo-deployer-git/node_modules/bluebird/js/release/promise.js:619:10)
    at Promise._settlePromises (/SW/myBlog/node_modules/hexo-deployer-git/node_modules/bluebird/js/release/promise.js:699:18)
    at Promise._fulfill (/SW/myBlog/node_modules/hexo-deployer-git/node_modules/bluebird/js/release/promise.js:643:18)
    at /SW/myBlog/node_modules/hexo-deployer-git/node_modules/bluebird/js/release/nodeback.js:42:21
    at FSReqCallback.oncomplete (fs.js:163:23)
  ...


【Linux】Oh-my-zsh 启动慢

升级

$ upgrade_oh_my_zsh

启动测速

$ time /bin/zsh -i -c exit

$ for i in $(seq 1 10); do /usr/bin/time $SHELL -i -c exit; done
  ...


【Linux】Shell 和 Shell 脚本的执行

fork - 创建子 shell 进程

父子 shell 进程是相对而言的,它描述了两个 shell 进程的fork关系。

以bash为例,当在bash shell中执行一个命令时,其实是在当前 bash shell 进程中 fork 出一个子 bash shell 进程,然后在这个子进程中运行相应的命令,当命令执行完成后,这个子进程就被end了。

简单来说,父Shell进程创建子Shell进程时,调用的是 fork() 函数。

在这种情况中:

  • 子 shell 进程会继承父 shell 进程中设置的环境变量
  • 但是子 shell 进程中设置的环境变量并不会带回父 shell 进程(即不会影响父 shell 进程),以下为证明:
$ export SW="aaa"
$ echo $SW
aaa
$ bash
$ echo $SW
aaa
$ export SW2="bbb"
$ echo $SW2
bbb
$ exit
exit
$ echo $SW2
  ...


【Linux】Shell 和 Bash

Unix shell

Unix shell,一种壳层与命令行界面,是UNIX操作系统下传统的用户和计算机的交互界面。第一个用户直接输入命令来执行各种各样的任务。

普通意义上的shell就是可以接受用户输入命令的程序。它之所以被称作shell是因为它隐藏了操作系统低层的细节。同样的Unix下的图形用户界面GNOME和KDE,有时也被叫做“虚拟shell”或“图形shell”。

  ...


【Linux】bash 和 zsh 的启动脚本(.zshrc,.bash_profile,~/.profile 等区别)

结论

zsh

当默认 shell 为 zsh 时,且当开启一个新 tab 时(或者一台主机通过 SSH 登录本主机时),/etc/zprofile 、/etc/zshrc 和 ~/.zshrc 均会被执行 ,且执行顺序为:

  • /etc/zprofile
  • /etc/zshrc
  • ~/.zshrc

当开启一个新 tab 时,

Last login: Sat Jun 13 11:46:23 on ttys006
execute /etc/zprofile
execute /etc/zshrc
execute ~/.zshrc

当一台主机通过 SSH 登录本主机时

$ ssh wei.shi@192.168.16.173
Last login: Sat Jun 13 11:54:43 2020
execute /etc/zprofile
execute /etc/zshrc
execute ~/.zshrc
~ $

当启用一个新zsh 进程时

$ zsh
execute /etc/zshrc
execute ~/.zshrc
$
  ...


【Golang】go-redis Redis 连接库学习

  ...


【Redis】Wireshark 分析 Redis 通讯

Background

Redis client与Redis server在默认情况下的通讯,是不加密的。而且他们之间的通讯基于TCP。

因此,我们可以通过Wireshark来获取它们之间的通讯内容。

Redis server: 192.168.184:6379

Redis client: 192.168.31.169

  ...


【Docker】Docker Compose

Install

Run this command to download the current stable release of Docker Compose:

$ sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

Apply executable permissions to the binary:

$ sudo chmod +x /usr/local/bin/docker-compose

Set a soft link

$ sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

Test the installation.

$ docker-compose --version
  ...