Skip to content

2022年11月

xmind常用配置

xind 不能默认打开对应文件问题

在xmind文件中新建 xmind.bat 文件

E:
cd E:\{xmind dir}
start XMind.exe %1%

右键打开方式,使用该bat文件打开

vscode 打开xmind文件

试过vscode 几个 Open 插件均无效,但我测试可以使用task去打开

添加tasks.json

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "xmind",
            "type": "process",
            "command": "E:/{XMind dir}/XMind.bat",
            "args": [
                "${file}"
            ],
            "problemMatcher": [],
        }
    ]
}

type 一定要使用 process 否则只能打开 XMind, 这样点开 对应xmind文件 运行 run task 即可

进一步方便打开

如果嫌运行命令行太麻烦,只需如下配置,

下载以下插件

Task Buttons
v1.1.3
spencerwmiles

setting配置

"VsCodeTaskButtons.showCounter": false,
"VsCodeTaskButtons.tasks": [
    {
        "label": "🔥 open xmind",
        "task": "xmind"
    }
]

这下可使用左下任务栏打开任务了,happy

挂载

挂载新硬盘

1.查看硬盘

root@ubuntu:~# fdisk -lu
Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x3c78b7a1

Device     Boot    Start      End  Sectors Size Id Type
/dev/sda1  *        2048 16777215 16775168   8G 83 Linux
/dev/sda2       16779262 20969471  4190210   2G  5 Extended
/dev/sda5       16779264 20969471  4190208   2G 82 Linux swap / Solaris

Partition 2 does not start on physical sector boundary.


Disk /dev/sdb: 50 GiB, 53687091200 bytes, 104857600 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

2.创建分区

root@ubuntu:~# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0xdf96fde2.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-104857599, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-104857599, default 104857599):

Created a new partition 1 of type 'Linux' and of size 50 GiB.

Command (m for help): p
Disk /dev/sdb: 50 GiB, 53687091200 bytes, 104857600 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0xdf96fde2

Device     Boot Start       End   Sectors Size Id Type
/dev/sdb1        2048 104857599 104855552  50G 83 Linux

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

3.格式化分区

root@ubuntu:~# mkfs.ext4 /dev/sdb1
mke2fs 1.42.13 (17-May-2015)
Discarding device blocks: 完成
Creating filesystem with 13106944 4k blocks and 3276800 inodes
Filesystem UUID: c0887faa-eed2-4f38-9f18-6e3059261202
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
    4096000, 7962624, 11239424

Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

4.挂载和查看分区表

root@ubuntu:~# mount /dev/sdb1 /data
root@ubuntu:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            2.0G     0  2.0G   0% /dev
tmpfs           395M  5.5M  389M   2% /run
/dev/sda1       7.8G  1.2G  6.2G  16% /
tmpfs           2.0G     0  2.0G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           2.0G     0  2.0G   0% /sys/fs/cgroup
tmpfs           395M     0  395M   0% /run/user/0
/dev/sdb1        50G   52M   47G   1% /data

5.永久挂载

# 执行前一定要进行备份,以免误操作
echo '/dev/sdb1       /data   ext4    defaults        0       0' >> /etc/fstab

映射硬盘

eg: 将 docker lib 目录映射到 /data/lib/docker

echo '/data/lib/docker /var/lib/docker none defaults,bind 0 0'>>/etc/fstab

fstab 立即生效

mount -a

windows常用脚本

程序后台运行

之前 alist 挂载网盘后台运行

Set ws = CreateObject("Wscript.Shell")
ws.run "D:\alist-windows-amd64\alist.exe server",vbhide

命名为 alist.VBS 加入到 shell:startup 中运行

golang超实用技巧

拉取私有库

比如我私有库为 github.com/gofulljs/private

1.配置ssh密钥用以拉取代码

ssh -T git@github.com
Hi gofulljs! You've successfully authenticated, but GitHub does not provide shell access.

2.配置https替换为ssh

git config --global url."git@github.com:gofulljs".insteadOf "https://github.com/gofulljs"

这样针对自己写的库都会走ssh,不会弹出

 fatal: could not read Username for 'https://github.com': terminal prompts disabled
  1. 配置自己库路径为私有,这样避免校验
go env -w GOPRIVATE=github.com/gofulljs
  1. 享受成果
go get github.com/gofulljs/private@latest

可自行打 tag 来实用自己项目了,非常happy

linux信息

查看系统版本

# 打印系统信息
$ uname -a
Linux LAPTOP-2181LTT2 5.4.72-microsoft-standard-WSL2 #1 SMP Wed Oct 28 23:40:43 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

# 获取发行版信息
$ cat /etc/issue
Ubuntu 18.04.6 LTS \n \l

$ cat /etc/issue.net 
Ubuntu 18.04.6 LTS

$ cat /etc/os-release 
NAME="Ubuntu"
VERSION="18.04.6 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.6 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic

# 根据上面 ID_LIKE 来获取version
$ cat /etc/debian_version
9.3

# 也可直接通过system 获取(如果有)
$ cat /etc/system-release
9.3

# 获取内核版本
$ cat /proc/version 
Linux version 5.4.72-microsoft-standard-WSL2 (oe-user@oe-host) (gcc version 8.2.0 (GCC)) #1 SMP Wed Oct 28 23:40:43 UTC 2020

# dmesg 命令
$ dmesg | grep "Linux"
[    0.000000] Linux version 5.4.72-microsoft-standard-WSL2 (oe-user@oe-host) (gcc version 8.2.0 (GCC)) #1 SMP Wed Oct 28 23:40:43 UTC 2020
[    3.522133] ACPI: Added _OSI(Linux-Dell-Video)
[    3.527064] ACPI: Added _OSI(Linux-Lenovo-NV-HDMI-Audio)
[    3.531431] ACPI: Added _OSI(Linux-HPI-Hybrid-Graphics)

# 其他 Yum/Dnf
$ yum info nano
$ yum repolist
$ dnf info nano
$ apt-cache policy nano
nano:
  Installed: 2.9.3-2
  Candidate: 2.9.3-2
  Version table:
 *** 2.9.3-2 500
        500 http://archive.ubuntu.com/ubuntu bionic/main amd64 Packages
        100 /var/lib/dpkg/status

golang技巧

Go语言中的数值溢出检测

package main

import (
    "fmt"
    "math"
)

func addInt8WithOverflowCheck(a, b int8) (int8, bool) {
    result := a + b
    // 使用异或运算检测溢出
    overflow := (a^result)&(b^result) < 0
    return result, overflow
}

func main() {
    a := int8(-127)
    b := int8(-1)
    result, overflowed := addInt8WithOverflowCheck(a, b)
    if overflowed {
        fmt.Println("溢出发生,结果:", result)
    } else {
        fmt.Println("结果:", result)
    }
}

nginx配置

nginx 配置单机器多域名

1.conf.d/default.conf 默认域名,若没命中,进入此处

server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;

    location / {
        root   /usr/share/nginx/html/default;
        index  index.html index.htm;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

1.conf.d/www.my.com.conf www.my.com 和 my.com 进入会命中

server {
    listen       80;
    listen  [::]:80;
    server_name  www.my.com my.com;

    location / {
        root   /usr/share/nginx/html/my;
        index  index.html index.htm;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

常用功能

文件服务器

server {
    listen 80;  # 监听 HTTP 请求的端口,可以根据需要更改
    server_name files.localhost;  # 你的服务器名称或 IP 地址

    location / {
        alias /files/;  # 指定文件存储目录
        autoindex on;  # 启用自动列出目录内容
        autoindex_exact_size off;  # 显示文件大小的近似值
        charset utf-8;
    }
}

basic auth

  • htpasswd文件生成
printf "test:$(openssl passwd -crypt 123456)\n" >> /usr/local/nginx-1.5.1/conf/basicauth
  • 使用
server{
    listen 80;
    server_name  auth.localhost;

    location / {
        root   html;
        auth_basic "Please enter your username and password";
        auth_basic_user_file ../conf/basicauth; 
        index  index.html index.htm;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}