Posted in: Python

python按照固定长度分割字符串

按照固定长度分割字符串在很多地方都要用到(例如输出FASTA格式的文件)。去网上搜发现真是令人无语。最后发现python官网的方案最简单:

import textwrap
str = '123456789abcdefg'
print(*textwrap.wrap(str, width=5), sep='\n')

输出结果:

12345
6789a
bcdef
g


最后更新于 2022 年 11 月 3 日 作者 springwood

Posted in: Mobile/iOS

植物大战僵尸

这个游戏(PVZ1)在十几年前我上大学时在电脑上玩的初代。

后来出来了第二代(PVZ2),但mobile only,那时我还没有智能手机,只能眼巴巴地看着别人玩。后来有了智能手机,玩了几次,直觉是:好难!另外还有很多奇怪的按钮,一不小心就点到付费。

去年在iPhone上又玩了一次PVZ2,还是好难!于是想去看看PVZ1,然后发现了一个悲剧:PVZ1虽然有个Mac移植版,但由于是32bit only,无法运行于MacOS10.15了。

于是乎最后,用美区Apple ID下载PVZ1成了最接近原生体验且最清爽的方式。至于电脑上么?目测等以后买了M1 Macbook之后在MacOS上运行 iOS PVZ1吧。

附两个秘籍:

(1)巧用iOS PVZ1内购bug,可以购入大量金币,也可以内购去广告,基本原理是点击购买后快速退出app(在全面屏iPhone里面操作需要有点技巧)

(2)Endless Mode本次尝试不用大炮的模式试试。(即使是iPhone12PM那种大屏,在屏幕上点炮也太麻烦了)


最后更新于 2020 年 12 月 31 日 作者 springwood

Posted in: IT, Website/Blog

利用 certbot 给Let’s Encrypt SSL 续期的两种方法

国内主机:推荐 DNS 法来手动续期

国内主机由于对Let’s Encrypt官网连接经常出现问题,因此推荐 DNS 法手动续期。特别是默认的 certbot renew 命令很容易由于网络连接问题导致失败,此时千万不要反复尝试,否则失败多次后直接封你一个星期没商量。惨痛教训。 😥

DNS验证是比较安全的方法,具体参考这篇文章。在此备份一下命令:

# certbot --manual --preferred-challenges dns certonly

然后有两个地方需要注意的,文章没提到:

第一:添加DNS时千万要仔细看清楚域名写的是什么,不是简单一个_acme-challenge 就完事了,因为可能有子域名。

第二:成功之后最好重启一下httpd服务。

这种方法每三个月都得手动操作一次,不能自动

国外主机:推荐 snap 自动续期

snap 的官方全文在此处。其实也没什么特殊的,事实上就是它自动帮你安装了一个list-timers脚本,无需手动去设置cron。

webroot 的坑

官方原文里讲了standalone和webroot两种模式,什么区别呢?比如我的博客 URL 是 https://springwood.me ,用的443端口,不需要80端口。但实际上我必须得用80端口来承接 http://springwood.me,然后重定向到 443 的 https,这种情况下就不能使用standalone模式了,要用webroot。

官方原文里有一个没有提到的坑是:用 --webroot 时必须用 -w 加上具体的目录名字,例如:

# certbot certonly --webroot -w /var/www/html

这里的 /var/www/html/ 是你的域名对应的根目录

然后去看一下 /etc/letsencrypt/renewal/yourdomain.com.conf,最后几行应该是:

[renewalparams]
account = XXXXXXXX
authenticator = webroot
server = https://acme-v02.api.letsencrypt.org/directory
key_type = rsa
webroot_path = /var/www/html,
[[webroot_map]]

这样就对了。

此时可以 certbot renew --dry-run尝试一下。

如果最开始用 --webroot 时没有用 -w 加上具体的目录名字, certbot renew --dry-run就会出现如下错误:

Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/yourdomain.com.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Simulating renewal of an existing certificate for yourdomain.com
Failed to renew certificate yourdomain.com with error: Missing command line flag or config entry for this setting:
Input the webroot for yourdomain.com:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
All simulated renewals failed. The following certificates could not be renewed:
  /etc/letsencrypt/live/yourdomain.com/fullchain.pem (failure)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1 renew failure(s), 0 parse failure(s)
Ask for help or search for solutions at https://community.letsencrypt.org. See the logfile /var/log/letsencrypt/letsencrypt.log or re-run Certbot with -v for more details.

刚才在这坑里折腾了很久。


最后更新于 2022 年 11 月 4 日 作者 springwood

Back to Top