小星的编程笔记

  • ubuntu 设置密钥登录

    1. 在本地生成密钥对

    在本地电脑上执行(Windows/Mac/Linux 都可以):

    ssh-keygen -t ed25519 -C "1111222@qq.com"

    按提示操作:

    • 保存位置:直接回车(默认 ~/.ssh/id_ed25519
    • 密码:可以设置密码增加安全性,或直接回车留空
    • Enter file in which to save the key (C:\Users\Administrator/.ssh/id_ed25519):
    • Enter passphrase (empty for no passphrase):
    • Enter same passphrase again:

    旧系统兼容性:如果服务器不支持 ed25519,改用 RSA:

    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

    2. 将公钥复制到服务器

    先查看本地公钥内容:

    在 C:\Users\Administrator.ssh\id_ed25519.pub

    登录服务器,将公钥追加到授权文件:

    mkdir -p ~/.ssh
    chmod 700 ~/.ssh
    echo "粘贴你的公钥内容" >> ~/.ssh/authorized_keys
    chmod 600 ~/.ssh/authorized_keys

    3. 配置 SSH 服务(增强安全性)

    sudo vim /etc/ssh/sshd_config
    # 禁用密码登录(确认能用密钥登录后再设置!)
    PasswordAuthentication no
    
    # 禁用 root 密码登录(如需允许 root 密钥登录,设为 prohibit-password)
    PermitRootLogin prohibit-password
    
    # 禁用空密码
    PermitEmptyPasswords no
    
    # 启用公钥认证
    PubkeyAuthentication yes

    注意:保存后,一定要先验证配置是否正确(非常重要!):

    sudo sshd -t

    如果没有错误输出,重启 SSH 服务:

    sudo systemctl restart sshd

    4 客户端 FinalShell 登录 选择私钥 位置

    C:\Users\Administrator.ssh\id_ed25519

  • mysql安全的添加索引

    ALTER TABLE app_member_ext
    ADD INDEX idx_uid (uid),
    ALGORITHM=INPLACE, LOCK=NONE;

    对于InnoDB引擎的普通索引

    • ALGORITHM=INPLACE:不会全表复制,只修改元数据和填充索引页
    • LOCK=NONE:允许并发读写,不会阻塞DML操作
    • 结论:可以在线执行,不会导致业务中断

    注意. 主键索引不支持

    如何安全的重命名 表

    RENAME TABLE
    table1 TO table1_backup_20260509,
    table1_copy1 TO table1;
    
    假设有  table1_copy1  完全复制 table1  结构和数据
    先将  table1  改为  table1_backup_20260509
    然后将  table1_copy1  重命名为 table1   完成。
    
    原子性:MySQL 会锁住字典,确保在重命名期间不会有新的查询进来。当语句执行完毕,所有后续的查询都会指向新的表(即原来的 copy1)。
    
    回滚简单:如果新表有问题,你可以马上执行反向操作,把名字换回来,数据零损失。

  • git常用命令

    1.将本地代码推送到远程空仓库

    设置远程仓库的地址
    git remote set-url origin https://codeup.aliyun.com/123456/sph/sph_crawler.git
    
    推送并绑定master分支
    git push -u origin master
    
    强制推送 覆盖远程
    git push -f origin master
    
    

    常用的gitignore文件

    # Python
    # 字节编译的 Python 文件
    __pycache__/
    *.py[cod]
    *$py.class
    *.so
    .Python
    
    # 虚拟环境
    venv/
    env/
    .venv/
    ENV/
    
    # 编辑器
    # VS Code
    .vscode/
    *.code-workspace
    
    # PyCharm
    .idea/
    *.iml
    *.ipr
    *.iws
    
    # 其他编辑器
    *.swp
    *.swo
    *~
    .DS_Store
    
    # 日志目录
    logs/
    *.log
    
    # 环境配置文件
    .env
    .env.example
    
    # 其他
    *.egg-info/
    dist/
    build/
    .pytest_cache/
    .coverage
    htmlcov/
    
  • Cursor使用

    1 、如何关闭多余的工作区

    ctrl+w 关闭

    2、打开或关闭终端显示

    Ctrl+` (tab上面的反引号)

    3、修改标题栏的颜色

    Ctrl + Shift + P
    → Preferences: Open User Settings (JSON)

    打开用户设置

    "workbench.colorCustomizations": {
            "titleBar.activeBackground": "#3c5985",       // 深灰色
            "titleBar.activeForeground": "#fffb00",       // 橙黄色
            "titleBar.inactiveBackground": "#008000",     // 绿色
            "titleBar.inactiveForeground": "#FF8C00"      // 橙色
        }

    4自动补全头文件

    1 自动补全头文件
    
    
    001 按 Ctrl + Shift + P
    
    002 输入 Preferences: Configure User Snippets
    
    选择 python.json
    
    {
    	"Python File Header": {
    	  "prefix": "pyhd",
    	  "body": [
    		"# -*- coding: utf-8 -*-",
    		"\"\"\"",
    		"-------------------------------------------------",
    		"   File Name:     ${TM_FILENAME}",
    		"   Description :   $1",
    		"   Author :        Xiaoxing",
    		"   date:          ${CURRENT_YEAR}/${CURRENT_MONTH}/${CURRENT_DATE}  ${CURRENT_HOUR}:${CURRENT_MINUTE}:${CURRENT_SECOND}",
    		"-------------------------------------------------",
    		"\"\"\""
    	  ],
    	  "description": "Auto generate Python file header"
    	},
    
    	"a main guard": {
        "prefix": "main2",
        "body": [
          "if __name__ == '__main__':",
          "   pass"
        ],
        "description": "Insert Python main guard"
      }
    
    }

    5 实现 ctrl+d 复制本行到下一行

    按下 Ctrl + Shift + P 打开命令面板。
    输入并选择 Preferences: Open Keyboard Shortcuts (JSON)

    首选项:打开键盘快捷方式 (JSON)


    在打开的 keybindings.json 文件的中括号 [] 里,添加以下代码并保存:

    {
            "key": "ctrl+d",
            "command": "editor.action.copyLinesDownAction",
            "when": "editorTextFocus"
        }
  • AdGuard Home代理配置

    韩国代理

    [/openai.com/]168.126.63.1
    [/i.ytimg.com/]168.126.63.1
    [/yt3.ggpht.com/]168.126.63.1
    [/accounts.google.co.jp/]168.126.63.1
    [/www.google.co.kr/]168.126.63.1
    [/chatgpt.com/]168.126.63.1
    [/ab.chatgpt.com/]168.126.63.1
    [/google.com/]168.126.63.1
    [/facebook.com/]168.126.63.1
    [/www.facebook.com/]168.126.63.1
    [/youtube.com/]168.126.63.1
    [/google.com/]168.126.63.1
    [/www.google.com/]168.126.63.1
    [/gmail.com/]168.126.63.1
    [/docs.google.com/]168.126.63.1
    [/drive.google.com/]168.126.63.1
    [/outlook.com/]168.126.63.1
    [/office.com/]168.126.63.1
    [/microsoft.com/]168.126.63.1
    [/live.com/]168.126.63.1
    [/fb.com/]168.126.63.1
    [/twitter.com/]168.126.63.1
    [/instagram.com/]168.126.63.1
    [/linkedin.com/]168.126.63.1
    [/tiktok.com/]168.126.63.1
    [/netflix.com/]168.126.63.1
    [/spotify.com/]168.126.63.1
    [/soundcloud.com/]168.126.63.1
    [/vimeo.com/]168.126.63.1
    [/github.com/]168.126.63.1
    [/www.github.com/]168.126.63.1
    [/gitlab.com/]168.126.63.1
    [/bitbucket.org/]168.126.63.1
    [/stackoverflow.com/]168.126.63.1
    [/npmjs.com/]168.126.63.1
    [/docker.com/]168.126.63.1
    [/nodejs.org/]168.126.63.1
    [/python.org/]168.126.63.1
    [/openai.com/]168.126.63.1
    [/chat.openai.com/]168.126.63.1
    [/aws.amazon.com/]168.126.63.1
    [/amazon.com/]168.126.63.1
    [/googleapis.com/]168.126.63.1
    [/cloudflare.com/]168.126.63.1
    [/cloud.google.com/]168.126.63.1
    [/adobe.com/]168.126.63.1
    [/paypal.com/]168.126.63.1
    [/ebay.com/]168.126.63.1
    211.140.13.188
    223.5.5.5
    114.114.114.114

    硅谷代理

    [/openai.com/]8.8.8.8
    [/i.ytimg.com/]8.8.8.8
    [/yt3.ggpht.com/]8.8.8.8
    [/accounts.google.co.jp/]8.8.8.8
    [/www.google.co.kr/]8.8.8.8
    [/chatgpt.com/]8.8.8.8
    [/ab.chatgpt.com/]8.8.8.8
    [/google.com/]8.8.8.8
    [/facebook.com/]8.8.8.8
    [/www.facebook.com/]8.8.8.8
    [/youtube.com/]8.8.8.8
    [/google.com/]8.8.8.8
    [/www.google.com/]8.8.8.8
    [/gmail.com/]8.8.8.8
    [/docs.google.com/]8.8.8.8
    [/drive.google.com/]8.8.8.8
    [/outlook.com/]8.8.8.8
    [/office.com/]8.8.8.8
    [/microsoft.com/]8.8.8.8
    [/live.com/]8.8.8.8
    [/fb.com/]8.8.8.8
    [/twitter.com/]8.8.8.8
    [/instagram.com/]8.8.8.8
    [/linkedin.com/]8.8.8.8
    [/tiktok.com/]8.8.8.8
    [/netflix.com/]8.8.8.8
    [/spotify.com/]8.8.8.8
    [/soundcloud.com/]8.8.8.8
    [/vimeo.com/]8.8.8.8
    [/github.com/]8.8.8.8
    [/www.github.com/]8.8.8.8
    [/gitlab.com/]8.8.8.8
    [/bitbucket.org/]8.8.8.8
    [/stackoverflow.com/]8.8.8.8
    [/npmjs.com/]8.8.8.8
    [/docker.com/]8.8.8.8
    [/nodejs.org/]8.8.8.8
    [/python.org/]8.8.8.8
    [/openai.com/]8.8.8.8
    [/chat.openai.com/]8.8.8.8
    [/aws.amazon.com/]8.8.8.8
    [/amazon.com/]8.8.8.8
    [/googleapis.com/]8.8.8.8
    [/cloudflare.com/]8.8.8.8
    [/cloud.google.com/]8.8.8.8
    [/adobe.com/]8.8.8.8
    [/paypal.com/]8.8.8.8
    [/ebay.com/]8.8.8.8
    211.140.13.188
    223.5.5.5
    114.114.114.114
    

    刷新dns缓存

    ipconfig /flushdns
  • Ubuntu 24快速搭建wireguard

    curl -O https://raw.githubusercontent.com/angristan/wireguard-install/master/wireguard-install.sh
    chmod +x wireguard-install.sh
    sudo ./wireguard-install.sh
    
    一键搭建脚本  一路ok  即可

    下载 wireguard 软件

    https://www.wireguard.com/install/
    建议选择msi
    https://download.wireguard.com/windows-client/
    找到
    wireguard-installer.exe 下载
    
    配置  客户端
    
    /home/ubuntu/wg0-client-xiao2.conf
    
    创建新用户  选择1
    
    sudo ./wireguard-install.sh 
    Welcome to WireGuard-install!
    The git repository is available at: https://github.com/angristan/wireguard-install
    
    It looks like WireGuard is already installed.
    
    What do you want to do?
       1) Add a new user
       2) List all users
       3) Revoke existing user
       4) Uninstall WireGuard
       5) Exit
    Select an option [1-5]: 
    
    填入名字
    
    
    
    配置 国内  AllowedIPs
    AllowedIPs = 0.0.0.0/8, 1.1.1.1/32, 2.0.0.0/8, 4.0.0.0/8, 5.0.0.0/8, 6.0.0.0/8, 8.8.8.8/32, 9.0.0.0/8, 12.0.0.0/8, 13.0.0.0/8, 15.0.0.0/8, 16.0.0.0/8, 17.0.0.0/8, 18.0.0.0/8, 20.0.0.0/8, 23.0.0.0/8, 24.0.0.0/8, 26.0.0.0/8, 28.0.0.0/8, 31.13.0.0/16, 32.0.0.0/8, 37.0.0.0/8, 38.0.0.0/8, 40.0.0.0/8, 41.0.0.0/8, 44.0.0.0/8, 46.0.0.0/8, 48.0.0.0/8, 50.0.0.0/8, 52.0.0.0/8, 53.0.0.0/8, 54.0.0.0/8, 55.0.0.0/8, 56.0.0.0/8, 57.0.0.0/8, 62.0.0.0/8, 63.0.0.0/8, 64.0.0.0/8, 65.0.0.0/8, 67.0.0.0/8, 68.0.0.0/8, 69.0.0.0/8, 70.0.0.0/8, 71.0.0.0/8, 72.0.0.0/8, 73.0.0.0/8, 74.0.0.0/8, 76.0.0.0/8, 80.0.0.0/8, 81.0.0.0/8, 82.0.0.0/8, 83.0.0.0/8, 84.0.0.0/8, 86.0.0.0/8, 87.0.0.0/8, 88.0.0.0/8, 92.0.0.0/8, 93.0.0.0/8, 94.0.0.0/8, 95.0.0.0/8, 96.0.0.0/8, 100.0.0.0/8, 102.0.0.0/8, 104.0.0.0/8, 105.0.0.0/8, 107.0.0.0/8, 108.0.0.0/8, 109.0.0.0/8, 128.0.0.0/8, 129.0.0.0/8, 130.0.0.0/8, 131.0.0.0/8, 132.0.0.0/8, 133.0.0.0/8, 134.0.0.0/8, 135.0.0.0/8, 136.0.0.0/8, 137.0.0.0/8, 138.0.0.0/8, 139.0.0.0/8, 141.0.0.0/8, 142.0.0.0/8, 143.0.0.0/8, 144.0.0.0/8, 145.0.0.0/8, 146.0.0.0/8, 147.0.0.0/8, 148.0.0.0/8, 149.0.0.0/8, 150.0.0.0/8, 151.0.0.0/8, 152.0.0.0/8, 153.0.0.0/8, 154.0.0.0/8, 155.0.0.0/8, 156.0.0.0/8, 157.0.0.0/8, 158.0.0.0/8, 159.0.0.0/8, 160.0.0.0/8, 161.0.0.0/8, 162.0.0.0/8, 163.0.0.0/8, 164.0.0.0/8, 165.0.0.0/8, 166.0.0.0/8, 167.0.0.0/8, 168.0.0.0/8, 169.0.0.0/8, 170.0.0.0/8, 171.0.0.0/8, 172.0.0.0/8, 173.0.0.0/8, 174.0.0.0/8, 175.0.0.0/8, 176.0.0.0/8, 180.0.0.0/8, 181.0.0.0/8, 182.0.0.0/8, 184.0.0.0/8, 185.60.0.0/16, 188.0.0.0/8, 189.0.0.0/8, 190.0.0.0/8, 193.0.0.0/8, 194.0.0.0/8, 195.0.0.0/8, 196.0.0.0/8, 198.0.0.0/8, 199.0.0.0/8, 200.0.0.0/8, 204.0.0.0/8, 205.0.0.0/8, 206.0.0.0/8, 208.0.0.0/8, 212.0.0.0/8, 213.0.0.0/8, 214.0.0.0/8, 216.0.0.0/8, 224.0.0.0/8
    
    
    注意 Endpoint = 111.222.111.222:62986
    写入公网ip 否则无法上网
    
    
    代理走国内配置dns
    
    下载  AdGuardHome_windows_amd64.zip
    github地址
    https://github.com/AdguardTeam/AdGuardHome/releases
    
    解压后双击打开  AdGuardHome.exe
    
    本地地址
    http://127.0.0.1:3000   后面设置完 可能改为 http://127.0.0.1:80  了
    
    
    
    设置监听地址  选择本地lookback  地址  
    DNS server:
    127.0.0.1:53
    
    
    设置  -->   dns设置
    
    上游dns设置
    国外使用8.8.8.8  其他默认使用国内的
    
    [/openai.com/]8.8.8.8
    [/chatgpt.com/]8.8.8.8
    [/google.com/]8.8.8.8
    [/cursor.com/]8.8.8.8
    [/facebook.com/]8.8.8.8
    [/youtube.com/]8.8.8.8
    [/google.com/]8.8.8.8
    [/gmail.com/]8.8.8.8
    [/docs.google.com/]8.8.8.8
    [/drive.google.com/]8.8.8.8
    [/outlook.com/]8.8.8.8
    [/office.com/]8.8.8.8
    [/microsoft.com/]8.8.8.8
    [/live.com/]8.8.8.8
    [/fb.com/]8.8.8.8
    [/twitter.com/]8.8.8.8
    [/instagram.com/]8.8.8.8
    [/linkedin.com/]8.8.8.8
    [/tiktok.com/]8.8.8.8
    [/netflix.com/]8.8.8.8
    [/spotify.com/]8.8.8.8
    [/soundcloud.com/]8.8.8.8
    [/vimeo.com/]8.8.8.8
    [/github.com/]8.8.8.8
    [/gitlab.com/]8.8.8.8
    [/bitbucket.org/]8.8.8.8
    [/stackoverflow.com/]8.8.8.8
    [/npmjs.com/]8.8.8.8
    [/docker.com/]8.8.8.8
    [/nodejs.org/]8.8.8.8
    [/python.org/]8.8.8.8
    [/openai.com/]8.8.8.8
    [/chat.openai.com/]8.8.8.8
    [/aws.amazon.com/]8.8.8.8
    [/amazon.com/]8.8.8.8
    [/googleapis.com/]8.8.8.8
    [/cloudflare.com/]8.8.8.8
    [/cloud.google.com/]8.8.8.8
    [/adobe.com/]8.8.8.8
    [/paypal.com/]8.8.8.8
    [/ebay.com/]8.8.8.8
    211.140.13.188
    223.5.5.5
    
    选择最快的ip地址
    应用
    
    DNS 缓存配置
    启用
    覆盖最小 TTL 值
    600
    覆盖最大 TTL 值
    86400
    保存
    
    
    
    然后配置  wireguard  
    DNS = 127.0.0.1
    
    
    测试是否成功  这样就对了
    
    nslookup google.com
    服务器:  activate.navicat.com
    Address:  127.0.0.1
    
    非权威应答:
    名称:    google.com
    Addresses:  2404:6800:4012:8::200e
              142.251.218.174
    
    
    
    设置AdGuardHome  自启动  为服务程序
    在安装目录右键  打开终端 powershell
    .\AdGuardHome.exe -s install   安装服务  设置为自动
    .\AdGuardHome.exe -s start   启动服务
    
    
  • Windows安装Redis

    安装Redis-x64-5.0.14.1.msi

    配置文件设置

    找到 安装目录下的 redis.windows-service.conf

    #修改最大内存

    maxmemory 4gb

    #设置出错时允许写入 避免一些报错

    stop-writes-on-bgsave-error no

    #设置端口号

    port 6379

    #设置允许内网和本地访问redis(以空格隔开可以多个)

    bind 192.168.1.150 127.0.0.1

    #设置redis密码

    requirepass your_strong_password

  • Windows定时任务报错原因

    终端程序 对于有空格的需要加上引号 否则报错
    “C:\Program Files\WindowsApps\Microsoft.WindowsTerminal_1.22.11141.0_x64__8wekyb3d8bbwe\wt.exe”

    运行参数
    -w 0 nt -p “PowerShell” “C:\Users\Administrator\Desktop\fsdownload\venv\Scripts\python.exe” “C:\Users\Administrator\PycharmProjects\pythonProject2\新脚本\ttt.py”

  • git常用命令

    git常用命令

    # 查看提交历史,找到要回退的commit hash

    git log –oneline

    恢复到以前的某个版本

    git reset –hard 93424a2

    # 强制推送,会覆盖远程的提交历史(之前的一些提交)

    git push –force origin master

    强制拉取远程 覆盖本地

    git pull –force origin master

    丢弃所有未提交的修改,回到最近一次提交的状态

    git reset –hard HEAD

    查看分支

    git branch

    切换分支

    git checkout feature-xc

    验证结果

    git branch

    # 查看当前状态

    git status

    ————文件冲突 checkout 文件名 进行覆盖 ——–

    # 方法 A:直接 checkout 覆盖(保留文件但内容变回远程版本)

    git checkout HEAD — .env

    git pull origin master

    —————– 如何忽略文件———–

    git rm –cached .env

    . 确保 .gitignore 已包含 .env

    提交本次修改

    git add .gitignore

    git commit -m “停止监控并忽略 .env文件”

    git push origin master

  • windows镜像下载地址

    server 2025

    server 2022

    win11 24H2

    • ed2k://|file|zh-cn_windows_11_business_editions_version_24h2_updated_aug_2025_x64_dvd_08e70c15.iso|7260784640|46437315738020E5643BF5139395B704|/

    win11 21H2

    • ed2k://|file|zh-cn_windows_11_business_editions_version_21h2_updated_aug_2022_x64_dvd_01ab3d1a.iso|5773361152|E2E979BB3A24CFF03011C6888D4F3C8E|/

    win11 22H2

    • ed2k://|file|zh-cn_windows_11_business_editions_version_22h2_updated_oct_2023_x64_dvd_370ed1b7.iso|6615459840|8F46CEFA55F43404535AF960B4784E67|/

    win11 23H2

    • ed2k://|file|zh-cn_windows_11_business_editions_version_23h2_updated_sep_2024_x64_dvd_22316bf2.iso|7094269952|9437FD5D778E65B27176BA17CF40BC32|/

    win11 LTSC

    • ed2k://|file|zh-cn_windows_11_enterprise_ltsc_2024_x64_dvd_cff9cd2d.iso|5287520256|D6E4FE0BA5FD8A2F22FC9C0326481791|/

    win7

    • ed2k://|file|cn_windows_7_ultimate_with_sp1_x64_dvd_u_677408.iso|3420557312|B58548681854236C7939003B583A8078|/

    win7 英文版

    • ed2k://|file|7601.24214.180801-1700.win7sp1_ldr_escrow_CLIENT_ULTIMATE_x64FRE_en-us.iso|5876357120|9C55A020B327AD60CB8A37D0317743F2|/

    xp

    • ed2k://|file|zh-hans_windows_xp_professional_with_service_pack_3_x86_cd_x14-80404.iso|630239232|CD0900AFA058ACB6345761969CBCBFF4|/

    win10 LTSC 2021

    • ed2k://|file|SW_DVD9_WIN_ENT_LTSC_2021_64BIT_ChnSimp_MLF_X22-84402.ISO|5044211712|1555B7DCA052B5958EE68DB58A42408D|/

    win10 LTSB 2016

    ed2k://|file|cn_windows_10_enterprise_2016_ltsb_x64_dvd_9060409.iso|3821895680|FF17FF2D5919E3A560151BBC11C399D1|/

    win10 1909

    • magnet:?xt=urn:btih:CACC1E9EEC070BE56F939863E189EAE3116F98E4&dn=cn_windows_10_business_editions_version_1909_updated_april_2020_x64_dvd_5d3fcf2e.iso&xl=5420953600

    win10 21h2

    • ed2k://|file|zh-cn_windows_10_business_editions_version_21h2_updated_june_2023_x64_dvd_74594186.iso|5992781824|8330E81B21382B195F86EE4CED2320D8|/

    win10 22h2

    • ed2k://|file|zh-cn_windows_10_business_editions_version_22h2_updated_aug_2025_x64_dvd_b6baaad4.iso|6802696192|5D326D747342928B5E5949993FB43249|/

    2016长期版本 32位

    • ed2k://|file|cn_windows_10_enterprise_2016_ltsb_x86_dvd_9057089.iso|2817034240|67C3865D03E765BDD4845BA2CB7649F8|/

    2016长期版本 64位

    • ed2k://|file|cn_windows_10_enterprise_2016_ltsb_x64_dvd_9060409.iso|3821895680|FF17FF2D5919E3A560151BBC11C399D1|/