Mac 安装 mysqlclient

Python 版本 (venv) ➜ python --version Python 3.8.2 安装 brew install mysql export LDFLAGS="-L/usr/local/opt/openssl/lib" export CPPFLAGS="-I/usr/local/opt/openssl/include" pip install mysqlclient brew uninstall mysql ……

阅读全文

常用 git 命令

git log -p | grep 'xxx' -B 300 // 查询修改历史 git push origin branch_name // 推送 git commit -m "commit_message" // 提交 commit git add -A . // add 文件 ……

阅读全文

Python 中的else

if…else 最常见的 else if 1 > 0: pass else: pass for else for 循环中 只有 for 循环结束了才执行, 注意空循环也会执行 for i in range(3): print(i) else: print("end") # 0 # 1 # 2 # end for i in range(3): print(i) if i == 1: break else: print("end") # 0 # 1 try… else 这个就很好理解了, else 只会在 try 未发生任何异常的时候执行 finally 在所有状态下都会执行 try: 1 except Exception as e: print(e) else: print("else") finally: print("finally") # else # finally try: 1/0 except Exception as e: print(e) else: print("else") finally: print("finally") # division by zero # finally ……

阅读全文

二叉树

二叉树 本文摘自 代码随想录 定义 满二叉树 除最后一层无任何子节点外,每一层上的所有结点都有两个子结点的二叉树。 国内教程定义:一个二叉树,如果每一个层的结点数都达到最大值,则这个二叉树就是满二叉树。也就是说,如果一个二叉树的层数为K,且结点总数是(2^k) -1 ,则它就是满二叉树。 满二叉树的结点要么是叶子结点,度为0,要么是度为2的结点,不存在度为1的结点。 但是, 下图根据国内定义就不是一个满二叉树 满二叉树 百度百科 完全二叉树 一棵深度为k的有n个结点的二叉树,对树中的结点按从上至下、从左到右的顺序进行编号,如果编号为i(1≤i≤n)的结点与满二叉树中编号为i的结点在二叉树中的位置相同,则这棵二叉树称为完全二叉树 完全二叉树 二叉搜索树 一个有序树 若它的左子树不空,则左子树上所有结点的值均小于它的根结点的值; 若它的右子树不空,则右子树上所有结点的值均大于它的根结点的值; 它的左、右子树也分别为二叉排序树 平衡二叉搜索树 AVL (Adelson-Velsky and Landis) 空树 左右两个子树高度绝对值不超过1 (<=1), 并且两个子树都是 AVL 存储方式 顺序, 数组 链式, 指针方式 链式: 顺序: 遍历 如果父节点的数组下表是i,那么它的左孩子就是i * 2 + 1,右孩子就是 i * 2 + 2。 注意: 常用的还是链式……

阅读全文

数据库跟 null 比较会得到非预期结果

现象 在执行 sql 中得到了非预期结果 select * from user where age > 20; 其中, 数据库中存在大量的 age 为 null 的记录, 在执行完上述 sql 后, 没有将 age is null 的数据查出 测试 SELECT 1>=1, NULL = NULL, Null > 1; mysql 5.7.21-log sqlite 3.34.0 postgresql PostgreSQL 14.0 (Debian 14.0-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit 原因 stackoverflow 在 The Three-Valued Logic of SQL 中规定, 与 null 比较返回值为 null The SQL null value basically means “could be anything”.……

阅读全文

Vaultwarden 搭建

准备 docker nginx/caddy 启动 docker run -d --name vaultwarden -v `pwd`:/data -p 8088:80 vaultwarden/server:latest 此时打开 http://yourhost:8088, 就可以看到页面 配置 在工作目录(即上述执行的目录, 如果 -v 指定了目录, 则为其指定目录)中, 增加一个 config.json 其中 signups_allowed 为是否允许注册, 注册完第一个账号之后建议关闭 admin_token 为 /admin 管理页面的 token, 建议配置完之后将其置空(即不开启 /admin) { "domain": "http://localhost", "sends_allowed": false, "disable_icon_download": false, "signups_allowed": true, "signups_verify": false, "signups_verify_resend_time": 3600, "signups_verify_resend_limit": 6, "invitations_allowed": false, "password_iterations": 100000, "show_password_hint": false, "admin_token": "token", "invitation_org_name": "Vaultwarden", "ip_header": "X-Real-IP", "icon_cache_ttl": 2592000, "icon_cache_negttl": 259200, "icon_download_timeout": 10, "icon_blacklist_non_global_ips": true, "disable_2fa_remember": false, "authenticator_disable_time_drift": false, "require_device_email": false, "reload_templates": false, "log_timestamp_format": "%Y-%m-%d %H:%M:%S.……

阅读全文

博客搭建

准备 hugo github nginx/caddy hugo 注意: 安装 extended 版本, 否则使用第三方主题时会有问题 hugo new site quickstart cd quickstart git clone https://github.com/flysnow-org/maupassant-hugo themes/maupassant echo theme = \"maupassant\" >> config.toml hugo new posts/my-first-post.md // 测试 hugo server -D // 生成静态文件 hugo -D github 创建 repo 设置 webhook 将上面的 quickstart 文件夹整体进行版本管理(其实只管理 content 也行, 要是为了方便换主题, 可以直接搞整个) 在 server 上启动 webhook server eg. package main import ( "crypto/hmac" "crypto/sha1" "encoding/hex" "fmt" "io/ioutil" "net/http" "os/exec" ) var ( key []byte ) func sha1Data(data []byte) string { h := hmac.……

阅读全文

python 异常处理

异常处理 def demo(): try: 1 / 0 except Exception as e: print(type(e)) #<class 'ZeroDivisionError'> 自定义异常 class CustomError(Exception): pass 异常链 class CustomError(Exception): pass def demo(): try: 1 / 0 except Exception as e: print(type(e)) #<class 'ZeroDivisionError'> raise CustomError() from e <class 'ZeroDivisionError'> Traceback (most recent call last): File "/Users/tiger/work/customer/dd.py", line 23, in demo 1 / 0 ZeroDivisionError: division by zero The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/Users/tiger/work/customer/dd.……

阅读全文