Hugo Part 3: Auto Renew Certificate

󰃭 2025-03-20 | #Automation #HTTPS #Hugo

For servers that completely block port 80 for security requirements, we need to temporarily open port 80 when renewing Let’s Encrypt certificates. Here’s an automated solution using systemd timer and AWS CLI (Assume you already configured it). Create the renewal script: #!/bin/bash # /usr/local/bin/certbot-renew-with-sg.sh SG_ID="sg-CAFEBABE7355608" RULE_DESCRIPTION="Temporary HTTP for LetsEncrypt" add_sg_rule() { aws ec2 authorize-security-group-ingress \ --group-id $SG_ID \ --protocol tcp \ --port 80 \ --cidr 0.0.0.0/0 \ --description "$RULE_DESCRIPTION" sleep 10 } remove_sg_rule() { aws ec2 revoke-security-group-ingress \ --group-id $SG_ID \ --protocol tcp \ --port 80 \ --cidr 0.

Continue reading 


因为懒得写引用传递

󰃭 2025-02-17 | #bar #foo

起因:懒得写递归函数并手动传参 今天刷 LeetCode 时又遇到了 DFS 等递归函数时,因为懒得显式定义递归函数并传递引用参数,尝试直接用 lambda 来写递归逻辑。 第一次尝试:auto 推断递归 lambda vector<vector<int>> graph = {{1, 2}, {3}, {3}, {}}; vector<bool> visited(4, false); auto dfs = [&](int u) { visited[u] = true; for (auto v : graph[u]) { // error: variable 'dfs' declared with deduced type 'auto' cannot appear in its own initializer if (!visited[v]) dfs(v); } }; dfs(0); lambda 表达式的类型是编译器生成的匿名闭包类型,而 auto 推断的类型需要在编译期确定。而在 auto 推断时,dfs 需要引用自己,但它自身的类型尚未推断完成,因此无法通过编译。 第二次尝试:使用 std::function 为了解决这个问题,引入 std::function: vector<vector<int>> graph = {{1, 2}, {3}, {3}, {}}; vector<bool> visited(4, false); function<void(int)> dfs = [&](int u) { visited[u] = true; for (auto v : graph[u]) { if (!

Continue reading 