GitHub 获得项目中每种编程语言占比
首先使用 GitHub API 获得项目中每种语言的代码行数,
API: https://api.github.com/repos/<user/repo>/languages
,替换其中的 <user/repo>
。
例如 curl https://api.github.com/repos/cli/cli/languages
,
返回的结果示例:
首先使用 GitHub API 获得项目中每种语言的代码行数,
API: https://api.github.com/repos/<user/repo>/languages
,替换其中的 <user/repo>
。
例如 curl https://api.github.com/repos/cli/cli/languages
,
返回的结果示例:
Use PDM to export Python project dependencies to requirements.txt file.
pdm export --pyproject > requirements.txt
or
pdm export --pyproject -o requirements.txt
Export lockfile
pdm export > requirements.lock
Amplify 自动部署 Hugo 项目在构建前端环节失败,报错某个模板时解析失败。类似:
[WARNING]: Error: add site dependencies: load resources: loading templates: ".../layouts/partials/meta/author.html:9:1": parse failed: template: partials/meta/author.html:9: unclosed action
[ERROR]: !!! Build failed
[ERROR]: !!! Non-Zero Exit Code detected
首先的确是模板文件有语法错误,将其纠正。
仍然报告此错误,且本地使用 Hugo 创建完全正常。可能是 Amlify 使用的 Hugo 版本有 Bug,
使用 Array.prototype.join()
以下内容参考 MDN web docs
join()
方法将数组中所有元素成一个新的字符串并返回。默认使用逗号作为分隔符或使用指定的分隔字符。
语法:
Array.join( )
Array.join(separator)
举例:
// Code copied from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join
const elements = ['Fire', 'Air', 'Water'];
console.log(elements.join());
// expected output: "Fire,Air,Water"
console.log(elements.join(''));
// expected output: "FireAirWater"
console.log(elements.join('-'));
// expected output: "Fire-Air-Water"
使用 curl 通过 post 方法提交 json 格式的数据:
curl --request POST \
--header "Content-Type: application/json" \
--data '{"foo":"bar","num":1}' \
http://localhost:3000/path/
参数说明:
--request POST
, 可选。当使用 --data
选项时,默认就是 post 方法
How to convert MP3 to OGG audio format?
ffmpeg -i in.mp3 -ar 48000 -vn -c:a libvorbis out.ogg
If you have sample rate errors, use -vn
.
References
使用 pexpect 库比较省心,使用方便。也不像使用 subprocess 会出现很多问题。
代码:
import pexpect
def execute_cli_command(cmd: str) -> str:
"""return stdout:str"""
(command_output, exitstatus) = pexpect.run(cmd, withexitstatus=1)
command_output = command_output.decode("utf-8")
if exitstatus != 0:
raise Exception(exitstatus, command_output)
return command_output
假设要将 main
分支完全替换成 dev
分支的内容(即用 dev
分支内容覆盖 main
分支内容):
git checkout dev
git merge -s ours main
git checkout main
git merge dev
命令说明:
git checkout dev
:将当前工作目录切换到 dev 分支。git merge -s ours main
:将 main 分支合并到当前的 dev 分支,使用 -s ours
选项告诉 Git 在合并冲突时,总是选择当前分支( dev 分支)的版本。git checkout main
:将当前工作目录切换回 main 分支。git merge dev
:将 dev 分支合并到 main 分支。此后 main 分支的内容和 dev 分支一样。参考链接:StackOverflow
CSS:
.container{
display: flex;
justify-content: center; //水平居中
align-items: center; //垂直居中
}
HTML:
<div class="container">
<div>居中元素</div>
</div>
tail -n 3 file
显示文件内容的最后3行
-n <行数>
显示文件的尾部 n 行内容tail 命令更多选项