AWS 在本地配置AWS资源访问授权

如果本地安装了 AWS CLI 可以直接使用 aws 命令进行配置:
aws configure

或者,可以手动创建证书文件,文件默认位置是 ~/.aws/credentials

文件内容:

[default]
aws_access_key_id=YOUR_ACCESS_KEY
aws_secret_access_key=YOUR_SECRET_KEY

如果要设置默认地区(Regoin),示例:

BeautifulSoup 获取DOM元素的文本

举例:

from bs4 import BeautifulSoup

html="""<div>Hello<br>
<br> World!</div>""" # 示例HTML

soup = BeautifulSoup(html, 'html.parser')
elem = soup.select_one('div')

纯文本。
旧版。只是去除了 HTML tag,留下了空白字符,包括换行符。
新版。去除了 HTML tag 、换行、多余的空白字符。

print(elem.get_text())
# 输出:
'''
Hello
 World!
'''

elem.stripped_strings 以迭代方式返回每个HTML tag 间的文本,但会过滤掉多余的空白字符。

Homebrew update 失败,报错 homebrew-core is a shallow clone

发生环境:macOS V11.1 (Big Sur)

发生的问题:brew update 时报错,

Error: 
  homebrew-core is a shallow clone.
  homebrew-cask is a shallow clone.
To `brew update`, first run:
  git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
  git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow
This restriction has been made on GitHub's request because updating shallow
clones is an extremely expensive operation due to the tree layout and traffic of
Homebrew/homebrew-core and Homebrew/homebrew-cask. We don't do this for you
automatically to avoid repeatedly performing an expensive unshallow operation in
CI systems (which should instead be fixed to not use shallow clones). Sorry for
the inconvenience!
...

按照提示执行git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow,而往往等待很久后,还总是失败。
报错内容类似:
fatal: unable to access 'https://github.com/Homebrew/homebrew-core.git/': transfer closed with outstanding read data remaining

解决 Homebrew 卡顿和下载速度慢的问题

1,执行 brew 命令时,卡在 Updating Homebrew...
这是在检查和更新 brew 自身无法连接到仓库源。

2,安装软件包时下载速度缓慢
同上。

先执行命令 brew doctor,根据提示修复问题。

通常是由于国内网络问题导致,可以将 homebew 的仓库源改成国内镜像源来解决此问题。
参见 Homebrew 修改和复原仓库源

Liquid sort 排序

{{ my_array | sort }}
{{ my_array | sort | reverse }}

例如在 Jekyll 中按文章的日期排序

{% assign sorted_posts = site.posts | sort:"date" %}

如何激活与退出 Python 虚拟环境

如何激活/启动已创建的 Python 虚拟运行环境?macOS 和 Windows 下略有不同。以及如何退出虚拟环境。

假设虚拟环境的目录是:.env

  • macOS/Linux 下激活虚拟环境
    命令行:source .env/bin/activate

    成功激活独立环境,命令行前会多出字符:(.env)

一键混淆加密 Excel VBA 宏代码

有时我们希望加密自己写的VBA代码,保护自己的劳动成功不被窃取。
对代码进行混淆虽然保护程度有限,但是一种容易实现和容易使用的方式。 尤其对于 Excel 宏来说不能编译,只能用源码。