mirror of
https://github.com/jaywcjlove/reference.git
synced 2025-08-23 22:56:13 +08:00
Compare commits
151 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
599215755f | ||
![]() |
bce9b67afb | ||
![]() |
50e82b11b6 | ||
![]() |
e36abdee8b | ||
![]() |
7fe648c170 | ||
![]() |
76e8c1bdc6 | ||
![]() |
9fe2674c6c | ||
![]() |
5c8b11767f | ||
![]() |
709aef66fb | ||
![]() |
13e67d63ac | ||
![]() |
f9a31e40ca | ||
![]() |
effa2500ed | ||
![]() |
1d1f8778dd | ||
![]() |
74afc52463 | ||
![]() |
d9ed56a390 | ||
![]() |
f9461ac0c3 | ||
![]() |
1bda7de8c4 | ||
![]() |
067e5d6d16 | ||
![]() |
76b1e5b41f | ||
![]() |
fe10fbe8bb | ||
![]() |
2c07547c83 | ||
![]() |
390eaa2e1b | ||
![]() |
d7688f90bb | ||
![]() |
38453c5e31 | ||
![]() |
fda783c165 | ||
![]() |
152dc14279 | ||
![]() |
e4d6ddecca | ||
![]() |
51bd7303d1 | ||
![]() |
7d26adb7a6 | ||
![]() |
769d75e8bf | ||
![]() |
7c6e2270b8 | ||
![]() |
db647aaf35 | ||
![]() |
fbbbd00a9c | ||
![]() |
6f7affffdd | ||
![]() |
464c49645d | ||
![]() |
c20d19c976 | ||
![]() |
0f199d2ff5 | ||
![]() |
57f25fc10a | ||
![]() |
d8a37d084f | ||
![]() |
03cc3cf5c3 | ||
![]() |
bf49b5f9a5 | ||
![]() |
adebf47812 | ||
![]() |
f5c9b232b5 | ||
![]() |
d6504023d5 | ||
![]() |
3bade1d5a5 | ||
![]() |
0ad14d89a0 | ||
![]() |
5ee649ae9b | ||
![]() |
ef680890ce | ||
![]() |
1fda256237 | ||
![]() |
f9ca460565 | ||
![]() |
8e265becb5 | ||
![]() |
e1639d0ce0 | ||
![]() |
f5f05aacf5 | ||
![]() |
90c80e720e | ||
![]() |
823b3163d4 | ||
![]() |
fe562e5fb1 | ||
![]() |
85c4149e1c | ||
![]() |
e849f19712 | ||
![]() |
71e5470efd | ||
![]() |
38d79cd2a0 | ||
![]() |
0e0eb9c628 | ||
![]() |
7b46142372 | ||
![]() |
41b42c17b7 | ||
![]() |
cfb0b98673 | ||
![]() |
8a9d9de14b | ||
![]() |
c2cb9fa3d7 | ||
![]() |
11edef0d1b | ||
![]() |
b13ca7ee0a | ||
![]() |
5f6029a051 | ||
![]() |
8592dff419 | ||
![]() |
bb817cbb40 | ||
![]() |
0bc31c68c3 | ||
![]() |
aab4d3bcff | ||
![]() |
a3ddc58b0a | ||
![]() |
c4398d5220 | ||
![]() |
ada64ac643 | ||
![]() |
84876edb2e | ||
![]() |
0c8dddf8e7 | ||
![]() |
edaf531b50 | ||
![]() |
2200972ce7 | ||
![]() |
aaa0f1f523 | ||
![]() |
465cdc7bc1 | ||
![]() |
c97f6a7bca | ||
![]() |
8f980a92c1 | ||
![]() |
4f0198877b | ||
![]() |
e0ccae5659 | ||
![]() |
c40b5ecb85 | ||
![]() |
9c3ad5a300 | ||
![]() |
3bac78a4d0 | ||
![]() |
9db2ce1974 | ||
![]() |
345bb9013d | ||
![]() |
4eedb2bcbe | ||
![]() |
63739bff97 | ||
![]() |
a4650ba20b | ||
![]() |
304fca65aa | ||
![]() |
7dab4bc821 | ||
![]() |
a3a03dc5cf | ||
![]() |
c4027826df | ||
![]() |
ec5de21ad8 | ||
![]() |
2d29bce40d | ||
![]() |
45916503c1 | ||
![]() |
7dab833cb5 | ||
![]() |
2787e80dd2 | ||
![]() |
51377308ab | ||
![]() |
5660ad20dd | ||
![]() |
0917f70be8 | ||
![]() |
dcbdaea754 | ||
![]() |
144f263ad0 | ||
![]() |
ef5a27f5a1 | ||
![]() |
82457e896e | ||
![]() |
d796def71c | ||
![]() |
8cb9a8eaa4 | ||
![]() |
739697937d | ||
![]() |
4ce6660ca8 | ||
![]() |
5677612d9d | ||
![]() |
6d24b1b957 | ||
![]() |
72d3bd8d42 | ||
![]() |
2d4a9604cf | ||
![]() |
7a22e7cda2 | ||
![]() |
85071d3204 | ||
![]() |
c4694ed832 | ||
![]() |
906cbdd152 | ||
![]() |
a38f6d8f85 | ||
![]() |
2037e0f6b9 | ||
![]() |
bb2cff4f9b | ||
![]() |
b3c47e2b2d | ||
![]() |
5701da6e5b | ||
![]() |
ea80136db3 | ||
![]() |
aa26be4186 | ||
![]() |
2b1d33a5db | ||
![]() |
dbf8ac4fb2 | ||
![]() |
f2f1ef8c52 | ||
![]() |
748ed480f4 | ||
![]() |
7c2338ea76 | ||
![]() |
90c9fefa51 | ||
![]() |
29f3b971d2 | ||
![]() |
b2aabe4291 | ||
![]() |
04e6e16a97 | ||
![]() |
3db12d6cce | ||
![]() |
3f0b60187c | ||
![]() |
bead2f0e3b | ||
![]() |
816f49004f | ||
![]() |
12b84b8368 | ||
![]() |
56b4b78d7d | ||
![]() |
f28c93b918 | ||
![]() |
0bfe15e4dc | ||
![]() |
c1394813bc | ||
![]() |
06c6229cac | ||
![]() |
04dd94d6f8 | ||
![]() |
5f19d3feee | ||
![]() |
e48fd74c38 |
@@ -4,6 +4,8 @@ docs
|
||||
scripts
|
||||
node_modules
|
||||
package-lock.json
|
||||
pnpm-lock.yaml
|
||||
yarn.lock
|
||||
|
||||
.DS_Store
|
||||
.cache
|
||||
|
7
.editorconfig
Normal file
7
.editorconfig
Normal file
@@ -0,0 +1,7 @@
|
||||
root = true
|
||||
|
||||
[./docs/*.md]
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
insert_final_newline = true
|
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.md linguist-detectable=true
|
18
.github/ISSUE_TEMPLATE/cheatsheet-request.md
vendored
18
.github/ISSUE_TEMPLATE/cheatsheet-request.md
vendored
@@ -6,13 +6,25 @@ labels: request
|
||||
assignees: jaywcjlove
|
||||
---
|
||||
|
||||
🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧
|
||||
注意:请求太多,参考【优先级】快速添加内容
|
||||
🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧
|
||||
|
||||
#### 优先级
|
||||
|
||||
- [ ] 提交 PR 优先合并(优先处理)
|
||||
- [ ] 提供可复制的[中文/英文]备忘清单资料,优先添加
|
||||
- [ ] 大众化的内容(java/python),优先搬运(小众内容请提供资料)
|
||||
|
||||
#### 说明项目
|
||||
|
||||
您可以在这里简单的提供一些资料,方便我们在 Quick Reference 中添加您想添加的备忘清单(速查表)。
|
||||
|
||||
【请您在这里介绍一下工具或者语言,这很重要】
|
||||
|
||||
- [ ] 如果你有一张不错的备忘清单(速查表) [`参考这里`](https://github.com/jaywcjlove/reference/blob/main/CONTRIBUTING.md) 为仓库贡献。
|
||||
- [ ] 如果您不方便贡献,请在下方参考资料中提供链接地址,方便共建备忘清单(速查表)
|
||||
- [x] 这里为您提供了 Markdown 排版[示例教程](https://jaywcjlove.github.io/reference/docs/quickreference.html)
|
||||
- 如果你有一张不错的备忘清单(速查表) [`参考这里`](https://github.com/jaywcjlove/reference/blob/main/CONTRIBUTING.md) 为仓库贡献。
|
||||
- 如果您不方便贡献,请在下方参考资料中提供链接地址,方便共建备忘清单(速查表)
|
||||
- 这里为您提供了 Markdown 排版[示例教程](https://jaywcjlove.github.io/reference/docs/quickreference.html)
|
||||
|
||||
#### 提供参考资料地址
|
||||
|
||||
|
15
.github/workflows/ci.yml
vendored
15
.github/workflows/ci.yml
vendored
@@ -18,11 +18,26 @@ jobs:
|
||||
|
||||
- name: Generate Contributors Images
|
||||
uses: jaywcjlove/github-action-contributors@main
|
||||
id: contributors
|
||||
with:
|
||||
filter-author: (renovate\[bot\]|renovate-bot|dependabot\[bot\])
|
||||
output: dist/CONTRIBUTORS.svg
|
||||
avatarSize: 42
|
||||
|
||||
- name: Modify CONTRIBUTING.md
|
||||
uses: jaywcjlove/github-action-modify-file-content@main
|
||||
with:
|
||||
path: CONTRIBUTING.md
|
||||
body: |
|
||||
${{steps.contributors.outputs.htmlList}}
|
||||
|
||||
- name: Modify README.md
|
||||
uses: jaywcjlove/github-action-modify-file-content@main
|
||||
with:
|
||||
path: README.md
|
||||
body: |
|
||||
${{steps.contributors.outputs.htmlList}}
|
||||
|
||||
- name: Create Tag
|
||||
id: create_tag
|
||||
uses: jaywcjlove/create-tag-action@main
|
||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@@ -2,6 +2,8 @@ build
|
||||
dist
|
||||
node_modules
|
||||
package-lock.json
|
||||
pnpm-lock.yaml
|
||||
yarn.lock
|
||||
|
||||
.DS_Store
|
||||
.cache
|
||||
|
@@ -1,3 +1,4 @@
|
||||
{
|
||||
"**/*.{mjs,css,json,prettierrc,lintstagedrc}": ["prettier --write"]
|
||||
"**/*.{mjs,css,json,prettierrc,lintstagedrc}": ["prettier --write"],
|
||||
"./docs/*.md": ["npx markdownlint-cli --fix ./docs"]
|
||||
}
|
||||
|
12
.markdownlint.json
Normal file
12
.markdownlint.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"MD003": false,
|
||||
"MD013": false,
|
||||
"MD014": false,
|
||||
"MD024": false,
|
||||
"MD033": false,
|
||||
"MD040": false,
|
||||
"MD010": {
|
||||
"code_blocks": true,
|
||||
"spaces_per_tab": 2
|
||||
}
|
||||
}
|
106
CONTRIBUTING.md
106
CONTRIBUTING.md
@@ -38,7 +38,7 @@ Contributing 贡献
|
||||
|
||||
## CSS 类注释
|
||||
|
||||
[`Quick Reference`](https://jaywcjlove.github.io/reference) 使用 [`@wcj/markdown-to-html`](https://github.com/jaywcjlove/markdown-to-html) 转换 `Markdown`,并使用 [`rehype-attr`](https://github.com/jaywcjlove/rehype-attr) 插件让其支持通过其注释语法添加类和样式。 此外,您可以在 Quick Reference 备忘清单上使用样式参考:https://jaywcjlove.github.io/reference/docs/quickreference.html
|
||||
[`Quick Reference`](https://jaywcjlove.github.io/reference) 使用 [`@wcj/markdown-to-html`](https://github.com/jaywcjlove/markdown-to-html) 转换 `Markdown`,并使用 [`rehype-attr`](https://github.com/jaywcjlove/rehype-attr) 插件让其支持通过其注释语法添加类和样式。此外,您可以在 Quick Reference 备忘清单上使用样式参考:<https://jaywcjlove.github.io/reference/docs/quickreference.html>
|
||||
|
||||
最后,参考现有备忘清单的源代码是一个好习惯!
|
||||
|
||||
@@ -61,7 +61,7 @@ Contributing 贡献
|
||||
- SVG 图标尺寸 `<svg height="1em" width="1em"`
|
||||
- SVG 图标颜色使用继承颜色值 `<svg fill="currentColor"`
|
||||
|
||||
#### 提示配置
|
||||
### 提示配置
|
||||
|
||||
```markdown
|
||||
[Django](./docs/djiango.md)<!--rehype:style=background: rgb(12 75 51/var(\-\-bg\-opacity));&class=contributing-->
|
||||
@@ -69,7 +69,6 @@ Contributing 贡献
|
||||
|
||||
添加 `contributing` 类名,会在卡片下方添加 _`👆待完善需要您的参与`_,添加 `data-info=👆看看还缺点儿什么?`,更换默认提示文本。
|
||||
|
||||
|
||||
```markdown
|
||||
[Django](./docs/djiango.md)<!--rehype:style=background: rgb(12 75 51/var(\-\-bg\-opacity));&class=tag&data-lang=Python-->
|
||||
```
|
||||
@@ -83,3 +82,104 @@ npm i # 安装依赖
|
||||
npm run build # 编译输出 HTML
|
||||
npm run start # 监听 md 文件编译输出 HTML
|
||||
```
|
||||
|
||||
或者你也可以使用 `pnpm` 或者 `yarn` 做为包管理器
|
||||
|
||||
|
||||
## 贡献
|
||||
|
||||
请参阅[贡献指南](./CONTRIBUTING.md)了解如何开始。一如既往,感谢我们出色的贡献者!
|
||||
|
||||
<!--GAMFC--><a href="https://github.com/jaywcjlove" title="小弟调调™">
|
||||
<img src="https://avatars.githubusercontent.com/u/1680273?v=4" width="42;" alt="小弟调调™"/>
|
||||
</a>
|
||||
<a href="https://github.com/Jack-Zhang-1314" title="fw_qaq">
|
||||
<img src="https://avatars.githubusercontent.com/u/82551626?v=4" width="42;" alt="fw_qaq"/>
|
||||
</a>
|
||||
<a href="https://github.com/partoneplay" title="partoneplay">
|
||||
<img src="https://avatars.githubusercontent.com/u/5189132?v=4" width="42;" alt="partoneplay"/>
|
||||
</a>
|
||||
<a href="https://github.com/catcto" title="喵仙人">
|
||||
<img src="https://avatars.githubusercontent.com/u/5467932?v=4" width="42;" alt="喵仙人"/>
|
||||
</a>
|
||||
<a href="https://github.com/13812700839" title="花殇">
|
||||
<img src="https://avatars.githubusercontent.com/u/58072506?v=4" width="42;" alt="花殇"/>
|
||||
</a>
|
||||
<a href="https://github.com/Smartdousha" title="Anko">
|
||||
<img src="https://avatars.githubusercontent.com/u/52566311?v=4" width="42;" alt="Anko"/>
|
||||
</a>
|
||||
<a href="https://github.com/CharlotteZeng" title="Chart">
|
||||
<img src="https://avatars.githubusercontent.com/u/19461184?v=4" width="42;" alt="Chart"/>
|
||||
</a>
|
||||
<a href="https://github.com/demigodliu" title="DemigodLiu">
|
||||
<img src="https://avatars.githubusercontent.com/u/30372735?v=4" width="42;" alt="DemigodLiu"/>
|
||||
</a>
|
||||
<a href="https://github.com/jasnzhuang" title="Jason Zhuang">
|
||||
<img src="https://avatars.githubusercontent.com/u/16612921?v=4" width="42;" alt="Jason Zhuang"/>
|
||||
</a>
|
||||
<a href="https://github.com/JetSquirrel" title="JetSquirrel">
|
||||
<img src="https://avatars.githubusercontent.com/u/20291255?v=4" width="42;" alt="JetSquirrel"/>
|
||||
</a>
|
||||
<a href="https://github.com/HanaNoryu" title="Noryu">
|
||||
<img src="https://avatars.githubusercontent.com/u/109856546?v=4" width="42;" alt="Noryu"/>
|
||||
</a>
|
||||
<a href="https://github.com/chyok" title="chyok">
|
||||
<img src="https://avatars.githubusercontent.com/u/32629225?v=4" width="42;" alt="chyok"/>
|
||||
</a>
|
||||
<a href="https://github.com/gaoxiaoduan" title="coderduan">
|
||||
<img src="https://avatars.githubusercontent.com/u/69953511?v=4" width="42;" alt="coderduan"/>
|
||||
</a>
|
||||
<a href="https://github.com/cool9203" title="cool9203">
|
||||
<img src="https://avatars.githubusercontent.com/u/29609607?v=4" width="42;" alt="cool9203"/>
|
||||
</a>
|
||||
<a href="https://github.com/godotc" title="godotc">
|
||||
<img src="https://avatars.githubusercontent.com/u/79260851?v=4" width="42;" alt="godotc"/>
|
||||
</a>
|
||||
<a href="https://github.com/greyhao" title="greyhao">
|
||||
<img src="https://avatars.githubusercontent.com/u/107107440?v=4" width="42;" alt="greyhao"/>
|
||||
</a>
|
||||
<a href="https://github.com/hua03" title="hua03">
|
||||
<img src="https://avatars.githubusercontent.com/u/19561959?v=4" width="42;" alt="hua03"/>
|
||||
</a>
|
||||
<a href="https://github.com/hweining" title="hweining">
|
||||
<img src="https://avatars.githubusercontent.com/u/8973985?v=4" width="42;" alt="hweining"/>
|
||||
</a>
|
||||
<a href="https://github.com/kdxcxs" title="kdxcxs">
|
||||
<img src="https://avatars.githubusercontent.com/u/18746192?v=4" width="42;" alt="kdxcxs"/>
|
||||
</a>
|
||||
<a href="https://github.com/larry-xue" title="larry">
|
||||
<img src="https://avatars.githubusercontent.com/u/48818060?v=4" width="42;" alt="larry"/>
|
||||
</a>
|
||||
<a href="https://github.com/liliangrong777" title="liliangrong777">
|
||||
<img src="https://avatars.githubusercontent.com/u/58727146?v=4" width="42;" alt="liliangrong777"/>
|
||||
</a>
|
||||
<a href="https://github.com/mofelee" title="mofelee">
|
||||
<img src="https://avatars.githubusercontent.com/u/5069410?v=4" width="42;" alt="mofelee"/>
|
||||
</a>
|
||||
<a href="https://github.com/onewesong" title="onewesong">
|
||||
<img src="https://avatars.githubusercontent.com/u/17920822?v=4" width="42;" alt="onewesong"/>
|
||||
</a>
|
||||
<a href="https://github.com/ryanhex53" title="ryanhex53">
|
||||
<img src="https://avatars.githubusercontent.com/u/360426?v=4" width="42;" alt="ryanhex53"/>
|
||||
</a>
|
||||
<a href="https://github.com/wjjwkwindy" title="wjjwkwindy">
|
||||
<img src="https://avatars.githubusercontent.com/u/9508591?v=4" width="42;" alt="wjjwkwindy"/>
|
||||
</a>
|
||||
<a href="https://github.com/xing133" title="xing133">
|
||||
<img src="https://avatars.githubusercontent.com/u/5336490?v=4" width="42;" alt="xing133"/>
|
||||
</a>
|
||||
<a href="https://github.com/zxx-457" title="zxx-457">
|
||||
<img src="https://avatars.githubusercontent.com/u/114141362?v=4" width="42;" alt="zxx-457"/>
|
||||
</a>
|
||||
<a href="https://github.com/lvzhenbo" title="吕振波">
|
||||
<img src="https://avatars.githubusercontent.com/u/32427677?v=4" width="42;" alt="吕振波"/>
|
||||
</a>
|
||||
<a href="https://github.com/lisheng741" title="芦荟柚子茶">
|
||||
<img src="https://avatars.githubusercontent.com/u/53617305?v=4" width="42;" alt="芦荟柚子茶"/>
|
||||
</a><!--GAMFC-END-->
|
||||
|
||||
上图贡献者列表,由 [contributors](https://github.com/jaywcjlove/github-action-contributors) 自动生成贡献者图片。
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Kenny Wong](https://github.com/jaywcjlove)
|
||||
|
147
README.md
147
README.md
@@ -9,10 +9,10 @@ Quick Reference
|
||||
<!--rehype:ignore:end-->
|
||||
|
||||
<!--rehype:ignore:start-->
|
||||
[](https://jaywcjlove.github.io/reference)
|
||||
[](https://jaywcjlove.github.io/reference)
|
||||
<!--rehype:ignore:end-->
|
||||
|
||||
为开发人员分享快速参考备忘清单【速查表】 _(主要是方便自己)_,在看到 [Reference](https://github.com/Randy8080/reference) 快速参考备忘单,感觉非常简单,造轮子使命感突然来了,造个中文版本的,为了方便自己的技术栈查阅,立马撸起来 :)。如果您发现此处的备忘单不合适,您可以通过提交 [PR](https://github.com/jaywcjlove/reference/blob/main/CONTRIBUTING.md) 来修复它或提供更好的备忘清单,只针对【中文】用户。以下是开源天使提供的一些备忘清单和快速参考 :)。
|
||||
为开发人员分享快速参考备忘清单【速查表】。在看到 [Reference](https://github.com/Randy8080/reference) 快速参考备忘单,感觉非常简单,造中文版本的轮子使命感突然来了,为了方便自己的技术栈查阅,如果您提供一个清单,我将抽空搬运,立即撸起来 :)。如果您发现此处的备忘单不合适,您可以通过提交 [PR](https://github.com/jaywcjlove/reference/blob/main/CONTRIBUTING.md) 来修复它或提供更好的备忘清单,只针对【中文】用户。以下是开源天使提供的一些备忘清单和快速参考 :)。
|
||||
|
||||
## 正在建设中...
|
||||
|
||||
@@ -21,8 +21,10 @@ Quick Reference
|
||||
|
||||
[Ansible](./docs/ansible.md)<!--rehype:style=background: rgb(238 0 0/var(\-\-bg\-opacity));&class=contributing tag&data-lang=RedHad&data-info=👆看看还缺点儿什么?-->
|
||||
[CMake](./docs/cmake.md)<!--rehype:style=background: rgb(92 107 192/var(\-\-bg\-opacity));&class=contributing-->
|
||||
[C#](./docs/cs.md)<!--rehype:style=background: rgb(6 147 13/var(\-\-bg\-opacity));&class=contributing-->
|
||||
[Django](./docs/djiango.md)<!--rehype:style=background: rgb(12 75 51/var(\-\-bg\-opacity));&class=contributing tag&data-lang=Python-->
|
||||
[FFmpeg](./docs/ffmpeg.md)<!--rehype:style=background: rgb(0 193 9/var(\-\-bg\-opacity));&class=contributing-->
|
||||
[LaTeX](./docs/latex.md)<!--rehype:style=background: rgb(0 128 128/var(\-\-bg\-opacity));&class=contributing-->
|
||||
[MATLAB](./docs/matlab.md)<!--rehype:style=background: rgb(0 118 168/var(\-\-bg\-opacity));&class=contributing-->
|
||||
[Vue 3 ](./docs/vue.md)<!--rehype:style=background: rgb(64 184 131/var(\-\-bg\-opacity));&class=contributing-->
|
||||
<!--rehype:class=home-card-->
|
||||
@@ -31,17 +33,27 @@ Quick Reference
|
||||
|
||||
[Bash](./docs/bash.md)<!--rehype:style=background: rgb(72 143 223/var(\-\-bg\-opacity));-->
|
||||
[C](./docs/c.md)<!--rehype:style=background: rgb(92 107 192/var(\-\-bg\-opacity));-->
|
||||
[C#](./docs/cs.md)<!--rehype:style=background: rgb(6 147 13/var(\-\-bg\-opacity));&class=contributing-->
|
||||
[CPP](./docs/cpp.md)<!--rehype:style=background: rgb(6 147 13/var(\-\-bg\-opacity));&class=contributing-->
|
||||
[Dart](./docs/dart.md)<!--rehype:style=background: rgb(64 196 255/var(\-\-bg\-opacity));-->
|
||||
[Docker](./docs/docker.md)<!--rehype:style=background: rgb(72 143 223/var(\-\-bg\-opacity));-->
|
||||
[Dockerfile](./docs/dockerfile.md)<!--rehype:style=background: rgb(0 72 153/var(\-\-bg\-opacity));&class=tag&data-lang=Docker-->
|
||||
[Django](./docs/djiango.md)<!--rehype:style=background: rgb(12 75 51/var(\-\-bg\-opacity));&class=contributing tag&data-lang=Python-->
|
||||
[Golang](./docs/golang.md)<!--rehype:style=background: rgb(39 160 193/var(\-\-bg\-opacity));-->
|
||||
[GraphQL](./docs/graphql.md)<!--rehype:style=background: rgb(214 66 146/var(\-\-bg\-opacity));-->
|
||||
[INI](./docs/ini.md)<!--rehype:style=background: rgb(57 59 60/var(\-\-bg\-opacity));-->
|
||||
[JSON](./docs/json.md)<!--rehype:style=background: rgb(57 59 60/var(\-\-bg\-opacity));-->
|
||||
[Java](./docs/java.md)<!--rehype:style=background: rgb(211 55 49/var(\-\-bg\-opacity));&class=contributing&data-info=👆看看还缺点儿什么?-->
|
||||
[Julia](./docs/julia.md)<!--rehype:style=background: rgb(211 55 49/var(\-\-bg\-opacity));&class=contributing&data-info=👆看看还缺点儿什么?-->
|
||||
[Kotlin](./docs/kotlin.md)<!--rehype:style=background: rgb(211 55 49/var(\-\-bg\-opacity));&class=contributing&data-info=👆看看还缺点儿什么?-->
|
||||
[LaTeX](./docs/latex.md)<!--rehype:style=background: rgb(0 128 128/var(\-\-bg\-opacity));&class=contributing-->
|
||||
[Markdown](./docs/markdown.md)<!--rehype:style=background: rgb(103 61 156/var(\-\-bg\-opacity));-->
|
||||
[MySQL](./docs/mysql.md)<!--rehype:style=background: rgb(103 61 156/var(\-\-bg\-opacity));&class=tag&data-lang=SQL-->
|
||||
[MySQL](./docs/mysql.md)<!--rehype:style=background: rgb(1 117 143/var(\-\-bg\-opacity));&class=tag&data-lang=SQL-->
|
||||
[MATLAB](./docs/matlab.md)<!--rehype:style=background: rgb(0 118 168/var(\-\-bg\-opacity));&class=contributing-->
|
||||
[Python](./docs/python.md)<!--rehype:style=background: rgb(240 81 57/var(\-\-bg\-opacity));-->
|
||||
[PHP](./docs/php.md)<!--rehype:style=background: rgb(79 91 147/var(\-\-bg\-opacity));-->
|
||||
[Python](./docs/python.md)<!--rehype:style=background: rgb(43 91 132/var(\-\-bg\-opacity));-->
|
||||
[PostgreSQL](./docs/postgres.md)<!--rehype:style=background: rgb(43 109 163/var(\-\-bg\-opacity));&class=tag&data-lang=SQL-->
|
||||
[Ruby](./docs/ruby.md)<!--rehype:style=background: rgb(204 52 45/var(\-\-bg\-opacity));-->
|
||||
[Rust](./docs/rust.md)<!--rehype:style=background: rgb(71 71 71/var(\-\-bg\-opacity));-->
|
||||
[Swift](./docs/swift.md)<!--rehype:style=background: rgb(240 81 57/var(\-\-bg\-opacity));-->
|
||||
[SwiftUI](./docs/swiftui.md)<!--rehype:style=background: rgb(10 127 247/var(\-\-bg\-opacity));&class=tag&data-lang=swift-->
|
||||
@@ -62,7 +74,7 @@ Quick Reference
|
||||
[JavaScript](./docs/javascript.md)<!--rehype:style=background: rgb(203 183 31/var(\-\-bg\-opacity));-->
|
||||
[Less.js](./docs/lessjs.md)<!--rehype:style=background: rgb(29 54 93/var(\-\-bg\-opacity));&class=tag&data-lang=CSS-->
|
||||
[React](./docs/react.md)<!--rehype:style=background: rgb(34 143 173/var(\-\-bg\-opacity));-->
|
||||
[RegEx](./docs/regex.md)<!--rehype:style=background: rgb(149 36 155/var(\-\-bg\-opacity));-->
|
||||
[RegEx 正则表达式](./docs/regex.md)<!--rehype:style=background: rgb(149 36 155/var(\-\-bg\-opacity));-->
|
||||
[TypeScript](./docs/typescript.md)<!--rehype:style=background: rgb(49 120 198/var(\-\-bg\-opacity));-->
|
||||
[Vue 2](./docs/vue2.md)<!--rehype:style=background: rgb(64 184 131/var(\-\-bg\-opacity));-->
|
||||
[Vue 3 ](./docs/vue.md)<!--rehype:style=background: rgb(64 184 131/var(\-\-bg\-opacity));&class=contributing-->
|
||||
@@ -85,20 +97,21 @@ Quick Reference
|
||||
[Gmail](./docs/gmail.md)<!--rehype:style=background: rgb(234 67 54/var(\-\-bg\-opacity));-->
|
||||
[nginx](./docs/nginx.md)<!--rehype:style=background: rgb(0 153 0/var(\-\-bg\-opacity));-->
|
||||
[Semver](./docs/semver.md)<!--rehype:style=background: rgb(106 111 141/var(\-\-bg\-opacity));-->
|
||||
[Sketch](./docs/sketch.md)<!--rehype:style=background: rgb(223 148 0/var(\-\-bg\-opacity));-->
|
||||
[Sketch](./docs/sketch.md)<!--rehype:style=background: rgb(223 148 0/var(\-\-bg\-opacity));&class=tag&data-lang=macOS-->
|
||||
[Sublime Text](./docs/sublime-text.md)<!--rehype:style=background: rgb(223 148 0/var(\-\-bg\-opacity));-->
|
||||
[VSCode](./docs/vscode.md)<!--rehype:style=background: rgb(91 163 230/var(\-\-bg\-opacity));-->
|
||||
[Vim](./docs/vim.md)<!--rehype:style=background: rgb(9 150 8/var(\-\-bg\-opacity));-->
|
||||
[WebStorm](./docs/webstorm.md)<!--rehype:style=background: rgb(32 148 220/var(\-\-bg\-opacity));-->
|
||||
[XPath](./docs/xpath.md)<!--rehype:style=background: rgb(91 163 230/var(\-\-bg\-opacity));-->
|
||||
[Xcode](./docs/xcode.md)<!--rehype:style=background: rgb(24 151 233/var(\-\-bg\-opacity));-->
|
||||
[Xcode](./docs/xcode.md)<!--rehype:style=background: rgb(24 151 233/var(\-\-bg\-opacity));&class=tag&data-lang=macOS-->
|
||||
<!--rehype:class=home-card-->
|
||||
|
||||
## Linux 命令
|
||||
## 命令
|
||||
|
||||
[Ansible](./docs/ansible.md)<!--rehype:style=background: rgb(238 0 0/var(\-\-bg\-opacity));&class=contributing tag&data-lang=RedHad&data-info=👆看看还缺点儿什么?-->
|
||||
[Awk](./docs/awk.md)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));-->
|
||||
[Conan](./docs/conan.md)<!--rehype:style=background: rgb(0 193 9/var(\-\-bg\-opacity));&class=tag&data-lang=C/C++-->
|
||||
[CocoaPods](./docs/cocoapods.md)<!--rehype:style=background: rgb(251 0 6/var(\-\-bg\-opacity));&class=tag&data-lang=C/C++-->
|
||||
[Cargo](./docs/cargo.md)<!--rehype:style=background: rgb(71 71 71/var(\-\-bg\-opacity));&class=tag&data-lang=Rust-->
|
||||
[Curl](./docs/curl.md)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));-->
|
||||
[Chmod](./docs/chmod.md)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));-->
|
||||
@@ -109,19 +122,22 @@ Quick Reference
|
||||
[Find](./docs/find.md)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));-->
|
||||
[FFmpeg](./docs/ffmpeg.md)<!--rehype:style=background: rgb(0 193 9/var(\-\-bg\-opacity));&class=contributing-->
|
||||
[Htop](./docs/htop.md)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));-->
|
||||
[Home Brew](./docs/homebrew.md)<!--rehype:style=background: rgb(252 185 87/var(\-\-bg\-opacity));-->
|
||||
[Home Brew](./docs/homebrew.md)<!--rehype:style=background: rgb(252 185 87/var(\-\-bg\-opacity));&class=tag&data-lang=macOS-->
|
||||
[Netstat](./docs/netstat.md)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));-->
|
||||
[jq](./docs/jq.md)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));&class=tag&data-lang=JSON-->
|
||||
[Lsof](./docs/lsof.md)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));-->
|
||||
[Netcat](./docs/netcat.md)<!--rehype:style=background: rgb(4 92 135/var(\-\-bg\-opacity));-->
|
||||
[Sed](./docs/sed.md)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));-->
|
||||
[Systemd](./docs/systemd.md)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));-->
|
||||
[SSH](./docs/ssh.md)<!--rehype:style=background: rgb(99 99 99/var(\-\-bg\-opacity));-->
|
||||
[Screen](./docs/screen.md)<!--rehype:style=background: rgb(99 99 99/var(\-\-bg\-opacity));-->
|
||||
[Tmux](./docs/tmux.md)<!--rehype:style=background: rgb(99 99 99/var(\-\-bg\-opacity));-->
|
||||
[YUM](./docs/yum.md)<!--rehype:style=background: rgb(86 86 123/var(\-\-bg\-opacity));-->
|
||||
<!--rehype:class=home-card-->
|
||||
|
||||
## 其它
|
||||
|
||||
[Quick Reference](./docs/quickreference.md)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));-->
|
||||
[Quick Reference](./docs/quickreference.md)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));&class=tag&data-lang=排版说明-->
|
||||
[Github Actions](./docs/github-actions.md)<!--rehype:style=background: rgb(121 184 255/var(\-\-bg\-opacity));-->
|
||||
[Colors Named](./docs/colors-named.md)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));&class=tag&data-lang=CSS-->
|
||||
[HTTP 状态码](./docs/http-status-code.md)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));-->
|
||||
@@ -141,17 +157,116 @@ Quick Reference
|
||||
[`我有一张备忘单(速查表)`](https://github.com/jaywcjlove/reference/blob/main/CONTRIBUTING.md)<!--rehype:class=home-button text-grey&target=__blank-->
|
||||
<!--rehype:style=margin-top:3rem-->
|
||||
|
||||
<!--rehype:ignore:start-->
|
||||
## 贡献
|
||||
## 感谢所有贡献者
|
||||
<!--rehype:wrap-style=text-align: center;max-width: 650px;margin: 0 auto;&class=home-title-reset-->
|
||||
|
||||
请参阅[贡献指南](./CONTRIBUTING.md)了解如何开始。一如既往,感谢我们出色的贡献者!
|
||||
请参阅 [Quick Reference](./docs/quickreference.md) 了解如何开始。一如既往,感谢我们出色的贡献者!
|
||||
<!--rehype:style=padding-bottom:1rem;-->
|
||||
|
||||
<a href="https://github.com/jaywcjlove/reference/graphs/contributors">
|
||||
<img src="https://jaywcjlove.github.io/reference/CONTRIBUTORS.svg" />
|
||||
<!--GAMFC--><a href="https://github.com/jaywcjlove" title="小弟调调™">
|
||||
<img src="https://avatars.githubusercontent.com/u/1680273?v=4" width="42;" alt="小弟调调™"/>
|
||||
</a>
|
||||
<a href="https://github.com/Jack-Zhang-1314" title="fw_qaq">
|
||||
<img src="https://avatars.githubusercontent.com/u/82551626?v=4" width="42;" alt="fw_qaq"/>
|
||||
</a>
|
||||
<a href="https://github.com/partoneplay" title="partoneplay">
|
||||
<img src="https://avatars.githubusercontent.com/u/5189132?v=4" width="42;" alt="partoneplay"/>
|
||||
</a>
|
||||
<a href="https://github.com/catcto" title="喵仙人">
|
||||
<img src="https://avatars.githubusercontent.com/u/5467932?v=4" width="42;" alt="喵仙人"/>
|
||||
</a>
|
||||
<a href="https://github.com/13812700839" title="花殇">
|
||||
<img src="https://avatars.githubusercontent.com/u/58072506?v=4" width="42;" alt="花殇"/>
|
||||
</a>
|
||||
<a href="https://github.com/Smartdousha" title="Anko">
|
||||
<img src="https://avatars.githubusercontent.com/u/52566311?v=4" width="42;" alt="Anko"/>
|
||||
</a>
|
||||
<a href="https://github.com/CharlotteZeng" title="Chart">
|
||||
<img src="https://avatars.githubusercontent.com/u/19461184?v=4" width="42;" alt="Chart"/>
|
||||
</a>
|
||||
<a href="https://github.com/demigodliu" title="DemigodLiu">
|
||||
<img src="https://avatars.githubusercontent.com/u/30372735?v=4" width="42;" alt="DemigodLiu"/>
|
||||
</a>
|
||||
<a href="https://github.com/jasnzhuang" title="Jason Zhuang">
|
||||
<img src="https://avatars.githubusercontent.com/u/16612921?v=4" width="42;" alt="Jason Zhuang"/>
|
||||
</a>
|
||||
<a href="https://github.com/JetSquirrel" title="JetSquirrel">
|
||||
<img src="https://avatars.githubusercontent.com/u/20291255?v=4" width="42;" alt="JetSquirrel"/>
|
||||
</a>
|
||||
<a href="https://github.com/HanaNoryu" title="Noryu">
|
||||
<img src="https://avatars.githubusercontent.com/u/109856546?v=4" width="42;" alt="Noryu"/>
|
||||
</a>
|
||||
<a href="https://github.com/chyok" title="chyok">
|
||||
<img src="https://avatars.githubusercontent.com/u/32629225?v=4" width="42;" alt="chyok"/>
|
||||
</a>
|
||||
<a href="https://github.com/gaoxiaoduan" title="coderduan">
|
||||
<img src="https://avatars.githubusercontent.com/u/69953511?v=4" width="42;" alt="coderduan"/>
|
||||
</a>
|
||||
<a href="https://github.com/cool9203" title="cool9203">
|
||||
<img src="https://avatars.githubusercontent.com/u/29609607?v=4" width="42;" alt="cool9203"/>
|
||||
</a>
|
||||
<a href="https://github.com/godotc" title="godotc">
|
||||
<img src="https://avatars.githubusercontent.com/u/79260851?v=4" width="42;" alt="godotc"/>
|
||||
</a>
|
||||
<a href="https://github.com/greyhao" title="greyhao">
|
||||
<img src="https://avatars.githubusercontent.com/u/107107440?v=4" width="42;" alt="greyhao"/>
|
||||
</a>
|
||||
<a href="https://github.com/hua03" title="hua03">
|
||||
<img src="https://avatars.githubusercontent.com/u/19561959?v=4" width="42;" alt="hua03"/>
|
||||
</a>
|
||||
<a href="https://github.com/hweining" title="hweining">
|
||||
<img src="https://avatars.githubusercontent.com/u/8973985?v=4" width="42;" alt="hweining"/>
|
||||
</a>
|
||||
<a href="https://github.com/kdxcxs" title="kdxcxs">
|
||||
<img src="https://avatars.githubusercontent.com/u/18746192?v=4" width="42;" alt="kdxcxs"/>
|
||||
</a>
|
||||
<a href="https://github.com/larry-xue" title="larry">
|
||||
<img src="https://avatars.githubusercontent.com/u/48818060?v=4" width="42;" alt="larry"/>
|
||||
</a>
|
||||
<a href="https://github.com/liliangrong777" title="liliangrong777">
|
||||
<img src="https://avatars.githubusercontent.com/u/58727146?v=4" width="42;" alt="liliangrong777"/>
|
||||
</a>
|
||||
<a href="https://github.com/mofelee" title="mofelee">
|
||||
<img src="https://avatars.githubusercontent.com/u/5069410?v=4" width="42;" alt="mofelee"/>
|
||||
</a>
|
||||
<a href="https://github.com/onewesong" title="onewesong">
|
||||
<img src="https://avatars.githubusercontent.com/u/17920822?v=4" width="42;" alt="onewesong"/>
|
||||
</a>
|
||||
<a href="https://github.com/ryanhex53" title="ryanhex53">
|
||||
<img src="https://avatars.githubusercontent.com/u/360426?v=4" width="42;" alt="ryanhex53"/>
|
||||
</a>
|
||||
<a href="https://github.com/wjjwkwindy" title="wjjwkwindy">
|
||||
<img src="https://avatars.githubusercontent.com/u/9508591?v=4" width="42;" alt="wjjwkwindy"/>
|
||||
</a>
|
||||
<a href="https://github.com/xing133" title="xing133">
|
||||
<img src="https://avatars.githubusercontent.com/u/5336490?v=4" width="42;" alt="xing133"/>
|
||||
</a>
|
||||
<a href="https://github.com/zxx-457" title="zxx-457">
|
||||
<img src="https://avatars.githubusercontent.com/u/114141362?v=4" width="42;" alt="zxx-457"/>
|
||||
</a>
|
||||
<a href="https://github.com/lvzhenbo" title="吕振波">
|
||||
<img src="https://avatars.githubusercontent.com/u/32427677?v=4" width="42;" alt="吕振波"/>
|
||||
</a>
|
||||
<a href="https://github.com/lisheng741" title="芦荟柚子茶">
|
||||
<img src="https://avatars.githubusercontent.com/u/53617305?v=4" width="42;" alt="芦荟柚子茶"/>
|
||||
</a><!--GAMFC-END-->
|
||||
|
||||
上图贡献者列表,由 [contributors](https://github.com/jaywcjlove/github-action-contributors) 自动生成贡献者图片。
|
||||
贡献者列表,由 [contributors](https://github.com/jaywcjlove/github-action-contributors) 自动生成
|
||||
<!--rehype:style=padding-top:1rem;-->
|
||||
|
||||
## 国内镜像网站
|
||||
<!--rehype:wrap-style=text-align: center;max-width: 650px;margin: 0 auto;&class=home-title-reset-->
|
||||
|
||||
由于中国国内访问,时常打不开,你可以访问下面镜像网站。推荐我的[镜像网站](https://github.com/jaywcjlove/reference/issues/102#issue-1451649637)
|
||||
|
||||
[ecdata.cn](http://ref.ecdata.cn/)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));height: 3rem;-->
|
||||
[mofe.io](http://quickref.mofe.io)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));height: 3rem;-->
|
||||
<!--rehype:class=home-card&style=margin:1.2rem 0;display: flex;justify-content: center;-->
|
||||
|
||||
如果你有资源,可以很方便部署 web 版,这非常简单,只需要克隆 gh-pages 分支代码到你的静态服务就可以了,还可以使用 [docker](https://hub.docker.com/r/wcjiang/reference) 快捷部署 web 版。
|
||||
|
||||
|
||||
<!--rehype:ignore:start-->
|
||||
## License
|
||||
|
||||
MIT © [Kenny Wong](https://github.com/jaywcjlove)
|
||||
|
@@ -18,7 +18,6 @@ Ansible 备忘清单
|
||||
|
||||
- [Ansible 官方文档](https://docs.ansible.com)
|
||||
|
||||
|
||||
### 配置位置
|
||||
|
||||
文件路径 | 说明
|
||||
@@ -27,12 +26,12 @@ Ansible 备忘清单
|
||||
`~/ansible.cfg` | 用户特定的配置
|
||||
`$pwd/ansible.cfg` | 当前目录下的配置
|
||||
|
||||
|
||||
### Inventory文件(hosts列表)
|
||||
|
||||
#### 静态Inventory
|
||||
|
||||
`/etc/ansible/hosts`
|
||||
|
||||
```INI
|
||||
mail.example.com
|
||||
|
||||
@@ -41,6 +40,41 @@ foo.example.com
|
||||
bar.example.com
|
||||
```
|
||||
|
||||
### Inventory 主机组使用多个IP和域名
|
||||
|
||||
```
|
||||
[web]
|
||||
172.18.12.5[1:4]
|
||||
[webservers]
|
||||
www[01:50].example.com
|
||||
```
|
||||
|
||||
### Inventory 主机组使用子主机组
|
||||
|
||||
```ini
|
||||
[usa:children]
|
||||
southeast
|
||||
northeast
|
||||
southwest
|
||||
northwest
|
||||
```
|
||||
|
||||
### 给多台主机设置变量
|
||||
|
||||
`group variables`
|
||||
如果组中的所有主机共享一个变量值,则可以一次将该变量应用于整个组
|
||||
|
||||
```ini
|
||||
[atlanta]
|
||||
host1
|
||||
host2
|
||||
|
||||
[atlanta:vars]
|
||||
ntp_server=ntp.atlanta.example.com
|
||||
proxy=proxy.atlanta.example.com
|
||||
|
||||
```
|
||||
|
||||
## 命令行(ad-hoc)
|
||||
|
||||
### ansible
|
||||
@@ -50,6 +84,7 @@ bar.example.com
|
||||
```shell
|
||||
$ ansible all --list-hosts
|
||||
```
|
||||
|
||||
ping所有目标
|
||||
|
||||
```shell
|
||||
@@ -95,7 +130,7 @@ $ ansible
|
||||
$ ansible <host-pattern> [options]
|
||||
```
|
||||
|
||||
----
|
||||
---
|
||||
|
||||
:- | -
|
||||
:- | -
|
||||
@@ -183,7 +218,6 @@ $ ansible-galaxy init --offline <ROLE>
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
|
||||
### ansible-doc
|
||||
|
||||
在本地访问文档
|
||||
@@ -205,13 +239,13 @@ $ ansible-doc [options] [module...]
|
||||
`--version` | 显示程序的版本号并退出
|
||||
<!--rehype:className=style-list-->
|
||||
|
||||
|
||||
### ansible-vault
|
||||
|
||||
```bash
|
||||
$ ansible-vault
|
||||
$ ansible-vault [create|decrypt|edit|encrypt|rekey|view] [--help] [options] vaultfile.yml
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
:- | -
|
||||
@@ -232,6 +266,7 @@ $ ansible-vault [create|decrypt|edit|encrypt|rekey|view] [--help] [options] vaul
|
||||
$ ansible-playbook
|
||||
$ ansible-playbook playbook.yml
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
:- | -
|
||||
@@ -300,6 +335,7 @@ $ ansible-playbook playbook.yml
|
||||
$ ansible-pull
|
||||
$ ansible-pull -U <repository> [options]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
:- | -
|
||||
@@ -358,10 +394,9 @@ $ ansible-pull -U <repository> [options]
|
||||
<!-- ### ansible-playbook -->
|
||||
<!-- todo -->
|
||||
|
||||
|
||||
|
||||
另见
|
||||
---
|
||||
|
||||
[Getting started with Ansible](https://docs.ansible.com/ansible/latest/getting_started/index.html)
|
||||
[Introduction to ad hoc commands](https://docs.ansible.com/ansible/latest/user_guide/intro_adhoc.html)
|
||||
[Ansible cheatsheet](https://github.com/luckylittle/ansible-cheatsheet/blob/master/ansible-cheatsheet.txt)
|
@@ -59,7 +59,8 @@ $0/NR ▶ │ 1 │ baidu.com │ awk │
|
||||
$0/NR ▶ │ 2 │ google.com │ 25 │
|
||||
└──────┴──────────────┴───────┘
|
||||
```
|
||||
---
|
||||
|
||||
----
|
||||
|
||||
```shell
|
||||
# 第一个和最后一个字段
|
||||
@@ -253,7 +254,6 @@ awk -v varName="$PWD" '
|
||||
END {print varName}' </dev/null
|
||||
```
|
||||
|
||||
|
||||
Awk 运算符
|
||||
---------
|
||||
|
||||
@@ -366,7 +366,6 @@ Awk 函数
|
||||
`toupper(s)` | 字符串 `s` 转大写
|
||||
`getline` | 将 `$0` 设置为当前输入文件中的下一个输入记录
|
||||
|
||||
|
||||
### 用户定义函数
|
||||
|
||||
```shell
|
||||
@@ -424,7 +423,6 @@ awk 'BEGIN {
|
||||
}'
|
||||
```
|
||||
|
||||
|
||||
### 带拆分的数组
|
||||
|
||||
```shell
|
||||
@@ -536,7 +534,6 @@ awk -F: '{
|
||||
}' /etc/passwd
|
||||
```
|
||||
|
||||
|
||||
Awk 循环
|
||||
----------
|
||||
|
||||
@@ -744,6 +741,7 @@ daemon /sbin
|
||||
-------------
|
||||
|
||||
### 正则表达式元字符
|
||||
|
||||
- `\`
|
||||
- `^`
|
||||
- `$`
|
||||
|
75
docs/bash.md
75
docs/bash.md
@@ -27,9 +27,9 @@ NAME="John"
|
||||
echo ${NAME} # => John (变量)
|
||||
echo $NAME # => John (变量)
|
||||
echo "$NAME" # => John (变量)
|
||||
echo '$NAME' # => $NAME (确切的字符串)
|
||||
echo '$NAME' # => $NAME (字符串原样输出)
|
||||
echo "${NAME}!" # => John! (变量)
|
||||
NAME = "John" # => Error (关于空间)
|
||||
NAME = "John" # => Error (注意不能有空格)
|
||||
```
|
||||
|
||||
### 注释
|
||||
@@ -39,8 +39,8 @@ NAME = "John" # => Error (关于空间)
|
||||
|
||||
: '
|
||||
这是一个
|
||||
非常整洁的评论
|
||||
在 bash
|
||||
非常整洁的
|
||||
bash 注释
|
||||
'
|
||||
```
|
||||
|
||||
@@ -53,18 +53,17 @@ NAME = "John" # => Error (关于空间)
|
||||
:-|-
|
||||
`$1` … `$9` | 参数 1 ... 9
|
||||
`$0` | 脚本本身的名称
|
||||
`$1` | 第一个论点
|
||||
`$1` | 第一个参数
|
||||
`${10}` | 位置参数 10
|
||||
`$#` | 参数数量
|
||||
`$$` | shell 的进程 id
|
||||
`$*` | 所有论据
|
||||
`$*` | 所有参数
|
||||
`$@` | 所有参数,从第一个开始
|
||||
`$-` | 当前选项
|
||||
`$_` | 上一个命令的最后一个参数
|
||||
|
||||
见:[特殊参数](http://wiki.bash-hackers.org/syntax/shellvars#special_parameters_and_shell_variables)
|
||||
|
||||
|
||||
### 函数
|
||||
|
||||
```bash
|
||||
@@ -265,7 +264,9 @@ for e in "${Fruits[@]}"; do
|
||||
echo $e
|
||||
done
|
||||
```
|
||||
|
||||
#### With index
|
||||
|
||||
```bash
|
||||
for i in "${!Fruits[@]}"; do
|
||||
printf "%s\t%s\n" "$i" "${Fruits[$i]}"
|
||||
@@ -276,8 +277,8 @@ done
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
```bash
|
||||
Fruits=("${Fruits[@]}" "Watermelon") # 推
|
||||
Fruits+=('Watermelon') # 也推
|
||||
Fruits=("${Fruits[@]}" "Watermelon") # 添加
|
||||
Fruits+=('Watermelon') # 也是添加
|
||||
Fruits=( ${Fruits[@]/Ap*/} ) # 通过正则表达式匹配删除
|
||||
unset Fruits[2] # 删除一项
|
||||
Fruits=("${Fruits[@]}") # 复制
|
||||
@@ -349,14 +350,14 @@ Bash 条件句
|
||||
:- | -
|
||||
`[[ NUM -eq NUM ]]` | 等于 <yel>Eq</yel>ual |
|
||||
`[[ NUM -ne NUM ]]` | 不等于 <yel>N</yel>ot <yel>e</yel>qual |
|
||||
`[[ NUM -lt NUM ]]` | 少于 <yel>L</yel>ess <yel>t</yel>han |
|
||||
`[[ NUM -le NUM ]]` | 小于或等于 <yel>L</yel>ess than or <yel>e</yel>qual |
|
||||
`[[ NUM -lt NUM ]]` | 小于 <yel>L</yel>ess <yel>t</yel>han |
|
||||
`[[ NUM -le NUM ]]` | 小于等于 <yel>L</yel>ess than or <yel>e</yel>qual |
|
||||
`[[ NUM -gt NUM ]]` | 大于 <yel>G</yel>reater <yel>t</yel>han |
|
||||
`[[ NUM -ge NUM ]]` | 大于或等于 <yel>G</yel>reater than or <yel>e</yel>qual |
|
||||
`(( NUM < NUM ))` | 少于
|
||||
`[[ NUM -ge NUM ]]` | 大于等于 <yel>G</yel>reater than or <yel>e</yel>qual |
|
||||
`(( NUM < NUM ))` | 小于
|
||||
`(( NUM <= NUM ))` | 小于或等于
|
||||
`(( NUM > NUM ))` | 比...更棒
|
||||
`(( NUM >= NUM ))` | 大于或等于
|
||||
`(( NUM > NUM ))` | 比...更大
|
||||
`(( NUM >= NUM ))` | 大于等于
|
||||
|
||||
### 字符串条件
|
||||
|
||||
@@ -364,7 +365,7 @@ Bash 条件句
|
||||
:- | -
|
||||
`[[ -z STR ]]` | 空字符串
|
||||
`[[ -n STR ]]` | <yel>非</yel>空字符串
|
||||
`[[ STR == STR ]]` | 平等的
|
||||
`[[ STR == STR ]]` | 相等
|
||||
`[[ STR = STR ]]` | 相等(同上)
|
||||
`[[ STR < STR ]]` | 小于 _(ASCII)_
|
||||
`[[ STR > STR ]]` | 大于 _(ASCII)_
|
||||
@@ -410,7 +411,7 @@ if [[ '1. abc' =~ ([a-z]+) ]]; then
|
||||
fi
|
||||
```
|
||||
|
||||
#### 更小
|
||||
#### 小于
|
||||
|
||||
```bash
|
||||
if (( $a < $b )); then
|
||||
@@ -440,10 +441,9 @@ fi
|
||||
`[[ -w FILE ]]` | 可写
|
||||
`[[ -x FILE ]]` | 可执行文件
|
||||
`[[ f1 -nt f2 ]]` | f1 比 f2 新
|
||||
`[[ f1 -ot f2 ]]` | f2 早于 f1
|
||||
`[[ f1 -ot f2 ]]` | f2 比 f1 新
|
||||
`[[ f1 -ef f2 ]]` | 相同的文件
|
||||
|
||||
|
||||
### 更多条件
|
||||
|
||||
条件 | 描述
|
||||
@@ -492,7 +492,7 @@ for i in {1..5}; do
|
||||
done
|
||||
```
|
||||
|
||||
#### 具有步长
|
||||
#### 步长
|
||||
|
||||
```bash
|
||||
for i in {5..50..5}; do
|
||||
@@ -510,7 +510,7 @@ while [[ $i -lt 4 ]]; do
|
||||
done
|
||||
```
|
||||
|
||||
### 自动递增
|
||||
### 自动递减
|
||||
|
||||
```bash
|
||||
i=3
|
||||
@@ -554,7 +554,7 @@ until [ $count -gt 10 ]; do
|
||||
done
|
||||
```
|
||||
|
||||
### 永远
|
||||
### 死循环
|
||||
|
||||
```bash
|
||||
while true; do
|
||||
@@ -562,7 +562,7 @@ while true; do
|
||||
done
|
||||
```
|
||||
|
||||
### 永远(简写)
|
||||
### 死循环(简写)
|
||||
|
||||
```bash
|
||||
while :; do
|
||||
@@ -570,8 +570,7 @@ while :; do
|
||||
done
|
||||
```
|
||||
|
||||
|
||||
### 正在读取行
|
||||
### 读取文件的每一行
|
||||
|
||||
```bash
|
||||
cat file.txt | while read line; do
|
||||
@@ -614,7 +613,7 @@ myfunc() {
|
||||
result="$(myfunc)"
|
||||
```
|
||||
|
||||
### 正在引发错误
|
||||
### 抛出错误
|
||||
|
||||
```bash
|
||||
myfunc() {
|
||||
@@ -720,8 +719,7 @@ Bash 历史
|
||||
|
||||
`!!` 可以替换为任何有效的扩展,即 `!cat`、`!-2`、`!42` 等。
|
||||
|
||||
|
||||
各种各样的
|
||||
杂项
|
||||
-------------
|
||||
|
||||
### 数值计算
|
||||
@@ -741,7 +739,6 @@ $(($RANDOM%200)) # Random number 0..199
|
||||
pwd # still in first directory
|
||||
```
|
||||
|
||||
|
||||
### 检查命令
|
||||
|
||||
```bash
|
||||
@@ -765,7 +762,6 @@ python hello.py &>/dev/null # 标准输出和标准错误到(空null)
|
||||
python hello.py < foo.txt # 将 foo.txt 提供给 python 的标准输入
|
||||
```
|
||||
|
||||
|
||||
### 来源相对
|
||||
|
||||
```bash
|
||||
@@ -791,7 +787,6 @@ case "$1" in
|
||||
esac
|
||||
```
|
||||
|
||||
|
||||
### 陷阱错误
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
@@ -862,7 +857,6 @@ fi
|
||||
|
||||
见[特殊参数](http://wiki.bash-hackers.org/syntax/shellvars#special_parameters_and_shell_variables)。
|
||||
|
||||
|
||||
### grep 检查
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
@@ -872,7 +866,6 @@ if grep -q 'foo' ~/.bash_history; then
|
||||
fi
|
||||
```
|
||||
|
||||
|
||||
### 反斜杠转义
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
@@ -963,11 +956,11 @@ echo "${args[@]}"
|
||||
另见
|
||||
----
|
||||
|
||||
* [Shell 教程](https://jaywcjlove.github.io/shell-tutorial) _(jaywcjlove.github.io)_
|
||||
* [Devhints](https://devhints.io/bash) _(devhints.io)_
|
||||
* [Bash-hackers wiki](http://wiki.bash-hackers.org/) _(bash-hackers.org)_
|
||||
* [Shell vars](http://wiki.bash-hackers.org/syntax/shellvars) _(bash-hackers.org)_
|
||||
* [Learn bash in y minutes](https://learnxinyminutes.com/docs/bash/) _(learnxinyminutes.com)_
|
||||
* [Bash Guide](http://mywiki.wooledge.org/BashGuide) _(mywiki.wooledge.org)_
|
||||
* [ShellCheck](https://www.shellcheck.net/) _(shellcheck.net)_
|
||||
* [shell - Standard Shell](https://devmanual.gentoo.org/tools-reference/bash/index.html) _(devmanual.gentoo.org)_
|
||||
- [Shell 教程](https://jaywcjlove.github.io/shell-tutorial) _(jaywcjlove.github.io)_
|
||||
- [Devhints](https://devhints.io/bash) _(devhints.io)_
|
||||
- [Bash-hackers wiki](http://wiki.bash-hackers.org/) _(bash-hackers.org)_
|
||||
- [Shell vars](http://wiki.bash-hackers.org/syntax/shellvars) _(bash-hackers.org)_
|
||||
- [Learn bash in y minutes](https://learnxinyminutes.com/docs/bash/) _(learnxinyminutes.com)_
|
||||
- [Bash Guide](http://mywiki.wooledge.org/BashGuide) _(mywiki.wooledge.org)_
|
||||
- [ShellCheck](https://www.shellcheck.net/) _(shellcheck.net)_
|
||||
- [shell - Standard Shell](https://devmanual.gentoo.org/tools-reference/bash/index.html) _(devmanual.gentoo.org)_
|
||||
|
19
docs/c.md
19
docs/c.md
@@ -44,7 +44,7 @@ int myNum3 = 15; // myNum3 值为 15
|
||||
myNum3 = 10; // 现在 myNum3 值为 10
|
||||
|
||||
float myFloatNum = 5.99; // 浮点数
|
||||
char myLetter = 'D'; // 字符串
|
||||
char myLetter = 'D'; // 字符
|
||||
|
||||
int x = 5;
|
||||
int y = 6;
|
||||
@@ -608,7 +608,7 @@ printf("%c\n", myLetter);
|
||||
printf("%lf\n", myDouble);
|
||||
```
|
||||
|
||||
---
|
||||
----
|
||||
|
||||
数据类型 | 说 明
|
||||
:- | :-
|
||||
@@ -620,7 +620,6 @@ printf("%lf\n", myDouble);
|
||||
`double` | 双精度浮点型
|
||||
`void` | 无类型
|
||||
|
||||
|
||||
### 基本格式说明符
|
||||
|
||||
| 格式说明符 | 数据类型 |
|
||||
@@ -743,8 +742,6 @@ Carole 和 Debra: 我们爱你!
|
||||
|
||||
需要把一个宏的参数转换为字符串常量时,使用字符串常量化运算符 `#`
|
||||
|
||||
|
||||
|
||||
### 标记粘贴运算符(##)
|
||||
|
||||
```c
|
||||
@@ -821,12 +818,12 @@ void myFunction() { // 声明 declaration
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
----
|
||||
|
||||
- `Declaration` 声明函数名称、返回类型和参数 _(如果有)_
|
||||
- `Definition` 函数体 _(要执行的代码)_
|
||||
|
||||
---
|
||||
----
|
||||
|
||||
```c
|
||||
// 函数声明
|
||||
@@ -949,7 +946,7 @@ printf("%f", floor(1.4)); // 四舍五入 (舍)
|
||||
printf("%f", pow(4, 3)); // x(4)的y(3)次方
|
||||
```
|
||||
|
||||
---
|
||||
----
|
||||
|
||||
- `abs(x)` 绝对值
|
||||
- `acos(x)` 反余弦值
|
||||
@@ -1304,16 +1301,21 @@ void main (){
|
||||
|
||||
- 安装 [`Docker`](./docker.md)
|
||||
- 创建 [`Dockerfile`](./dockerfile.md) 文件
|
||||
|
||||
```dockerfile
|
||||
FROM alpine:3.14
|
||||
RUN apk add --no-cache gcc musl-dev
|
||||
RUN apk add --no-cache g++
|
||||
```
|
||||
|
||||
- 生成本地 myalpine 镜像
|
||||
|
||||
```bash
|
||||
docker build -t myalpine .
|
||||
```
|
||||
|
||||
- 运行映像,把当前路径 `($PWD)` 映射至容器的 `/test` 目录,用 `gcc` 编译程序,`exit`返回
|
||||
|
||||
```bash
|
||||
docker run -it -v $PWD:/test myalpine
|
||||
root@b1a38bd7107a:/# cd test
|
||||
@@ -1324,7 +1326,6 @@ void main (){
|
||||
```
|
||||
<!--rehype:className=style-timeline-->
|
||||
|
||||
|
||||
另见
|
||||
---
|
||||
|
||||
|
100
docs/cargo.md
100
docs/cargo.md
@@ -6,8 +6,7 @@ Cargo 备忘清单
|
||||
入门
|
||||
--------
|
||||
|
||||
### 安装 Rust 和 Cargo
|
||||
|
||||
### 安装/升级 Rust 和 Cargo
|
||||
|
||||
```bash
|
||||
$ curl -sSf https://static.rust-lang.org/rustup.sh | sh
|
||||
@@ -128,24 +127,27 @@ $ cargo run
|
||||
Hello, world!
|
||||
```
|
||||
|
||||
### 项目目录
|
||||
### 来源配置
|
||||
|
||||
```bash
|
||||
.
|
||||
├── Cargo.lock
|
||||
├── Cargo.toml
|
||||
├── benches # 基准目录
|
||||
│ └── large-input.rs
|
||||
├── examples # 示例
|
||||
│ └── simple.rs
|
||||
├── src # 源代码
|
||||
│ ├── bin
|
||||
│ │ └── another_executable.rs
|
||||
│ ├── lib.rs # 默认库
|
||||
│ └── main.rs # 入口文件
|
||||
└── tests # 集成测试
|
||||
└── some-integration-tests.rs
|
||||
```toml
|
||||
# `source` 表下,就是存储有关要更换的来源名称
|
||||
[source]
|
||||
|
||||
# 在`source` 表格之下的,可为一定数量的有关来源名称. 示例下面就,定义了一个新源, 叫 `my-awesome-source`,其内容来自本地,`vendor`目录 ,其相对于包含 `.cargo/config` 文件的目录
|
||||
[source.my-awesome-source]
|
||||
directory = "vendor"
|
||||
|
||||
# Git sources 也指定一个 branch/tag/rev
|
||||
git = "https://example.com/path/to/repo"
|
||||
# branch = "master"
|
||||
# tag = "v1.0.1"
|
||||
# rev = "313f44e8"
|
||||
|
||||
# crates.io 默认源 在"crates-io"名称下,且在这里我们使用 `replace-with` 字段指明 默认源更换成"my-awesome-source"源
|
||||
[source.crates-io]
|
||||
replace-with = "my-awesome-source"
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 编译测试
|
||||
|
||||
@@ -155,10 +157,22 @@ $ cargo build
|
||||
# 输出二进制文件,放入 `target/release` 目录
|
||||
$ cargo build --release
|
||||
$ cargo run # 编译并运行
|
||||
$ cargo test # 运行您的测试
|
||||
$ cargo test foo # 传递过滤器,来运行特定测试
|
||||
```
|
||||
|
||||
#### 测试
|
||||
|
||||
```bash
|
||||
$ cargo test # 运行你的所有测试
|
||||
# 指定函数过滤器
|
||||
$ cargo test test_foo # 开头是 test_foo 的函数都会运行,例如(test_foo_bar)
|
||||
# 指定特定模块中的测试函数(通常可以简写 cargo test foo::bar::tests::test_foo)
|
||||
$ cargo test --package rustt --lib -- foo::bar::tests::test_foo --exact --nocapture
|
||||
|
||||
# 指定特定测试的模块(通常可以简写 cargo test foo::bar::tests)
|
||||
$ cargo test --package rustt --lib -- foo::bar::tests --nocapture
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 配置目标
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
@@ -189,27 +203,24 @@ edition = '2015'
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 来源配置
|
||||
### 项目目录
|
||||
|
||||
```toml
|
||||
# `source` 表下,就是存储有关要更换的来源名称
|
||||
[source]
|
||||
|
||||
# 在`source` 表格之下的,可为一定数量的有关来源名称. 示例下面就,定义了一个新源, 叫 `my-awesome-source`,其内容来自本地,`vendor`目录 ,其相对于包含 `.cargo/config` 文件的目录
|
||||
[source.my-awesome-source]
|
||||
directory = "vendor"
|
||||
|
||||
# Git sources 也指定一个 branch/tag/rev
|
||||
git = "https://example.com/path/to/repo"
|
||||
# branch = "master"
|
||||
# tag = "v1.0.1"
|
||||
# rev = "313f44e8"
|
||||
|
||||
# crates.io 默认源 在"crates-io"名称下,且在这里我们使用 `replace-with` 字段指明 默认源更换成"my-awesome-source"源
|
||||
[source.crates-io]
|
||||
replace-with = "my-awesome-source"
|
||||
```bash
|
||||
.
|
||||
├── Cargo.lock
|
||||
├── Cargo.toml
|
||||
├── benches # 基准目录
|
||||
│ └── large-input.rs
|
||||
├── examples # 示例
|
||||
│ └── simple.rs
|
||||
├── src # 源代码
|
||||
│ ├── bin
|
||||
│ │ └── another_executable.rs
|
||||
│ ├── lib.rs # 默认库
|
||||
│ └── main.rs # 入口文件
|
||||
└── tests # 集成测试
|
||||
└── some-integration-tests.rs
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 配置
|
||||
|
||||
@@ -266,7 +277,7 @@ $ cargo install --path .
|
||||
$ cargo install --list
|
||||
```
|
||||
|
||||
----
|
||||
---
|
||||
|
||||
- `--vers version`
|
||||
- `--version version` 指定要安装的版本
|
||||
@@ -315,13 +326,13 @@ $ cargo uninstall ripgrep
|
||||
$ cargo login [options] [token]
|
||||
```
|
||||
|
||||
----
|
||||
---
|
||||
|
||||
:-|:-
|
||||
:-|:-
|
||||
`--registry` | 要使用的注册表的名称
|
||||
|
||||
----
|
||||
---
|
||||
|
||||
:-|:-
|
||||
:-|:-
|
||||
@@ -339,7 +350,8 @@ $ cargo owner --add username foo
|
||||
# 从包中删除所有者:
|
||||
$ cargo owner --remove username foo
|
||||
```
|
||||
----
|
||||
|
||||
---
|
||||
|
||||
:-|:-
|
||||
:-|:-
|
||||
@@ -384,7 +396,7 @@ $ cargo owner --remove username foo
|
||||
$ cargo package [options]
|
||||
```
|
||||
|
||||
----
|
||||
---
|
||||
|
||||
- `-l`, `--list` 输出包中包含的文件(不实际进行打包)。
|
||||
- `--no-verify` 构建包时不进行校验。
|
||||
|
@@ -107,7 +107,6 @@ d rwx r-x r-x
|
||||
| `a` | 全部,和 ugo 一样 |
|
||||
<!--rehype:className=show-header-->
|
||||
|
||||
|
||||
### 权限
|
||||
|
||||
| 缩写 | 权限 | 值 |
|
||||
@@ -138,7 +137,6 @@ Chmod 示例
|
||||
| `-` | 删除 |
|
||||
| `=` | 设置 |
|
||||
|
||||
|
||||
### chmod 600
|
||||
|
||||
```shell
|
||||
|
@@ -11,8 +11,13 @@ CMake 备忘清单
|
||||
CMake 是一个用于配置跨平台源代码项目应该如何配置的工具建立在给定的平台上。
|
||||
|
||||
```bash
|
||||
├┈ CMakeLists.txt # 希望运行的 CMake 命令
|
||||
╰┈ main.cpp # 带有 main 的源文件
|
||||
├── CMakeLists.txt # 希望运行的 CMake命令
|
||||
├── main.cpp # 带有main 的源文件
|
||||
├── include # 头文件目录
|
||||
│ └── header.h
|
||||
└── src # 源代码目录
|
||||
├── a.c
|
||||
└── b.c
|
||||
```
|
||||
|
||||
在此项目上运行 `CMake` 时,系统会要求您提供二进制目录,运行 `CMake` 不会创建最终的可执行文件,而是会为 `Visual Studio`、`XCode` 或 `makefile` 生成项目文件。 使用这些工具构建该项目
|
||||
@@ -26,6 +31,18 @@ cmake_minimum_required(VERSION 3.5)
|
||||
project (hello_cmake)
|
||||
# 添加可执行文件
|
||||
add_executable(hello_cmake main.cpp)
|
||||
# 添加头文件目录
|
||||
target_include_directories(hello_cmake PRIVATE ./include)
|
||||
# 批量添加源文件
|
||||
file(GLOB SRCS CONFIGURE_DEPENDS ./src/*.cpp)
|
||||
target_sources(hello_cmake PUBLIC ${SRCS})
|
||||
# 添加第三方库
|
||||
find_package(OpenGL CONFIG REQUIRED)
|
||||
# 链接第三方库
|
||||
target_link_libraries(hello_cmake PRIVATE OpenGL)
|
||||
# 指定输出路径
|
||||
set_property(TARGET hello_cmake ${CMAKE_SOURCE_DIR}/bin)
|
||||
|
||||
```
|
||||
|
||||
#### main.cpp
|
||||
@@ -46,6 +63,7 @@ int main(int argc, char *argv[])
|
||||
$ mkdir build # 创建 build 目录
|
||||
$ cd build # 进入目录
|
||||
$ cmake .. # 目录的上一级目录运行命令
|
||||
$ make # 使用对应的编译工具
|
||||
$ ./hello_cmake # 运行生成的 hello_cmake
|
||||
Hello CMake!
|
||||
```
|
||||
@@ -72,6 +90,12 @@ $ cmake --build <dir> [<options>] [-- <build-tool-options>]
|
||||
$ cmake --install <dir> [<options>]
|
||||
```
|
||||
|
||||
运行指定项目
|
||||
|
||||
```bash
|
||||
cmake --build <dir> --target <project>
|
||||
```
|
||||
|
||||
打开一个项目
|
||||
|
||||
```bash
|
||||
@@ -108,6 +132,30 @@ $ cmake --workflow [<options>]
|
||||
$ cmake --help[-<topic>]
|
||||
```
|
||||
|
||||
#### 常用参数
|
||||
|
||||
- 方式一: 在`CMakeLists.txt`中使用`set(KEY VAL)`函数
|
||||
- 方式二: 在执行`cmake ...` -D<arg> 指定(只需一次,推荐)
|
||||
|
||||
```cmake
|
||||
# 指定编译参数(Debug/Release/MinSizeRel/RelWithDebInfo)
|
||||
$ cmake ... -D CMAKE_BUILD_TYPE=DEBUG
|
||||
# 指定编译链工具(windows下vcpkg需要)
|
||||
$ cmake ... -D CMAKE_TOOLCHAIN_FILE=<vcpkg_path>/scripts/buildsystems/vcpkg.cmake
|
||||
# 指定编译器
|
||||
$ cmake ... -D CAMKE_C_COMPILER=...
|
||||
$ cmake ... -D CAMKE_CXX_COMPILER=...
|
||||
# 指定生成器
|
||||
$ cmake .. -G "Unix Makefile"
|
||||
$ cmake .. -G "Ninja"
|
||||
$ cmake .. -G "Visual Studio 17 2022"
|
||||
|
||||
# 设置Cpp标准
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON) # 在检测到不支持时出错
|
||||
set(CMAKE_CXX_EXTENSIONS ON) #一般设为off,否则在msvc上没有特性会出错
|
||||
```
|
||||
|
||||
另见
|
||||
----
|
||||
|
||||
|
261
docs/cocoapods.md
Normal file
261
docs/cocoapods.md
Normal file
@@ -0,0 +1,261 @@
|
||||
CocoaPods 备忘清单
|
||||
===
|
||||
|
||||
[CocoaPods](https://en.wikipedia.org/wiki/Cron) 是 [Swift](./swift.md) 和 Objective-C Cocoa 项目的依赖管理器,此快速参考备忘单显示了它的常用命令使用清单。
|
||||
|
||||
入门
|
||||
---
|
||||
|
||||
### 安装
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```bash
|
||||
$ sudo gem install cocoapods
|
||||
```
|
||||
|
||||
无 Sudo 安装,不想为此过程授予 `RubyGems` 管理员权限
|
||||
|
||||
```bash
|
||||
export GEM_HOME=$HOME/.gem
|
||||
export PATH=$GEM_HOME/bin:$PATH
|
||||
```
|
||||
|
||||
编辑 `.bash_profile` 配置文件,添加上面内容
|
||||
|
||||
```bash
|
||||
$ gem install cocoapods --user-install
|
||||
$ gem which cocoapods
|
||||
/Users/wcj/.gem/ruby/2.0.0/gems/cocoapods-0.29.0/lib/cocoapods.rb
|
||||
$ /Users/wcj/.gem/ruby/2.0.0/bin/pod install
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 更新 CocoaPods
|
||||
|
||||
```bash
|
||||
$ gem install cocoapods
|
||||
```
|
||||
|
||||
或者对于预发布版本
|
||||
|
||||
```bash
|
||||
$ gem install cocoapods --pre
|
||||
```
|
||||
|
||||
### 安装
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```bash
|
||||
$ pod install
|
||||
```
|
||||
|
||||
在您的项目中安装新的 `pod`,即使你已经有一个 `Podfile` 并且之前运行过 `pod install`; 因此,即使您只是在已经使用 `CocoaPods` 的项目中添加/删除 `pod`
|
||||
|
||||
- 会在 `Podfile.lock` 文件中为每个 pod 写入已安装的版本,此文件跟踪每个 pod 的已安装版本并锁定这些版本
|
||||
- 它只会解析 `Podfile.lock` 中尚未列出的 pod 的依赖关系
|
||||
- 对于 `Podfile.lock` 中列出的 pod,会下载 `Podfile.lock` 中列出的显式版本,而不尝试检查是否有更新的版本可用
|
||||
|
||||
下载 `Podfile` 中定义的所有依赖项,并在 `./Pods` 中创建一个 `Xcode Pods` 库项目
|
||||
|
||||
### 更新过时的依赖
|
||||
|
||||
```bash
|
||||
$ pod outdated
|
||||
```
|
||||
|
||||
显示当前 `Podfile.lock` 中过时的 `pod`,但仅显示来自规范 `repos` 的那些,而不是来自本地/外部来源的那些
|
||||
|
||||
### 更新依赖
|
||||
|
||||
```bash
|
||||
$ pod update
|
||||
$ pod update PODNAME
|
||||
```
|
||||
|
||||
更新由指定 `pod` 名称标识的 `Pod`。 如果没有指定 `Pod` 名称,它会更新所有 `Pod`,而忽略 `Podfile.lock` 的内容。 此命令保留用于更新依赖项,应使用 `pod install` 安装对 `Podfile` 的更改
|
||||
|
||||
### 清理 Pods 依赖
|
||||
|
||||
```bash
|
||||
$ pod deintegrate
|
||||
```
|
||||
|
||||
从 `CocoaPods` 中分离您的项目。 从您的 `Xcode` 项目中删除所有 `CocoaPods` 的痕迹。如果未指定 `xcodeproj`,则将在当前目录中搜索 `Xcode` 项目
|
||||
|
||||
### pod env
|
||||
|
||||
```bash
|
||||
$ pod env
|
||||
```
|
||||
|
||||
显示 pod 环境
|
||||
|
||||
### 将 Pod 添加到 Xcode 项目
|
||||
|
||||
- 创建一个 Podfile,并添加您的依赖项
|
||||
|
||||
```ruby
|
||||
# Podfile
|
||||
target 'MyApp' do
|
||||
pod 'AFNetworking', '~> 3.0'
|
||||
pod 'FBSDKCoreKit', '~> 4.9'
|
||||
end
|
||||
```
|
||||
|
||||
- 在您的项目目录中运行 `$ pod install`
|
||||
- 打开 `App.xcworkspace` 并构建
|
||||
<!--rehype:className=style-timeline-->
|
||||
|
||||
### 创建一个新的 Cocoapod
|
||||
|
||||
命令 | 说明
|
||||
:-- | --
|
||||
`pod lib create pod_name` | 为您创建一个新的 pod 项目
|
||||
`pod trunk push pod_name.podspec` | 将 podspec 推送到 trunk
|
||||
`pod spec create pod_name` | 为您创建 podspec 模板
|
||||
<!--rehype:className=style-list-->
|
||||
|
||||
### 浏览
|
||||
|
||||
- `pod search QUERY` 搜索名称、摘要、描述或作者与 QUERY 匹配的 pod,忽略大小写。 如果指定了 --simple 选项,这将只搜索 pod 的名称
|
||||
- `pod list` 列出所有可用的 pod
|
||||
- `pod try NAME|URL` 下载具有给定名称(或 Git URL)的 Pod,如果需要,安装其依赖项并打开其演示项目。 如果提供了 Git URL,则使用 repo 的头部。 如果指定了 Git URL,则可以提供 --podspec_name,如果 podspec 名称由于某种原因与 git 存储库不同
|
||||
|
||||
### 规格
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
- `pod spec create [NAME\|https://github.com/USER/REPO]` 在当前工作目录中创建一个名为 NAME.podspec 的 PodSpec。如果传递了 GitHub url,则预先填充规范。
|
||||
- `pod spec lint [NAME.podspec|DIRECTORY|http://PATH/NAME.podspec ...]` 验证 NAME.podspec。 如果提供了 DIRECTORY,它会验证找到的 podspec 文件,包括子文件夹。 如果省略参数,则默认为当前工作目录。
|
||||
- `pod spec cat [QUERY]` 将名称与 QUERY 匹配的 podspec 的内容打印到标准输出。
|
||||
- `pod spec which [QUERY]` 打印名称与 QUERY 匹配的 .podspec 文件的路径
|
||||
- `pod spec edit [QUERY]` 打开要编辑的与 QUERY 匹配的 podspec。
|
||||
|
||||
### Repos
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
命令 | 说明
|
||||
:-- | --
|
||||
`pod repo add NAME URL [BRANCH]` | 在 `~/.cocoapods/repos/` 的本地 spec-repos 目录中克隆 URL。远程可以稍后由 NAME 引用
|
||||
`pod repo update [NAME]` | 更新 spec-repo NAME 的本地克隆。如果 NAME 被省略,这将更新 ~/.cocoapods/repos 中的所有 spec-repos
|
||||
`pod repo lint [NAME\|DIRECTORY]` | 对 spec-repo NAME 进行 lints。如果提供了目录,则假定它是存储库的根目录。最后,如果没有提供 NAME,这将 lint CocoaPods 已知的所有规范库
|
||||
`pod repo list` | 从 `~/.cocoapods/repos/` 的本地 spec-repos 目录中列出 repos
|
||||
`pod repo remove NAME` | 从 `~/.cocoapods/repos/` 的本地 spec-repos 目录中删除名为 NAME 的远程
|
||||
`pod repo push REPO [NAME.podspec]` | 验证当前工作目录中的 `NAME.podspec` 或 \*.podspec,在 REPO 的本地副本 (`~/.cocoapods/repos/[REPO]`) 中为 pod 创建目录和版本文件夹,将 podspec 文件复制到版本中目录,最后它将 REPO 推送到其远程
|
||||
`pod setup` | 在 `~/.cocoapods/repos` 创建一个目录,该目录将保存您的规范存储库。它将在这里创建公共主规范仓库的克隆:<https://github.com/CocoaPods/Specs> 如果克隆已经存在,它将确保它是最新的
|
||||
<!--rehype:className=style-list-arrow-->
|
||||
|
||||
### Trunk
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
- `pod trunk add-owner POD OWNER-EMAIL` 将具有指定 OWNER-EMAIL 的注册用户添加为给定 POD 的 `owner`
|
||||
- `pod trunk info NAME` 返回有关 Pod 的信息
|
||||
- `pod trunk me` 包括有关您的注册的信息,然后是您的所有会话
|
||||
- `pod trunk push [PATH]` 在 PATH 发布 podspec 以使其可供 `master` 规范存储库的所有用户使用
|
||||
- `pod trunk register EMAIL [NAME]` 注册一个新帐户,或创建一个新会话
|
||||
- `pod trunk remove-owner POD OWNER-EMAIL` 将具有指定 OWNER-EMAIL 的用户从给定 POD 的 owner 中移除
|
||||
- `pod trunk deprecate NAME` 弃用 pod
|
||||
- `pod trunk delete NAME VERSION` *警告*:删除其他人所依赖的 Pod 版本通常被认为是不良行为!请考虑改用 <red>`deprecate`</red> 命令
|
||||
|
||||
什么是 Podfile?
|
||||
---
|
||||
|
||||
### 简单配置
|
||||
|
||||
```ruby
|
||||
target 'MyApp' do
|
||||
use_frameworks!
|
||||
pod 'Alamofire', '~> 3.0'
|
||||
end
|
||||
```
|
||||
|
||||
Podfile 可以非常简单,这会将 Alamofire 添加到单个目标
|
||||
|
||||
### 添加测试
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```ruby
|
||||
source 'https://github.com/CocoaPods/Specs.git'
|
||||
source 'https://github.com/Artsy/Specs.git'
|
||||
|
||||
platform :ios, '9.0'
|
||||
inhibit_all_warnings!
|
||||
|
||||
target 'MyApp' do
|
||||
pod 'GoogleAnalytics', '~> 3.1'
|
||||
|
||||
# 拥有自己的 OCMock 副本
|
||||
# 并且可以通过应用访问 GoogleAnalytics
|
||||
# 承载测试目标
|
||||
|
||||
target 'MyAppTests' do
|
||||
inherit! :search_paths
|
||||
pod 'OCMock', '~> 2.0.1'
|
||||
end
|
||||
end
|
||||
|
||||
post_install do |installer|
|
||||
installer.pods_project.targets.each do |target|
|
||||
puts target.name
|
||||
end
|
||||
end
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
链接应用程序及其测试包的更复杂 Podfile 的示例
|
||||
|
||||
### 指定 pod 版本
|
||||
|
||||
在开始一个项目时,希望使用最新版本的 Pod。这种情况,只需忽略版本要求
|
||||
|
||||
```ruby
|
||||
pod 'SSZipArchive'
|
||||
```
|
||||
|
||||
稍后在项目中,您可能希望冻结到特定版本的 Pod,在这种情况下,您可以指定该版本号
|
||||
|
||||
```ruby
|
||||
pod 'Objection', '0.9'
|
||||
```
|
||||
|
||||
### 隐式抽象目标
|
||||
|
||||
Podfile 的根目录存在隐式抽象目标,因此您可以将上面的示例编写为
|
||||
|
||||
```ruby
|
||||
pod 'ShowsKit'
|
||||
pod 'Fabric'
|
||||
|
||||
# 拥有自己的 ShowsKit + ShowWebAuth 副本
|
||||
target 'ShowsiOS' do
|
||||
pod 'ShowWebAuth'
|
||||
end
|
||||
|
||||
# 拥有自己的 ShowsKit + ShowTVAuth 副本
|
||||
target 'ShowsTV' do
|
||||
pod 'ShowTVAuth'
|
||||
end
|
||||
```
|
||||
|
||||
### 多个目标共享同一个 pod
|
||||
|
||||
```ruby
|
||||
# 在任何 Xcode 项目中都没有名为“Shows”的目标
|
||||
abstract_target 'Shows' do
|
||||
pod 'ShowsKit'
|
||||
pod 'Fabric'
|
||||
# 拥有自己的 ShowsKit + ShowWebAuth 副本
|
||||
target 'ShowsiOS' do
|
||||
pod 'ShowWebAuth'
|
||||
end
|
||||
# 拥有自己的 ShowsKit + ShowTVAuth 副本
|
||||
target 'ShowsTV' do
|
||||
pod 'ShowTVAuth'
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
另见
|
||||
----
|
||||
|
||||
- [CocoaPods 官方网站](https://cocoapods.org/) *(cocoapods.org)*
|
||||
- [Cocoapods Cheatsheet](https://github.com/SebastianBoldt/Cocoapods-Cheatsheet) *(github.com)*
|
@@ -6,6 +6,8 @@ CSS 定义了一大组[命名颜色](https://www.w3.org/TR/css-color-4/#named-co
|
||||
Named Colors
|
||||
---
|
||||
|
||||
<!-- markdownlint-disable MD038 -->
|
||||
|
||||
### 颜色列表
|
||||
<!--rehype:wrap-class=col-span-3&style=display:none;&wrap-style=padding-top: 0;-->
|
||||
|
||||
@@ -760,7 +762,6 @@ HSL 颜色示例
|
||||
</table>
|
||||
<!--rehype:className=show-header-->
|
||||
|
||||
|
||||
### 150° Green-Cyans
|
||||
<!--rehype:wrap-class=col-span-3-->
|
||||
|
||||
@@ -880,7 +881,6 @@ HSL 颜色示例
|
||||
</table>
|
||||
<!--rehype:className=show-header-->
|
||||
|
||||
|
||||
### 180° Cyans
|
||||
<!--rehype:wrap-class=col-span-3-->
|
||||
|
||||
@@ -1000,7 +1000,6 @@ HSL 颜色示例
|
||||
</table>
|
||||
<!--rehype:className=show-header-->
|
||||
|
||||
|
||||
### 210° Cyan-Blues
|
||||
<!--rehype:wrap-class=col-span-3-->
|
||||
|
||||
@@ -1120,7 +1119,6 @@ HSL 颜色示例
|
||||
</table>
|
||||
<!--rehype:className=show-header-->
|
||||
|
||||
|
||||
### 240° blues
|
||||
<!--rehype:wrap-class=col-span-3-->
|
||||
|
||||
@@ -1240,7 +1238,6 @@ HSL 颜色示例
|
||||
</table>
|
||||
<!--rehype:className=show-header-->
|
||||
|
||||
|
||||
### 270° Blue-Magentas
|
||||
<!--rehype:wrap-class=col-span-3-->
|
||||
|
||||
@@ -1360,7 +1357,6 @@ HSL 颜色示例
|
||||
</table>
|
||||
<!--rehype:className=show-header-->
|
||||
|
||||
|
||||
### 300° Magentas
|
||||
<!--rehype:wrap-class=col-span-3-->
|
||||
|
||||
@@ -1480,7 +1476,6 @@ HSL 颜色示例
|
||||
</table>
|
||||
<!--rehype:className=show-header-->
|
||||
|
||||
|
||||
### 330° Magenta-Reds
|
||||
<!--rehype:wrap-class=col-span-3-->
|
||||
|
||||
@@ -1600,7 +1595,6 @@ HSL 颜色示例
|
||||
</table>
|
||||
<!--rehype:className=show-header-->
|
||||
|
||||
|
||||
另见
|
||||
----
|
||||
|
||||
|
@@ -209,7 +209,6 @@ $ conan inspect boost/1.74.0
|
||||
|
||||
请参阅 [conan get](https://docs.conan.io/en/latest/reference/commands/consumer/get.html) 和 [conan inspect](https://docs.conan.io/en/latest/reference/commands/misc/inspect.html) 参考
|
||||
|
||||
|
||||
### Lockfiles
|
||||
|
||||
创建一个锁文件:
|
||||
|
792
docs/cpp.md
Normal file
792
docs/cpp.md
Normal file
@@ -0,0 +1,792 @@
|
||||
C++ 备忘清单
|
||||
===
|
||||
|
||||
提供基本语法和方法的 [C++](https://zh.cppreference.com/) 快速参考备忘单
|
||||
|
||||
入门
|
||||
--------
|
||||
|
||||
### hello.cpp
|
||||
|
||||
```cpp
|
||||
#include <iostream>
|
||||
int main() {
|
||||
std::cout << "Hello Quick Reference\n";
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
编译运行
|
||||
|
||||
```shell
|
||||
$ g++ hello.cpp -o hello
|
||||
$ ./hello
|
||||
Hello Quick Reference
|
||||
```
|
||||
|
||||
### 变量
|
||||
|
||||
```cpp
|
||||
int number = 5; // 整数
|
||||
float f = 0.95; // 浮点数
|
||||
double PI = 3.14159; // 浮点数
|
||||
char yes = 'Y'; // 特点
|
||||
std::string s = "ME"; // 字符串(文本)
|
||||
bool isRight = true; // 布尔值
|
||||
// 常量
|
||||
const float RATE = 0.8;
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
```cpp
|
||||
int age {25}; // 自 C++11
|
||||
std::cout << age; // 打印 25
|
||||
```
|
||||
|
||||
### 原始数据类型
|
||||
|
||||
数据类型 | 大小 | 范围
|
||||
:- | -- | --
|
||||
`int` | 4 bytes | -2<sup>31</sup> 到 2<sup>31</sup>-1
|
||||
`float` | 4 bytes | _N/A_
|
||||
`double` | 8 bytes | _N/A_
|
||||
`char` | 1 byte | -128 到 127
|
||||
`bool` | 1 byte | `true` / `false`
|
||||
`void` | _N/A_ | _N/A_
|
||||
`wchar_t` | 2 到 4 bytes | 1 个宽字符
|
||||
<!--rehype:className=show-header-->
|
||||
|
||||
### 用户输入
|
||||
|
||||
```cpp
|
||||
int num;
|
||||
std::cout << "Type a number: ";
|
||||
std::cin >> num;
|
||||
std::cout << "You entered " << num;
|
||||
```
|
||||
|
||||
### 交换
|
||||
|
||||
```cpp
|
||||
int a = 5, b = 10;
|
||||
std::swap(a, b);
|
||||
// 输出: a=10, b=5
|
||||
std::cout << "a=" << a << ", b=" << b;
|
||||
```
|
||||
|
||||
### 注释
|
||||
|
||||
```cpp
|
||||
// C++中的单行注释
|
||||
/* 这是一个多行注释
|
||||
在 C++ 中 */
|
||||
```
|
||||
|
||||
### If 语句
|
||||
|
||||
```cpp
|
||||
if (a == 10) {
|
||||
// do something
|
||||
}
|
||||
```
|
||||
|
||||
查看: [条件](#c-条件)
|
||||
|
||||
### 循环
|
||||
|
||||
```cpp
|
||||
for (int i = 0; i < 10; i++) {
|
||||
std::cout << i << "\n";
|
||||
}
|
||||
```
|
||||
|
||||
查看: [循环 Loops](#c-循环)
|
||||
|
||||
### 函数
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```cpp
|
||||
#include <iostream>
|
||||
|
||||
void hello(); // 声明
|
||||
|
||||
int main() { // 主函数
|
||||
hello(); // 执行函数
|
||||
}
|
||||
|
||||
void hello() { // 定义
|
||||
std::cout << "Hello Quick Reference!\n";
|
||||
}
|
||||
```
|
||||
|
||||
查看: [函数 Functions](#c-函数)
|
||||
|
||||
### 引用
|
||||
|
||||
```cpp
|
||||
int i = 1;
|
||||
int& ri = i; // ri 是对 i 的引用
|
||||
ri = 2; // i 现在改为 2
|
||||
std::cout << "i=" << i;
|
||||
i = 3; // i 现在改为 3
|
||||
std::cout << "ri=" << ri;
|
||||
```
|
||||
|
||||
`ri` 和 `i` 指的是相同的内存位置
|
||||
|
||||
### 命名空间
|
||||
|
||||
```cpp
|
||||
#include <iostream>
|
||||
namespace ns1 {int val(){return 5;}}
|
||||
int main()
|
||||
{
|
||||
std::cout << ns1::val();
|
||||
}
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
```cpp
|
||||
#include <iostream>
|
||||
namespace ns1 {int val(){return 5;}}
|
||||
using namespace ns1;
|
||||
using namespace std;
|
||||
int main()
|
||||
{
|
||||
cout << val();
|
||||
}
|
||||
```
|
||||
|
||||
名称空间允许名称下的全局标识符
|
||||
|
||||
C++ 数组
|
||||
------
|
||||
|
||||
### 定义
|
||||
|
||||
```cpp
|
||||
std::array<int, 3> marks; // 定义
|
||||
marks[0] = 92;
|
||||
marks[1] = 97;
|
||||
marks[2] = 98;
|
||||
// 定义和初始化
|
||||
std::array<int, 3> = {92, 97, 98};
|
||||
// 有空成员
|
||||
std::array<int, 3> marks = {92, 97};
|
||||
std::cout << marks[2]; // 输出: 0
|
||||
```
|
||||
|
||||
### 操控
|
||||
|
||||
```cpp
|
||||
┌─────┬─────┬─────┬─────┬─────┬─────┐
|
||||
| 92 | 97 | 98 | 99 | 98 | 94 |
|
||||
└─────┴─────┴─────┴─────┴─────┴─────┘
|
||||
0 1 2 3 4 5
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
```cpp
|
||||
std::array<int, 6> marks = {
|
||||
92, 97, 98, 99, 98, 94
|
||||
};
|
||||
// 打印第一个元素
|
||||
std::cout << marks[0];
|
||||
// 将第 2 个元素更改为 99
|
||||
marks[1] = 99;
|
||||
// 从用户那里获取输入
|
||||
std::cin >> marks[2];
|
||||
```
|
||||
|
||||
### 展示
|
||||
|
||||
```cpp
|
||||
char ref[5] = {'R', 'e', 'f'};
|
||||
// 基于范围的for循环
|
||||
for (const int &n : ref) {
|
||||
std::cout << std::string(1, n);
|
||||
}
|
||||
// 传统的for循环
|
||||
for (int i = 0; i < sizeof(ref); ++i) {
|
||||
std::cout << ref[i];
|
||||
}
|
||||
```
|
||||
|
||||
### 多维
|
||||
|
||||
```cpp
|
||||
j0 j1 j2 j3 j4 j5
|
||||
┌────┬────┬────┬────┬────┬────┐
|
||||
i0 | 1 | 2 | 3 | 4 | 5 | 6 |
|
||||
├────┼────┼────┼────┼────┼────┤
|
||||
i1 | 6 | 5 | 4 | 3 | 2 | 1 |
|
||||
└────┴────┴────┴────┴────┴────┘
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
```cpp
|
||||
int x[2][6] = {
|
||||
{1,2,3,4,5,6}, {6,5,4,3,2,1}
|
||||
};
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
for (int j = 0; j < 6; ++j) {
|
||||
std::cout << x[i][j] << " ";
|
||||
}
|
||||
}
|
||||
// 输出: 1 2 3 4 5 6 6 5 4 3 2 1
|
||||
```
|
||||
|
||||
C++ 条件
|
||||
------------
|
||||
|
||||
### If Clause
|
||||
|
||||
```cpp
|
||||
if (a == 10) {
|
||||
// do something
|
||||
}
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
```cpp
|
||||
int number = 16;
|
||||
if (number % 2 == 0)
|
||||
{
|
||||
std::cout << "even";
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "odd";
|
||||
}
|
||||
// 输出: even
|
||||
```
|
||||
|
||||
### Else if 语句
|
||||
|
||||
```cpp
|
||||
int score = 99;
|
||||
if (score == 100) {
|
||||
std::cout << "Superb";
|
||||
}
|
||||
else if (score >= 90) {
|
||||
std::cout << "Excellent";
|
||||
}
|
||||
else if (score >= 80) {
|
||||
std::cout << "Very Good";
|
||||
}
|
||||
else if (score >= 70) {
|
||||
std::cout << "Good";
|
||||
}
|
||||
else if (score >= 60)
|
||||
std::cout << "OK";
|
||||
else
|
||||
std::cout << "What?";
|
||||
```
|
||||
|
||||
### 运算符
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
#### 关系运算符
|
||||
|
||||
:--|--
|
||||
:--|--
|
||||
`a == b` | a 等于 b
|
||||
`a != b` | a 不等于 b
|
||||
`a < b` | a 小于 b
|
||||
`a > b` | a 大于 b
|
||||
`a <= b` | a 小于或等于 b
|
||||
`a >= b` | a 大于或等于 b
|
||||
|
||||
#### 赋值运算符
|
||||
|
||||
范例 | 相当于
|
||||
:--|--
|
||||
`a += b` | _Aka_ `a = a + b`
|
||||
`a -= b` | _Aka_ `a = a - b`
|
||||
`a *= b` | _Aka_ `a = a * b`
|
||||
`a /= b` | _Aka_ `a = a / b`
|
||||
`a %= b` | _Aka_ `a = a % b`
|
||||
|
||||
#### 逻辑运算符
|
||||
|
||||
| Example | Meaning |
|
||||
|----------------|------------------------|
|
||||
| `exp1 && exp2` | Both are true _(AND)_ |
|
||||
| `exp1 || exp2` | Either is true _(OR)_ |
|
||||
| `!exp` | `exp` is false _(NOT)_ |
|
||||
|
||||
#### 位运算符
|
||||
|
||||
| Operator | Description |
|
||||
|----------|-------------------------|
|
||||
| `a & b` | Binary AND |
|
||||
| `a | b` | Binary OR |
|
||||
| `a ^ b` | Binary XOR |
|
||||
| `a ~ b` | Binary One's Complement |
|
||||
| `a << b` | Binary Shift Left |
|
||||
| `a >> b` | Binary Shift Right |
|
||||
|
||||
### 三元运算符
|
||||
|
||||
```
|
||||
┌── True ──┐
|
||||
Result = Condition ? Exp1 : Exp2;
|
||||
└───── False ─────┘
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
```cpp
|
||||
int x = 3, y = 5, max;
|
||||
max = (x > y) ? x : y;
|
||||
// 输出: 5
|
||||
std::cout << max << std::endl;
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
```cpp
|
||||
int x = 3, y = 5, max;
|
||||
if (x > y) {
|
||||
max = x;
|
||||
} else {
|
||||
max = y;
|
||||
}
|
||||
// 输出: 5
|
||||
std::cout << max << std::endl;
|
||||
```
|
||||
|
||||
### switch 语句
|
||||
|
||||
```cpp
|
||||
int num = 2;
|
||||
switch (num) {
|
||||
case 0:
|
||||
std::cout << "Zero";
|
||||
break;
|
||||
case 1:
|
||||
std::cout << "One";
|
||||
break;
|
||||
case 2:
|
||||
std::cout << "Two";
|
||||
break;
|
||||
case 3:
|
||||
std::cout << "Three";
|
||||
break;
|
||||
default:
|
||||
std::cout << "What?";
|
||||
break;
|
||||
}
|
||||
```
|
||||
|
||||
C++ 循环
|
||||
------------
|
||||
|
||||
### While
|
||||
|
||||
```cpp
|
||||
int i = 0;
|
||||
while (i < 6) {
|
||||
std::cout << i++;
|
||||
}
|
||||
// 输出: 012345
|
||||
```
|
||||
|
||||
### Do-while
|
||||
|
||||
```cpp
|
||||
int i = 1;
|
||||
do {
|
||||
std::cout << i++;
|
||||
} while (i <= 5);
|
||||
// 输出: 12345
|
||||
```
|
||||
|
||||
### Continue 语句
|
||||
|
||||
```cpp
|
||||
for (int i = 0; i < 10; i++) {
|
||||
if (i % 2 == 0) {
|
||||
continue;
|
||||
}
|
||||
std::cout << i;
|
||||
} // 输出: 13579
|
||||
```
|
||||
|
||||
### 无限循环
|
||||
|
||||
```cpp
|
||||
while (true) { // true or 1
|
||||
std::cout << "无限循环";
|
||||
}
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
```cpp
|
||||
for (;;) {
|
||||
std::cout << "无限循环";
|
||||
}
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
```cpp
|
||||
for(int i = 1; i > 0; i++) {
|
||||
std::cout << "infinite loop";
|
||||
}
|
||||
```
|
||||
|
||||
### for_each (C++11 起)
|
||||
|
||||
```cpp
|
||||
#include <iostream>
|
||||
int main()
|
||||
{
|
||||
auto print = [](int num) {
|
||||
std::cout << num << std::endl;
|
||||
};
|
||||
std::array<int, 4> arr = {1, 2, 3, 4};
|
||||
std::for_each(arr.begin(), arr.end(), print);
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 基于范围 (C++11 起)
|
||||
|
||||
```cpp
|
||||
for (int n : {1, 2, 3, 4, 5}) {
|
||||
std::cout << n << " ";
|
||||
}
|
||||
// 输出: 1 2 3 4 5
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
```cpp
|
||||
std::string hello = "Quick Reference.ME";
|
||||
for (char c: hello)
|
||||
{
|
||||
std::cout << c << " ";
|
||||
}
|
||||
// 输出: Q u i c k R e f . M E
|
||||
```
|
||||
|
||||
### 中断语句
|
||||
|
||||
```cpp
|
||||
int password, times = 0;
|
||||
while (password != 1234) {
|
||||
if (times++ >= 3) {
|
||||
std::cout << "Locked!\n";
|
||||
break;
|
||||
}
|
||||
std::cout << "Password: ";
|
||||
std::cin >> password; // input
|
||||
}
|
||||
```
|
||||
|
||||
### Several variations
|
||||
|
||||
```cpp
|
||||
for (int i = 0, j = 2; i < 3; i++, j--){
|
||||
std::cout << "i=" << i << ",";
|
||||
std::cout << "j=" << j << ";";
|
||||
}
|
||||
// 输出: i=0,j=2;i=1,j=1;i=2,j=0;
|
||||
```
|
||||
|
||||
C++ 函数
|
||||
------------
|
||||
|
||||
### 参数和返回
|
||||
|
||||
```cpp
|
||||
#include <iostream>
|
||||
int add(int a, int b) {
|
||||
return a + b;
|
||||
}
|
||||
int main() {
|
||||
std::cout << add(10, 20);
|
||||
}
|
||||
```
|
||||
|
||||
`add` 是一个接受 2 个整数并返回整数的函数
|
||||
|
||||
### 重载
|
||||
|
||||
```cpp
|
||||
void fun(string a, string b) {
|
||||
std::cout << a + " " + b;
|
||||
}
|
||||
void fun(string a) {
|
||||
std::cout << a;
|
||||
}
|
||||
void fun(int a) {
|
||||
std::cout << a;
|
||||
}
|
||||
```
|
||||
|
||||
### 内置函数
|
||||
|
||||
```cpp
|
||||
#include <iostream>
|
||||
#include <cmath> // 导入库
|
||||
|
||||
int main() {
|
||||
// sqrt() 来自 cmath
|
||||
std::cout << sqrt(9);
|
||||
}
|
||||
```
|
||||
|
||||
C++ 预处理器
|
||||
------------
|
||||
|
||||
### 预处理器
|
||||
<!--rehype:wrap-class=row-span-3-->
|
||||
|
||||
- [if](https://zh.cppreference.com/w/cpp/preprocessor/conditional)
|
||||
- [elif](https://zh.cppreference.com/w/cpp/preprocessor/conditional)
|
||||
- [else](https://zh.cppreference.com/w/cpp/preprocessor/conditional)
|
||||
- [endif](https://zh.cppreference.com/w/cpp/preprocessor/conditional)
|
||||
- [ifdef](https://zh.cppreference.com/w/cpp/preprocessor/conditional)
|
||||
- [ifndef](https://zh.cppreference.com/w/cpp/preprocessor/conditional)
|
||||
- [define](https://zh.cppreference.com/w/cpp/preprocessor/replace)
|
||||
- [undef](https://zh.cppreference.com/w/cpp/preprocessor/replace)
|
||||
- [include](https://zh.cppreference.com/w/cpp/preprocessor/include)
|
||||
- [line](https://zh.cppreference.com/w/cpp/preprocessor/line)
|
||||
- [error](https://zh.cppreference.com/w/cpp/preprocessor/error)
|
||||
- [pragma](https://zh.cppreference.com/w/cpp/preprocessor/impl)
|
||||
- [defined](https://zh.cppreference.com/w/cpp/preprocessor/conditional)
|
||||
- [__has_include](https://zh.cppreference.com/w/cpp/feature_test)
|
||||
- [__has_cpp_attribute](https://zh.cppreference.com/w/cpp/feature_test)
|
||||
- [export](https://zh.cppreference.com/w/cpp/keyword/export)
|
||||
- [import](https://zh.cppreference.com/mwiki/index.php?title=cpp/keyword/import&action=edit&redlink=1)
|
||||
- [module](https://zh.cppreference.com/mwiki/index.php?title=cpp/keyword/module&action=edit&redlink=1)
|
||||
<!--rehype:className=style-none cols-2-->
|
||||
|
||||
### Includes
|
||||
|
||||
```cpp
|
||||
#include "iostream"
|
||||
#include <iostream>
|
||||
```
|
||||
|
||||
### Defines
|
||||
|
||||
```cpp
|
||||
#define FOO
|
||||
#define FOO "hello"
|
||||
#undef FOO
|
||||
```
|
||||
|
||||
### If
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```cpp
|
||||
#ifdef DEBUG
|
||||
console.log('hi');
|
||||
#elif defined VERBOSE
|
||||
...
|
||||
#else
|
||||
...
|
||||
#endif
|
||||
```
|
||||
|
||||
### Error
|
||||
|
||||
```cpp
|
||||
#if VERSION == 2.0
|
||||
#error Unsupported
|
||||
#warning Not really supported
|
||||
#endif
|
||||
```
|
||||
|
||||
### 宏
|
||||
|
||||
```cpp
|
||||
#define DEG(x) ((x) * 57.29)
|
||||
```
|
||||
|
||||
### 令牌连接
|
||||
|
||||
```cpp
|
||||
#define DST(name) name##_s name##_t
|
||||
DST(object); #=> object_s object_t;
|
||||
```
|
||||
|
||||
### 字符串化
|
||||
|
||||
```cpp
|
||||
#define STR(name) #name
|
||||
char * a = STR(object); #=> char * a = "object";
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 文件和行
|
||||
|
||||
```cpp
|
||||
#define LOG(msg) console.log(__FILE__, __LINE__, msg)
|
||||
#=> console.log("file.txt", 3, "hey")
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
各种各样的
|
||||
-------------
|
||||
|
||||
### 转义序列
|
||||
|
||||
转义序列 | 说明
|
||||
:--|--
|
||||
`\b` | 退格键
|
||||
`\f` | 换页
|
||||
`\n` | 换行
|
||||
`\r` | 返回
|
||||
`\t` | 水平制表符
|
||||
`\v` | 垂直制表符
|
||||
`\\` | 反斜杠
|
||||
`\'` | 单引号
|
||||
`\"` | 双引号
|
||||
`\?` | 问号
|
||||
`\0` | 空字符
|
||||
|
||||
### 关键字
|
||||
<!--rehype:wrap-class=row-span-2 col-span-2-->
|
||||
|
||||
- [alignas](https://zh.cppreference.com/w/cpp/keyword/alignas)
|
||||
- [alignof](https://zh.cppreference.com/w/cpp/keyword/alignof)
|
||||
- [and](https://zh.cppreference.com/w/cpp/keyword/and)
|
||||
- [and_eq](https://zh.cppreference.com/w/cpp/keyword/and_eq)
|
||||
- [asm](https://zh.cppreference.com/w/cpp/keyword/asm)
|
||||
- [atomic_cancel](https://zh.cppreference.com/w/cpp/keyword/atomic_cancel)
|
||||
- [atomic_commit](https://zh.cppreference.com/w/cpp/keyword/atomic_commit)
|
||||
- [atomic_noexcept](https://zh.cppreference.com/w/cpp/keyword/atomic_noexcept)
|
||||
- [auto](https://zh.cppreference.com/w/cpp/keyword/auto)
|
||||
- [bitand](https://zh.cppreference.com/w/cpp/keyword/bitand)
|
||||
- [bitor](https://zh.cppreference.com/w/cpp/keyword/bitor)
|
||||
- [bool](https://zh.cppreference.com/w/cpp/keyword/bool)
|
||||
- [break](https://zh.cppreference.com/w/cpp/keyword/break)
|
||||
- [case](https://zh.cppreference.com/w/cpp/keyword/case)
|
||||
- [catch](https://zh.cppreference.com/w/cpp/keyword/catch)
|
||||
- [char](https://zh.cppreference.com/w/cpp/keyword/char)
|
||||
- [char8_t](https://zh.cppreference.com/w/cpp/keyword/char8_t)
|
||||
- [char16_t](https://zh.cppreference.com/w/cpp/keyword/char16_t)
|
||||
- [char32_t](https://zh.cppreference.com/w/cpp/keyword/char32_t)
|
||||
- [class](https://zh.cppreference.com/w/cpp/keyword/class)
|
||||
- [compl](https://zh.cppreference.com/w/cpp/keyword/compl)
|
||||
- [concept](https://zh.cppreference.com/w/cpp/keyword/concept)
|
||||
- [const](https://zh.cppreference.com/w/cpp/keyword/const)
|
||||
- [consteval](https://zh.cppreference.com/w/cpp/keyword/consteval)
|
||||
- [constexpr](https://zh.cppreference.com/w/cpp/keyword/constexpr)
|
||||
- [constinit](https://zh.cppreference.com/w/cpp/keyword/constinit)
|
||||
- [const_cast](https://zh.cppreference.com/w/cpp/keyword/const_cast)
|
||||
- [continue](https://zh.cppreference.com/w/cpp/keyword/continue)
|
||||
- [co_await](https://zh.cppreference.com/w/cpp/keyword/co_await)
|
||||
- [co_return](https://zh.cppreference.com/w/cpp/keyword/co_return)
|
||||
- [co_yield](https://zh.cppreference.com/w/cpp/keyword/co_yield)
|
||||
- [decltype](https://zh.cppreference.com/w/cpp/keyword/decltype)
|
||||
- [default](https://zh.cppreference.com/w/cpp/keyword/default)
|
||||
- [delete](https://zh.cppreference.com/w/cpp/keyword/delete)
|
||||
- [do](https://zh.cppreference.com/w/cpp/keyword/do)
|
||||
- [double](https://zh.cppreference.com/w/cpp/keyword/double)
|
||||
- [dynamic_cast](https://zh.cppreference.com/w/cpp/keyword/dynamic_cast)
|
||||
- [else](https://zh.cppreference.com/w/cpp/keyword/else)
|
||||
- [enum](https://zh.cppreference.com/w/cpp/keyword/enum)
|
||||
- [explicit](https://zh.cppreference.com/w/cpp/keyword/explicit)
|
||||
- [export](https://zh.cppreference.com/w/cpp/keyword/export)
|
||||
- [extern](https://zh.cppreference.com/w/cpp/keyword/extern)
|
||||
- [false](https://zh.cppreference.com/w/cpp/keyword/false)
|
||||
- [float](https://zh.cppreference.com/w/cpp/keyword/float)
|
||||
- [for](https://zh.cppreference.com/w/cpp/keyword/for)
|
||||
- [friend](https://zh.cppreference.com/w/cpp/keyword/friend)
|
||||
- [goto](https://zh.cppreference.com/w/cpp/keyword/goto)
|
||||
- [if](https://zh.cppreference.com/w/cpp/keyword/if)
|
||||
- [inline](https://zh.cppreference.com/w/cpp/keyword/inline)
|
||||
- [int](https://zh.cppreference.com/w/cpp/keyword/int)
|
||||
- [long](https://zh.cppreference.com/w/cpp/keyword/long)
|
||||
- [mutable](https://zh.cppreference.com/w/cpp/keyword/mutable)
|
||||
- [namespace](https://zh.cppreference.com/w/cpp/keyword/namespace)
|
||||
- [new](https://zh.cppreference.com/w/cpp/keyword/new)
|
||||
- [noexcept](https://zh.cppreference.com/w/cpp/keyword/noexcept)
|
||||
- [not](https://zh.cppreference.com/w/cpp/keyword/not)
|
||||
- [not_eq](https://zh.cppreference.com/w/cpp/keyword/not_eq)
|
||||
- [nullptr](https://zh.cppreference.com/w/cpp/keyword/nullptr)
|
||||
- [operator](https://zh.cppreference.com/w/cpp/keyword/operator)
|
||||
- [or](https://zh.cppreference.com/w/cpp/keyword/or)
|
||||
- [or_eq](https://zh.cppreference.com/w/cpp/keyword/or_eq)
|
||||
- [private](https://zh.cppreference.com/w/cpp/keyword/private)
|
||||
- [protected](https://zh.cppreference.com/w/cpp/keyword/protected)
|
||||
- [public](https://zh.cppreference.com/w/cpp/keyword/public)
|
||||
- [reflexpr](https://zh.cppreference.com/w/cpp/keyword/reflexpr)
|
||||
- [register](https://zh.cppreference.com/w/cpp/keyword/register)
|
||||
- [reinterpret_cast](https://zh.cppreference.com/w/cpp/keyword/reinterpret_cast)
|
||||
- [requires](https://zh.cppreference.com/w/cpp/keyword/requires)
|
||||
- [return](https://zh.cppreference.com/w/cpp/language/return)
|
||||
- [short](https://zh.cppreference.com/w/cpp/keyword/short)
|
||||
- [signed](https://zh.cppreference.com/w/cpp/keyword/signed)
|
||||
- [sizeof](https://zh.cppreference.com/w/cpp/keyword/sizeof)
|
||||
- [static](https://zh.cppreference.com/w/cpp/keyword/static)
|
||||
- [static_assert](https://zh.cppreference.com/w/cpp/keyword/static_assert)
|
||||
- [static_cast](https://zh.cppreference.com/w/cpp/keyword/static_cast)
|
||||
- [struct](https://zh.cppreference.com/w/cpp/keyword/struct)
|
||||
- [switch](https://zh.cppreference.com/w/cpp/keyword/switch)
|
||||
- [synchronized](https://zh.cppreference.com/w/cpp/keyword/synchronized)
|
||||
- [template](https://zh.cppreference.com/w/cpp/keyword/template)
|
||||
- [this](https://zh.cppreference.com/w/cpp/keyword/this)
|
||||
- [thread_local](https://zh.cppreference.com/w/cpp/keyword/thread_local)
|
||||
- [throw](https://zh.cppreference.com/w/cpp/keyword/throw)
|
||||
- [true](https://zh.cppreference.com/w/cpp/keyword/true)
|
||||
- [try](https://zh.cppreference.com/w/cpp/keyword/try)
|
||||
- [typedef](https://zh.cppreference.com/w/cpp/keyword/typedef)
|
||||
- [typeid](https://zh.cppreference.com/w/cpp/keyword/typeid)
|
||||
- [typename](https://zh.cppreference.com/w/cpp/keyword/typename)
|
||||
- [union](https://zh.cppreference.com/w/cpp/keyword/union)
|
||||
- [unsigned](https://zh.cppreference.com/w/cpp/keyword/unsigned)
|
||||
- [using](https://zh.cppreference.com/w/cpp/keyword/using)
|
||||
- [virtual](https://zh.cppreference.com/w/cpp/keyword/virtual)
|
||||
- [void](https://zh.cppreference.com/w/cpp/keyword/void)
|
||||
- [volatile](https://zh.cppreference.com/w/cpp/keyword/volatile)
|
||||
- [wchar_t](https://zh.cppreference.com/w/cpp/keyword/wchar_t)
|
||||
- [while](https://zh.cppreference.com/w/cpp/keyword/while)
|
||||
- [xor](https://zh.cppreference.com/w/cpp/keyword/xor)
|
||||
- [xor_eq](https://zh.cppreference.com/w/cpp/keyword/xor_eq)
|
||||
- [final](https://zh.cppreference.com/w/cpp/language/final)
|
||||
- [override](https://zh.cppreference.com/w/cpp/language/override)
|
||||
- [transaction_safe](https://zh.cppreference.com/w/cpp/language/transactional_memory)
|
||||
- [transaction_safe_dynamic](https://zh.cppreference.com/w/cpp/language/transactional_memory)
|
||||
<!--rehype:className=style-none cols-5-->
|
||||
|
||||
### 预处理器
|
||||
|
||||
- [if](https://zh.cppreference.com/w/cpp/preprocessor/conditional)
|
||||
- [elif](https://zh.cppreference.com/w/cpp/preprocessor/conditional)
|
||||
- [else](https://zh.cppreference.com/w/cpp/preprocessor/conditional)
|
||||
- [endif](https://zh.cppreference.com/w/cpp/preprocessor/conditional)
|
||||
- [ifdef](https://zh.cppreference.com/w/cpp/preprocessor/conditional)
|
||||
- [ifndef](https://zh.cppreference.com/w/cpp/preprocessor/conditional)
|
||||
- [define](https://zh.cppreference.com/w/cpp/preprocessor/replace)
|
||||
- [undef](https://zh.cppreference.com/w/cpp/preprocessor/replace)
|
||||
- [include](https://zh.cppreference.com/w/cpp/preprocessor/include)
|
||||
- [line](https://zh.cppreference.com/w/cpp/preprocessor/line)
|
||||
- [error](https://zh.cppreference.com/w/cpp/preprocessor/error)
|
||||
- [pragma](https://zh.cppreference.com/w/cpp/preprocessor/impl)
|
||||
- [defined](https://zh.cppreference.com/w/cpp/preprocessor/conditional)
|
||||
- [__has_include](https://zh.cppreference.com/w/cpp/feature_test)
|
||||
- [__has_cpp_attribute](https://zh.cppreference.com/w/cpp/feature_test)
|
||||
- [export](https://zh.cppreference.com/w/cpp/keyword/export)
|
||||
- [import](https://zh.cppreference.com/mwiki/index.php?title=cpp/keyword/import&action=edit&redlink=1)
|
||||
- [module](https://zh.cppreference.com/mwiki/index.php?title=cpp/keyword/module&action=edit&redlink=1)
|
||||
<!--rehype:className=style-none cols-2-->
|
||||
|
||||
另见
|
||||
----
|
||||
|
||||
- [C++ Infographics & Cheat Sheets](https://hackingcpp.com/cpp/cheat_sheets.html) _(hackingcpp.com)_
|
||||
- [C++ reference](https://zh.cppreference.com/w/) _(cppreference.com)_
|
||||
- [C++ Language Tutorials](http://www.cplusplus.com/doc/tutorial/) _(cplusplus.com)_
|
71
docs/cron.md
71
docs/cron.md
@@ -1,7 +1,6 @@
|
||||
Cron 备忘清单
|
||||
===
|
||||
|
||||
|
||||
[Cron](https://en.wikipedia.org/wiki/Cron) 最适合安排重复性任务。 可以使用关联的 at 实用程序来完成一次性任务的调度。
|
||||
|
||||
Crontab 格式
|
||||
@@ -17,8 +16,8 @@ Min Hour Day Mon Weekday
|
||||
|
||||
-------
|
||||
|
||||
```
|
||||
* * * * * 要执行的命令
|
||||
```bash
|
||||
* * * * * <要执行的命令>
|
||||
┬ ┬ ┬ ┬ ┬
|
||||
│ │ │ │ └─ 星期几 (0=周日 .. 6=星期六)
|
||||
│ │ │ └────── 月 (1..12)
|
||||
@@ -27,18 +26,18 @@ Min Hour Day Mon Weekday
|
||||
└───────────────────── 分钟 (0..59)
|
||||
```
|
||||
|
||||
------
|
||||
-------
|
||||
|
||||
| 字段 | 范围 | 特殊字符 |
|
||||
|--------------|--------|--------------------|
|
||||
| 分钟 Minute | 0 - 59 | , - * / |
|
||||
| 小时 Hour | 0 - 23 | , - * / |
|
||||
| 月份中的某天 | 1 - 31 | , - * ? / L W |
|
||||
| 月 Month | 1 - 12 | , - * / |
|
||||
| 星期几 | 0 - 6 | , - * ? / L # |
|
||||
| 分钟 Minute | 0 - 59 | <kbd>,</kbd> <kbd>-</kbd> <kbd>*</kbd> <kbd>/</kbd>
|
||||
| 小时 Hour | 0 - 23 | <kbd>,</kbd> <kbd>-</kbd> <kbd>*</kbd> <kbd>/</kbd>
|
||||
| 月份中的某天 | 1 - 31 | <kbd>,</kbd> <kbd>-</kbd> <kbd>*</kbd> <kbd>?</kbd> <kbd>/</kbd> <kbd>L</kbd> <kbd>W</kbd>
|
||||
| 月 Month | 1 - 12 | <kbd>,</kbd> <kbd>-</kbd> <kbd>*</kbd> <kbd>/</kbd>
|
||||
| 星期几 | 0 - 6 | <kbd>,</kbd> <kbd>-</kbd> <kbd>*</kbd> <kbd>?</kbd> <kbd>/</kbd> <kbd>L</kbd> <kbd>#</kbd>
|
||||
| 年 Year | 1970–2099 | <kbd>,</kbd> <kbd>-</kbd>
|
||||
<!--rehype:className=show-header-->
|
||||
|
||||
|
||||
### 示例
|
||||
|
||||
| Example | Description |
|
||||
@@ -52,36 +51,38 @@ Min Hour Day Mon Weekday
|
||||
| `0 0 * * 0` | 每个星期日的午夜 |
|
||||
| `15 2 * * 1L` | 每月最后一个星期一凌晨 2 点 15 分 |
|
||||
| `15 0 * * 4#2` | 每个月的第二个星期四早上 00:15 |
|
||||
| `0 0 0 1 * *` | 每个月的 1 日(每月) |
|
||||
| `0 0 0 1 1 *` | 每年 1 月 1 日(每年) |
|
||||
| `0 0 0 1 * *` | 每个月的 1 日(每月) |
|
||||
| `0 0 0 1 1 *` | 每年 1 月 1 日(每年) |
|
||||
| `@reboot` | 每次重启 _(非标准)_ |
|
||||
|
||||
|
||||
### 特殊字符串
|
||||
|
||||
| 特殊字符串 | 意义 |
|
||||
|----------------|----------------------------------------------------|
|
||||
| @reboot | 运行一次,在系统启动时 _(非标准)_ |
|
||||
| @yearly | 每年运行一次,“0 0 1 1 *” _(非标准)_ |
|
||||
| @annually | (与@yearly 相同)_(非标准)_ |
|
||||
| @monthly | 每月运行一次,“0 0 1 * *” _(非标准)_ |
|
||||
| @weekly | 每周运行一次,“0 0 * * 0” _(非标准)_ |
|
||||
| @daily | 每天运行一次,“0 0 * * *” _(非标准)_ |
|
||||
| @midnight | (与@daily 相同)_(非标准)_ |
|
||||
| @hourly | 每小时运行一次,“0 * * * *” _(非标准)_ |
|
||||
| @reboot | 运行一次,在系统启动时 _(非标准)_ |
|
||||
| @yearly | 每年运行一次,“0 0 1 1 *” _(非标准)_ |
|
||||
| @annually | (与@yearly 相同)_(非标准)_ |
|
||||
| @monthly | 每月运行一次,“0 0 1 \* \*” _(非标准)_ |
|
||||
| @weekly | 每周运行一次,“0 0 \* \* 0” _(非标准)_ |
|
||||
| @daily | 每天运行一次,“0 0 \* \* \*” _(非标准)_ |
|
||||
| @midnight | (与@daily 相同)_(非标准)_ |
|
||||
| @hourly | 每小时运行一次,“0 \* \* \* \*” _(非标准)_ |
|
||||
<!--rehype:className=show-header -->
|
||||
|
||||
|
||||
### Crontab 命令
|
||||
|
||||
| - | - |
|
||||
|--------------|---------------------------------------------|
|
||||
| `crontab -e` | 如果不存在,则编辑或创建一个 crontab 文件。 |
|
||||
| `crontab -l` | 显示 crontab 文件。 |
|
||||
| `crontab -r` | 删除 crontab 文件。 |
|
||||
| `crontab -v` | 显示您上次编辑 crontab 文件的时间。 _(非标准)_ |
|
||||
| `echo "@reboot echo hi" | crontab` | 轻松添加任务 |
|
||||
| `crontab -e` | 如果不存在,则编辑或创建一个 crontab 文件 |
|
||||
| `crontab -l` | 显示 crontab 文件 |
|
||||
| `crontab -r` | 删除 crontab 文件 |
|
||||
| `crontab -v` | 显示您上次编辑 crontab 文件的时间 _(非标准)_ |
|
||||
|
||||
轻松添加任务
|
||||
|
||||
```bash
|
||||
echo "@reboot echo hi" \| crontab
|
||||
```
|
||||
|
||||
### 特殊字符
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
@@ -89,17 +90,17 @@ Min Hour Day Mon Weekday
|
||||
| 特殊字符 | 说明 |
|
||||
|---------------------|------------|
|
||||
`星号(*)` | 匹配字段中的所有值或任何可能的值。
|
||||
`横杆(-)` | 用于定义范围。例如:第 5 个字段(星期几)中的 1-5 每个工作日,即星期一到星期五
|
||||
`斜线 (/)` | 第一个字段(分钟)/15 表示每十五分钟或范围的增量。
|
||||
`逗号(,)` | 用于分隔项目。例如:第二个字段(小时)中的 2、6、8 在凌晨 2 点、早上 6 点和早上 8 点执行
|
||||
`横杆(-)` | 用于定义范围。例如:第 5 个字段(星期几)中的 1-5 每个工作日,即星期一到星期五
|
||||
`斜线 (/)` | 第一个字段(分钟)/15 表示每十五分钟或范围的增量。
|
||||
`逗号(,)` | 用于分隔项目。例如:第二个字段(小时)中的 2、6、8 在凌晨 2 点、早上 6 点和早上 8 点执行
|
||||
`L` | 仅允许用于 `月份中的某天` 或 `星期几` 字段,`星期几` 中的 `2L` 表示每个月的最后一个星期二
|
||||
`井号 (#)` | 仅允许用于 `星期几` 字段,后面必须在 1 到 5 的范围内。例如,`4#1` 表示给定月份的“第一个星期四”。
|
||||
`问号(?)` | 可以代替“*”并允许用于月份和星期几。使用仅限于 cron 表达式中的 `月份中的某天` 或 `星期几`。
|
||||
<!--rehype:className=show-header auto-wrap-->
|
||||
|
||||
另见
|
||||
----
|
||||
|
||||
## Also see
|
||||
|
||||
* [Devhints](https://devhints.io/cron) _(devhints.io)_
|
||||
* [Crontab Generator](https://crontab-generator.org/) _(crontab-generator.org)_
|
||||
* [Crontab guru](https://crontab.guru/) _(crontab.guru)_
|
||||
- [Devhints](https://devhints.io/cron) _(devhints.io)_
|
||||
- [Crontab Generator](https://crontab-generator.org/) _(crontab-generator.org)_
|
||||
- [Crontab guru](https://crontab.guru/) _(crontab.guru)_
|
||||
|
234
docs/cs.md
Normal file
234
docs/cs.md
Normal file
@@ -0,0 +1,234 @@
|
||||
C# 备忘清单
|
||||
===
|
||||
|
||||
提供基本语法和方法的 C# 快速参考备忘单
|
||||
|
||||
入门
|
||||
--------
|
||||
|
||||
### Hello.cs
|
||||
|
||||
```cs
|
||||
class Hello {
|
||||
// main method
|
||||
static void Main(string[] args)
|
||||
{
|
||||
// 输出: Hello, world!
|
||||
Console.WriteLine("Hello, world!");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
编译运行(确保在项目目录下)
|
||||
|
||||
```shell
|
||||
$ dotnet run
|
||||
Hello, world!
|
||||
```
|
||||
|
||||
### 变量
|
||||
|
||||
```cs
|
||||
int intNum = 9;
|
||||
long longNum = 9999999;
|
||||
float floatNum = 9.99F;
|
||||
double doubleNum = 99.999;
|
||||
decimal decimalNum = 99.9999M;
|
||||
char letter = 'D';
|
||||
bool @bool = true;
|
||||
string site = "quickref.me";
|
||||
var num = 999;
|
||||
var str = "999";
|
||||
var bo = false;
|
||||
```
|
||||
|
||||
### 原始数据类型
|
||||
|
||||
数据类型 | 尺寸 | 范围
|
||||
:- | - | -
|
||||
| `int` | 4 bytes | -2^31^ ^to^ 2^31^-1 |
|
||||
| `long` | 8 bytes | -2^63^ ^to^ 2^63^-1 |
|
||||
| `float` | 4 bytes | 6 ^to^ 7 decimal digits |
|
||||
| `double` | 8 bytes | 15 decimal digits |
|
||||
| `decimal` | 16 bytes | 28 ^to^ 29 decimal digits |
|
||||
| `char` | 2 bytes | 0 ^to^ 65535 |
|
||||
| `bool` | 1 bit | true / false |
|
||||
| `string` | 2 bytes per char | _N/A_ |
|
||||
<!--rehype:className=show-header-->
|
||||
|
||||
### 注释
|
||||
|
||||
```cs
|
||||
// 单行注释
|
||||
/* 多行
|
||||
注释 */
|
||||
// TODO:向 Visual Studio 中的任务列表添加注释
|
||||
/// 用于文档的单行注释
|
||||
/** 多行 注释
|
||||
用于文档 **/
|
||||
```
|
||||
|
||||
### Strings
|
||||
|
||||
```cs
|
||||
string first = "John";
|
||||
string last = "Doe";
|
||||
// 字符串连接
|
||||
string name = first + " " + last;
|
||||
Console.WriteLine(name); // => John Doe
|
||||
```
|
||||
|
||||
查看: [Strings](#c-字符串)
|
||||
|
||||
### User Input
|
||||
|
||||
```cs
|
||||
Console.WriteLine("Enter number:");
|
||||
if(int.TryParse(Console.ReadLine(),out int input))
|
||||
{
|
||||
// 输入验证
|
||||
Console.WriteLine($"You entered {input}");
|
||||
}
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 条件句
|
||||
|
||||
```cs
|
||||
int j = 10;
|
||||
if (j == 10) {
|
||||
Console.WriteLine("I get printed");
|
||||
} else if (j > 10) {
|
||||
Console.WriteLine("I don't");
|
||||
} else {
|
||||
Console.WriteLine("I also don't");
|
||||
}
|
||||
```
|
||||
|
||||
### 数组
|
||||
|
||||
```cs
|
||||
char[] chars = new char[10];
|
||||
chars[0] = 'a';
|
||||
chars[1] = 'b';
|
||||
string[] letters = {"A", "B", "C"};
|
||||
int[] mylist = {100, 200};
|
||||
bool[] answers = {true, false};
|
||||
```
|
||||
|
||||
### 循环
|
||||
|
||||
```cs
|
||||
int[] numbers = {1, 2, 3, 4, 5};
|
||||
for(int i = 0; i < numbers.Length; i++) {
|
||||
Console.WriteLine(numbers[i]);
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```cs
|
||||
foreach(int num in numbers) {
|
||||
Console.WriteLine(num);
|
||||
}
|
||||
```
|
||||
|
||||
C# 字符串
|
||||
----------------
|
||||
|
||||
### 字符串连接
|
||||
|
||||
```cs
|
||||
string first = "John";
|
||||
string last = "Doe";
|
||||
string name = first + " " + last;
|
||||
Console.WriteLine(name); // => John Doe
|
||||
```
|
||||
|
||||
### 字符串插值
|
||||
|
||||
```cs
|
||||
string first = "John";
|
||||
string last = "Doe";
|
||||
string name = $"{first} {last}";
|
||||
Console.WriteLine(name); // => John Doe
|
||||
```
|
||||
|
||||
### 字符串成员
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
成员 | 说明
|
||||
:- | -
|
||||
`Length` | 返回字符串长度的属性
|
||||
`Compare()` | 比较两个字符串的静态方法
|
||||
`Contains()` | 确定字符串是否包含特定的子字符串
|
||||
`Equals()` | 确定两个字符串是否具有相同的字符数据
|
||||
`Format()` | 通过 {0} 表示法和使用其他原语格式化字符串
|
||||
`Trim()` | 从尾随和前导字符中删除特定字符的所有实例。 默认删除前导和尾随空格
|
||||
`Split()` | 删除提供的字符并从两侧的剩余字符中创建一个数组
|
||||
<!--rehype:className=show-header-->
|
||||
|
||||
### 逐字字符串
|
||||
|
||||
```cs
|
||||
string longString = @"I can type any characters in here !#@$%^&*()__+ '' \n \t except double quotes and I will be taken literally. I even work with multiple lines.";
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 成员示例
|
||||
|
||||
```cs
|
||||
// 使用 System.String 的属性
|
||||
string lengthOfString = "How long?";
|
||||
lengthOfString.Length // => 9
|
||||
// 使用 System.String 的方法
|
||||
lengthOfString.Contains("How"); // => true
|
||||
```
|
||||
|
||||
### 频繁字符串拼接
|
||||
|
||||
```cs
|
||||
var sb = new StringBuilder();
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
sb.Append(i.ToString());
|
||||
}
|
||||
Console.WriteLine(sb.ToString());
|
||||
// => 123456789....
|
||||
```
|
||||
|
||||
对于频繁拼接字符串的场景(如:成百上千次循环),使用 `System.Text.StringBuilder` 提升性能
|
||||
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 原始字符串文本
|
||||
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
```cs
|
||||
// C#11 语法, 至少3个双引号(""")开头和结尾,内容可以输入任何原始字符
|
||||
// 单行: 左引号,右引号,内容 三者同行
|
||||
string singleLine = """Content begin "Hello World!" end.""";
|
||||
|
||||
// 多行:左引号,右引号各一行,内容需与右引号缩进对齐
|
||||
string multiLine = """
|
||||
Content begin "Hello World!" /\n<>"" end.
|
||||
""";
|
||||
Console.WriteLine(multiLine); // => Content begin "Hello World!" /\n<>"" end.
|
||||
```
|
||||
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
杂项
|
||||
-----------
|
||||
|
||||
### 一般 .NET 条款
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
条款 | 定义
|
||||
:- | -
|
||||
Runtime | 执行给定的已编译代码单元所需的服务集合
|
||||
Common Language Runtime (CLR) | 主要定位、加载和托管 .NET 对象。<br/>CLR 还处理内存管理、应用程序托管、线程协调、执行安全检查和其他低级细节
|
||||
Managed code | 在 `.NET` 运行时编译和运行的代码。 C#/F#/VB 就是例子
|
||||
Unmanaged code | 直接编译为机器代码且不能由 .NET 运行时直接托管的代码。<br/>不包含空闲内存管理、垃圾收集等。从 C/C++ 创建的 DLL 就是示例
|
||||
<!--rehype:className=show-header-->
|
58
docs/css.md
58
docs/css.md
@@ -149,14 +149,14 @@ div {
|
||||
}
|
||||
```
|
||||
|
||||
查看: [Flexbox](#css-flexbox) | [Flex Tricks](#css-flexbox-tricks)
|
||||
查看: [Flexbox](#css-flexbox) | [Flex Tricks](#css-flexbox-技巧)
|
||||
|
||||
### Grid 布局
|
||||
|
||||
```css
|
||||
#container {
|
||||
display: grid;
|
||||
grid: repeat(2, 60px) / auto-flow 80px;
|
||||
s grid: repeat(2, 60px) / auto-flow 80px;
|
||||
}
|
||||
#container > div {
|
||||
background-color: #8ca0ff;
|
||||
@@ -165,7 +165,7 @@ div {
|
||||
}
|
||||
```
|
||||
|
||||
查看: [Grid Layout](#css-grid-layout)
|
||||
查看: [Grid Layout](#grid-布局)
|
||||
|
||||
### 变量和计数器
|
||||
|
||||
@@ -244,17 +244,16 @@ p:first-child {
|
||||
|
||||
另见: [元素](https://developer.mozilla.org/zh-CN/docs/Web/CSS/Type_selectors) / [类](https://developer.mozilla.org/zh-CN/docs/Web/CSS/Class_selectors) / [ID](https://developer.mozilla.org/zh-CN/docs/Web/CSS/ID_selectors) / [通配](https://developer.mozilla.org/zh-CN/docs/Web/CSS/Universal_selectors) 选择器
|
||||
|
||||
|
||||
### 组合器
|
||||
|
||||
选择器 | 说明
|
||||
:- | :-
|
||||
`div.classname` | 具有特定类名的 div
|
||||
`div#idname` | 具有特定 ID 的 div
|
||||
`div p` | div 中的段落
|
||||
`div > p` | div 子节点中的所有 `P` 标签
|
||||
`div + p` | div 之后的 `P` 标签
|
||||
`div ~ p` | div 前面的 `P` 标签
|
||||
`div p` | div 中的所有段落
|
||||
`div > p` | 父元素是 div 的 `P` 标签
|
||||
`div + p` | div 之后的第一个同级 `P` 标签
|
||||
`div ~ p` | div 之后所有的同级 `P` 标签
|
||||
|
||||
另见: [相邻兄弟](https://developer.mozilla.org/zh-CN/docs/Web/CSS/Adjacent_sibling_combinator) / [通用兄弟](https://developer.mozilla.org/zh-CN/docs/Web/CSS/General_sibling_combinator) / [子](https://developer.mozilla.org/zh-CN/docs/Web/CSS/Child_combinator) 选择器
|
||||
|
||||
@@ -341,7 +340,7 @@ a:active { color: red; }
|
||||
:- | :-
|
||||
`p:first-child` | 第一个孩子 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:first-child)
|
||||
`p:last-child` | 最后一个孩子 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:last-child)
|
||||
`p:first-of-type` | 首先是某种类型 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:first-of-type)
|
||||
`p:first-of-type` | 第一个 p 类型的元素 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:first-of-type)
|
||||
`p:last-of-type` | 某种类型的最后一个 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:last-of-type)
|
||||
`p:nth-child(2)` | 其父母的第二个孩子 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:nth-child)
|
||||
`p:nth-child(3n42)` | Nth-child(an + b) 公式 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:nth-child)
|
||||
@@ -353,8 +352,8 @@ a:active { color: red; }
|
||||
`:is(header, div) p` | 可以选择的元素 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:is)
|
||||
`:where(header, div) p` | 与 `:is` 相同 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:where)
|
||||
`a:has(> img)` | 包含 `img` 元素的 `a` 元素 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:has)
|
||||
`::first-letter` | 第一行的第一个字母 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:first-letter)
|
||||
`::first-line` | 第一行应用样式 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:first-line)
|
||||
`::first-letter` | 第一行的第一个字母 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/::first-letter)
|
||||
`::first-line` | 第一行应用样式 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/::first-line)
|
||||
|
||||
CSS 字体
|
||||
------
|
||||
@@ -565,7 +564,6 @@ CSS 盒子模型
|
||||
|
||||
另见: [Visibility](https://developer.mozilla.org/zh-CN/docs/Web/CSS/visibility)
|
||||
|
||||
|
||||
### Auto 关键字
|
||||
|
||||
```css
|
||||
@@ -577,7 +575,6 @@ div {
|
||||
|
||||
另见: [边距(margin)](https://developer.mozilla.org/zh-CN/docs/Web/CSS/margin)
|
||||
|
||||
|
||||
### 溢出(Overflow)
|
||||
|
||||
```css
|
||||
@@ -804,7 +801,7 @@ flex-wrap: nowrap | wrap | wrap-reverse;
|
||||
flex-direction: row | row-reverse | column | column-reverse;
|
||||
```
|
||||
|
||||
----
|
||||
---
|
||||
|
||||
```bash
|
||||
╭┈┈╮ ▲ ╭┈┈╮ ┆
|
||||
@@ -825,7 +822,7 @@ column-reverse column row row-reverse
|
||||
align-items: flex-start | flex-end | center | baseline | stretch;
|
||||
```
|
||||
|
||||
----
|
||||
---
|
||||
|
||||
```css
|
||||
▶ flex-start(起点对齐) ▶ flex-end(终点对齐)
|
||||
@@ -863,7 +860,7 @@ align-content: flex-start | flex-end | center | space-between | space-around | s
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
----
|
||||
---
|
||||
|
||||
```css
|
||||
▶ flex-start(起点对齐) ▶ flex-end(终点对齐)
|
||||
@@ -903,7 +900,7 @@ align-content: flex-start | flex-end | center | space-between | space-around | s
|
||||
}
|
||||
```
|
||||
|
||||
----
|
||||
---
|
||||
|
||||
```css
|
||||
╭┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╮ ╭┈┈┈┈┈┈┈┈┈╮
|
||||
@@ -927,7 +924,7 @@ align-content: flex-start | flex-end | center | space-between | space-around | s
|
||||
}
|
||||
```
|
||||
|
||||
----
|
||||
---
|
||||
|
||||
```css
|
||||
╭┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈╮
|
||||
@@ -983,7 +980,6 @@ CSS Flexbox 技巧
|
||||
|
||||
### 移动布局
|
||||
|
||||
|
||||
```css
|
||||
.container {
|
||||
display: flex;
|
||||
@@ -1166,7 +1162,6 @@ grid-row-end: span 2;
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### Justify Self
|
||||
|
||||
```css
|
||||
@@ -1376,7 +1371,6 @@ a[href^="http"]:empty::before {
|
||||
|
||||
如果 `<a>` 标签里面没有内容,将 `href` 的值作为内容展示
|
||||
|
||||
|
||||
### 使用 :root 表示灵活类型
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
@@ -1396,6 +1390,27 @@ body {
|
||||
}
|
||||
```
|
||||
|
||||
### 吸附滚动
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```css {5,12}
|
||||
.container {
|
||||
height: 250px;
|
||||
overflow-x: scroll;
|
||||
display: flex;
|
||||
scroll-snap-type: x mandatory;
|
||||
column-gap: 10px;
|
||||
}
|
||||
.child {
|
||||
flex: 0 0 66%;
|
||||
width: 250px;
|
||||
background-color: #663399;
|
||||
scroll-snap-align: center;
|
||||
}
|
||||
```
|
||||
|
||||
可用于 `轮播图` 效果,[效果预览](https://codesandbox.io/embed/pensive-leftpad-w9p8rk?fontsize=14&hidenavigation=1&theme=dark)
|
||||
|
||||
### 类似 contenteditable 的样式
|
||||
|
||||
```css
|
||||
@@ -1408,7 +1423,6 @@ div {
|
||||
|
||||
通过样式来控制一个元素 `div` 是否可以编辑
|
||||
|
||||
|
||||
另见
|
||||
---------
|
||||
|
||||
|
@@ -13,7 +13,6 @@ Curl 是一种在服务器之间传输数据的工具,支持协议,包括 HT
|
||||
- [Curl GitHub 源码仓库](https://github.com/curl/curl) _(github.com)_
|
||||
- [Curl 官方网站](https://curl.se/) _(curl.se)_
|
||||
|
||||
|
||||
### Options
|
||||
<!--rehype:wrap-class=col-span-2 row-span-2-->
|
||||
|
||||
|
598
docs/dart.md
Normal file
598
docs/dart.md
Normal file
@@ -0,0 +1,598 @@
|
||||
Dart 备忘清单
|
||||
===
|
||||
|
||||
包含最重要概念、功能、方法等的 [Dart](https://dart.dev/) 备忘单。初学者的完整快速参考
|
||||
|
||||
入门
|
||||
-----
|
||||
|
||||
### 安装 Dart
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
#### Windows
|
||||
|
||||
```bash
|
||||
C:\> choco install dart-sdk # Windows
|
||||
```
|
||||
|
||||
#### Linux
|
||||
|
||||
执行以下一次性设置
|
||||
|
||||
```bash
|
||||
$ sudo apt-get update
|
||||
$ sudo apt-get install apt-transport-https
|
||||
$ wget -qO- https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmor -o /usr/share/keyrings/dart.gpg
|
||||
$ echo 'deb [signed-by=/usr/share/keyrings/dart.gpg arch=amd64] https://storage.googleapis.com/download.dartlang.org/linux/debian stable main' | sudo tee /etc/apt/sources.list.d/dart_stable.list
|
||||
```
|
||||
|
||||
安装 Dart SDK
|
||||
|
||||
```bash
|
||||
$ sudo apt-get update
|
||||
$ sudo apt-get install dart
|
||||
```
|
||||
|
||||
#### Mac
|
||||
|
||||
```bash
|
||||
$ brew tap dart-lang/dart
|
||||
$ brew install dart
|
||||
```
|
||||
|
||||
### hello.dart
|
||||
|
||||
```dart
|
||||
// 应用执行开始的顶级函数
|
||||
void main() {
|
||||
print("Hello World!"); // 打印到控制台
|
||||
}
|
||||
```
|
||||
|
||||
每个应用程序都有一个 `main()` 函数
|
||||
|
||||
#### Windows
|
||||
|
||||
```bash
|
||||
$ dart compile exe hellow.dart
|
||||
$ time ./hello.exe
|
||||
Hello World!
|
||||
```
|
||||
|
||||
### 变量
|
||||
|
||||
```dart
|
||||
int x = 2; // 显式键入
|
||||
var p = 5; // 类型推断 - 具有类型推断的通用var
|
||||
dynamic z = 8; // 变量可以采用任何类型
|
||||
z = "cool"; // cool
|
||||
|
||||
// 如果您从不打算更改变量,请使用 final 或 const
|
||||
// 像这样的东西:
|
||||
final email = "temid@gmail.com";
|
||||
// 与 var 相同,但不能重新分配
|
||||
final String email = "temid@gmail.com";
|
||||
// 你不能改变价值
|
||||
const qty = 5; // 编译时常数
|
||||
```
|
||||
|
||||
### 数据类型
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```dart
|
||||
// 整数,范围 -2^63 到 2^63 - 1
|
||||
int age = 20;
|
||||
// 浮点数字
|
||||
|
||||
double height = 1.85;
|
||||
// 您还可以将变量声明为 num
|
||||
// x 可以同时具有 int 和 double 值
|
||||
num x = 1;
|
||||
num += 2.5;
|
||||
print(num); // 打印: 3.5
|
||||
|
||||
String name = "Nicola";
|
||||
bool isFavourite = true;
|
||||
bool isLoaded = false;
|
||||
```
|
||||
|
||||
### 注释
|
||||
|
||||
```dart
|
||||
// 这是一条正常的单行注释
|
||||
/// 这是一个文档注释,用于文档库,
|
||||
/// 类及其成员。 IDE 和 dartdoc 等工具
|
||||
/// doc 特别注释。
|
||||
/* 也支持此类注释 */
|
||||
```
|
||||
|
||||
### 字符串插值
|
||||
|
||||
```dart
|
||||
// 可以对字符串类型使用单引号或双引号
|
||||
var firstName = 'Nicola';
|
||||
var lastName = "Tesla";
|
||||
// 可以用 $ 将变量嵌入到字符串中
|
||||
String fullName = "$firstName $lastName";
|
||||
// 与 + 连接
|
||||
var name = "Albert " + "Einstein";
|
||||
String upperCase = '${firstName.toUpperCase()}';
|
||||
print(upperCase); // 打印: NICOLA
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 导入 Imports
|
||||
|
||||
```dart
|
||||
// 导入核心库
|
||||
import 'dart:math';
|
||||
// 从外部包导入库
|
||||
import 'package:test/test.dart';
|
||||
// 导入文件
|
||||
import 'path/to/my_other_file.dart';
|
||||
```
|
||||
|
||||
操作符
|
||||
-------
|
||||
|
||||
### 算术运算符
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```dart
|
||||
print(2 + 3); // 打印: 5
|
||||
print(2 - 3); // 打印: -1
|
||||
print(2 * 3); // 打印: 6
|
||||
print(5 / 2); // 打印: 2.5 - 结果是 double
|
||||
print(5 ~/ 2); // 打印: 2 - 结果是n int
|
||||
print(5 % 2); // 打印: 1 - 余
|
||||
int a = 1, b;
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
```dart
|
||||
// 增
|
||||
b = ++a; // 前增量 - 在 b 获得其值之前增加 a
|
||||
b = a++; // 后增量 - 在 b 获得它的值之后增加 a
|
||||
// 递
|
||||
b = --a; // 前减量 - 在 b 获得它的值之前减少 a
|
||||
b = a--; // 后减量 - 在 b 获得它的值之后递减 a
|
||||
```
|
||||
|
||||
### 逻辑运算符
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
```dart
|
||||
// !expr 反转表达式(将 false 更改为 true,反之亦然)
|
||||
// || 逻辑或
|
||||
// && 逻辑与
|
||||
bool isOutOfStock = false;
|
||||
int quantity = 3;
|
||||
if (!isOutOfStock && (quantity == 2 || quantity == 3)) {
|
||||
// ...Order the product...
|
||||
}
|
||||
```
|
||||
|
||||
### 等式和关系运算符
|
||||
|
||||
```dart
|
||||
print(2 == 2); // 打印: true - 平等的
|
||||
print(2 != 3); // 打印: true - 不相等
|
||||
print(3 > 2); // 打印: true - 比...更棒
|
||||
print(2 < 3); // 打印: true - 少于
|
||||
print(3 >= 3); // 打印: true - 大于或等于
|
||||
print(2 <= 3); // 打印: true - 小于或等于
|
||||
```
|
||||
|
||||
控制流:条件
|
||||
------
|
||||
|
||||
### if 和 else if
|
||||
|
||||
```dart
|
||||
if(age < 18){
|
||||
print("Teen");
|
||||
} else if( age > 18 && age <60){
|
||||
print("Adult");
|
||||
} else {
|
||||
print("Old");
|
||||
}
|
||||
```
|
||||
|
||||
### switch case
|
||||
|
||||
```dart
|
||||
enum Pet {dog, cat}
|
||||
Pet myPet = Pet.dog;
|
||||
switch(myPet){
|
||||
case Pet.dog:
|
||||
print('My Pet is Dog.');
|
||||
break;
|
||||
case Pet.cat:
|
||||
print('My Pet is Cat.');
|
||||
break;
|
||||
default:
|
||||
print('I don\'t have a Pet');
|
||||
}
|
||||
// 打印: My Pet is Dog.
|
||||
```
|
||||
|
||||
控制流:循环
|
||||
-----
|
||||
|
||||
### while 循环
|
||||
|
||||
```dart
|
||||
while (!dreamsAchieved) {
|
||||
workHard();
|
||||
}
|
||||
```
|
||||
|
||||
循环迭代之前的 `while` 循环检查条件
|
||||
|
||||
### do-while 循环
|
||||
|
||||
```dart
|
||||
do {
|
||||
workHard();
|
||||
} while (!dreamsAchieved);
|
||||
```
|
||||
|
||||
`do-while` 循环在执行循环内的语句后验证条件
|
||||
|
||||
### for 循环
|
||||
|
||||
```dart
|
||||
for(int i=0; i< 10; i++){
|
||||
print(i);
|
||||
}
|
||||
var numbers = [1,2,3];
|
||||
// 列表的 for-in 循环
|
||||
for(var number in numbers){
|
||||
print(number);
|
||||
}
|
||||
```
|
||||
|
||||
Collections
|
||||
------------
|
||||
|
||||
### Lists
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
```dart
|
||||
// 有序的对象组
|
||||
var list = [1, 2, 3];
|
||||
print(list.length); //Print: 3
|
||||
print(list[1]); //Print: 2
|
||||
// 列表声明和初始化的其他方式
|
||||
List<String> cities = <String>["New York", "Mumbai", "Tokyo"];
|
||||
// 创建一个编译时常量的列表
|
||||
const constantCities = const ["New York", "Mumbai", "Tokyo"];
|
||||
```
|
||||
|
||||
### Maps
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```dart
|
||||
// 映射是关联键和值的对象
|
||||
var person = Map<String, String>();
|
||||
// 要初始化地图,请执行以下操作:
|
||||
person['firstName'] = 'Nicola';
|
||||
person['lastName'] = 'Tesla';
|
||||
print(person);
|
||||
// 打印: {firstName:Nicola, lastName:Tesla}
|
||||
print(person['lastName']);
|
||||
// 打印: Tesla
|
||||
|
||||
var nobleGases = {
|
||||
// Key: Value
|
||||
2: 'helium',
|
||||
10: 'neon',
|
||||
18: 'argon',
|
||||
};
|
||||
```
|
||||
|
||||
### Sets
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
```dart
|
||||
// Dart 中的集合是唯一项的无序集合
|
||||
var halogens = {'fluorine', 'chlorine', 'bromine', 'iodine', 'astatine'};
|
||||
// 创建一个空集
|
||||
var names = <String>{};
|
||||
Set<String> names = {}; // 这也有效
|
||||
//var names = {}; // 创建地图,而不是集合
|
||||
```
|
||||
|
||||
函数
|
||||
------
|
||||
|
||||
### 函数示例
|
||||
|
||||
```dart
|
||||
// dart 中的函数是对象并且有一个类型
|
||||
int add(int a, int b){
|
||||
return a+b;
|
||||
}
|
||||
// 函数可以分配给变量
|
||||
int sum = add(2,3); // 回报:5
|
||||
// 可以作为参数传递给其他函数
|
||||
int totalSum = add(2, add(2,3)); // 返回:7
|
||||
```
|
||||
|
||||
### 箭头语法 (=>)
|
||||
|
||||
```dart
|
||||
// 只包含一个表达式的函数,您可以使用简写语法
|
||||
bool isFav(Product product) => favProductsList.contains(product);
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### Anonymous (lambda) functions
|
||||
|
||||
```dart
|
||||
// 没有名字的小单行函数
|
||||
int add(a,b) => a+b;
|
||||
// lambda 函数大多作为参数传递给其他函数
|
||||
const list = [
|
||||
'apples', 'bananas', 'oranges'
|
||||
];
|
||||
|
||||
list.forEach(
|
||||
(item) =>
|
||||
print('${list.indexOf(item)}: $item')
|
||||
);
|
||||
// 打印: 0: apples 1: bananas 2: oranges
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
类和对象
|
||||
----------
|
||||
|
||||
### 类 Class
|
||||
|
||||
```dart
|
||||
class Cat {
|
||||
String name;
|
||||
// 方法
|
||||
void voice(){
|
||||
print("Meow");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 对象 Object
|
||||
|
||||
```dart
|
||||
// 类的实例
|
||||
// 在 myCat 下面是 Cat 类的对象
|
||||
void main(){
|
||||
Cat myCat = Cat();
|
||||
myCat.name = "Kitty";
|
||||
myCat.voice(); // 打印: Meow
|
||||
}
|
||||
```
|
||||
|
||||
### 构造函数
|
||||
|
||||
```dart
|
||||
class Cat {
|
||||
String name;
|
||||
Cat(this.name);
|
||||
}
|
||||
void main(){
|
||||
Cat myCat = Cat("Kitty");
|
||||
print(myCat.name); // 打印: Kitty
|
||||
}
|
||||
```
|
||||
|
||||
### 抽象类
|
||||
|
||||
```dart
|
||||
// 抽象类——不能实例化的类
|
||||
// 这个类被声明为抽象的,因此不能被实例化
|
||||
abstract class AbstractContainer {
|
||||
// 定义构造函数、字段、方法...
|
||||
void updateChildren(); // 抽象方法
|
||||
}
|
||||
```
|
||||
|
||||
### Getters Setters
|
||||
|
||||
```dart
|
||||
// 提供对对象属性的读写访问
|
||||
class Cat {
|
||||
String name;
|
||||
// getter
|
||||
String get catName {
|
||||
return name;
|
||||
}
|
||||
// setter
|
||||
void set catName(String name){
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
隐式接口
|
||||
------------
|
||||
|
||||
### 一个基本的界面
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
```dart
|
||||
// 一个人。隐式接口包含 greet()。
|
||||
class Person {
|
||||
// 在接口中,但仅在此库中可见。
|
||||
final String _name;
|
||||
// 不在接口中,因为这是一个构造函数。
|
||||
Person(this._name);
|
||||
// 在接口中
|
||||
String greet(String who) => 'Hello, $who. I am $_name.';
|
||||
}
|
||||
// Person 接口的实现。
|
||||
class Impostor implements Person {
|
||||
String get _name => '';
|
||||
String greet(String who) => 'Hi $who. Do you know who I am?';
|
||||
}
|
||||
String greetBob(Person person) => person.greet('Bob');
|
||||
void main() {
|
||||
print(greetBob(Person('Kathy')));
|
||||
// 打印: Hello, Bob. I am Kathy.
|
||||
print(greetBob(Impostor()));
|
||||
// 打印: Hi Bob. Do you know who I am?
|
||||
}
|
||||
```
|
||||
|
||||
### 扩展类
|
||||
|
||||
```dart
|
||||
class Phone {
|
||||
void use(){
|
||||
_call();
|
||||
_sendMessage();
|
||||
}
|
||||
}
|
||||
// 使用 extends 创建子类
|
||||
class SmartPhone extends Phone {
|
||||
void use(){
|
||||
// 使用 super 来引用超类
|
||||
super.use();
|
||||
_takePhotos();
|
||||
_playGames();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
异常
|
||||
-----
|
||||
|
||||
### Throw
|
||||
|
||||
```dart
|
||||
// 抛出 throws 或引发 raises 和异常 exception
|
||||
throw IntegerDivisionByZeroException();
|
||||
// 你也可以抛出任意对象
|
||||
throw "Product out of stock!";
|
||||
```
|
||||
|
||||
### Catch
|
||||
|
||||
```dart
|
||||
try {
|
||||
int c = 3/0;
|
||||
print(c);
|
||||
} on IntegerDivisionByZeroException {
|
||||
// 一个特定的异常
|
||||
print('Can not divide integer by 0.')
|
||||
} on Exception catch (e) {
|
||||
// 任何其他异常情况
|
||||
print('Unknown exception: $e');
|
||||
} catch (e) {
|
||||
// 没有指定类型,处理所有
|
||||
print('Something really unknown: $e');
|
||||
}
|
||||
```
|
||||
|
||||
### Finally
|
||||
|
||||
```dart
|
||||
// 确保某些代码无论是否抛出异常都能运行
|
||||
try {
|
||||
cookFood();
|
||||
} catch (e) {
|
||||
print('Error: $e'); // 先处理异常
|
||||
} finally {
|
||||
cleanKitchen(); // 然后清理
|
||||
}
|
||||
```
|
||||
|
||||
Futures
|
||||
------------
|
||||
|
||||
### Async Await
|
||||
|
||||
```dart
|
||||
// 异步函数:它们在设置可能耗时的操作后返回
|
||||
// async 和 await 关键字支持异步编程
|
||||
Future<String> login() {
|
||||
String userName="Temidjoy";
|
||||
return
|
||||
Future.delayed(
|
||||
Duration(seconds: 4), () => userName
|
||||
);
|
||||
}
|
||||
// 异步
|
||||
main() async {
|
||||
print('Authenticating please wait...');
|
||||
print(await userName());
|
||||
}
|
||||
```
|
||||
|
||||
各种各样的
|
||||
------------
|
||||
|
||||
### Null 和 Null 感知
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
```dart
|
||||
int x; // 任何对象的初始值为 null
|
||||
// ?? 空感知运算符
|
||||
x ??=6; // ??= 赋值运算符,仅当变量当前为 null 时才为其赋值
|
||||
print(x); // 打印: 6
|
||||
x ??=3;
|
||||
print(x); // 打印: 6 - 结果仍然是 6
|
||||
print(null ?? 10); // 打印: 10。如果不为空,则显示左侧的值,否则返回右侧的值
|
||||
```
|
||||
|
||||
### 三元运算符
|
||||
|
||||
```dart
|
||||
// 条件 ? 条件如果为真 : 条件如果为假
|
||||
bool isAvailable;
|
||||
isAvailable ? orderproduct() : addToFavourite();
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 条件属性访问
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
```dart
|
||||
userObject?.userName
|
||||
// 上面的代码片段等效于以下代码:
|
||||
(userObject != null) ? userObject.userName : null
|
||||
// 您可以将 ? 的多种用途链接起来。一起在一个表达式中
|
||||
userObject?.userName?.toString()
|
||||
// 如果 userObject 或 userObject.userName 为 null,则前面的代码返回 null 并且从不调用 toString()
|
||||
```
|
||||
|
||||
### 级联符号 (..)
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```dart
|
||||
// 允许您对同一对象进行一系列操作
|
||||
// 而不是这样做
|
||||
var user = User();
|
||||
user.name = "Nicola";
|
||||
user.email = "nicola@g.c";
|
||||
user.age = 24;
|
||||
// 你可以这样做
|
||||
var user = User()
|
||||
..name = "Nicola"
|
||||
..email = "nicola@g.c"
|
||||
..age = 24;
|
||||
```
|
||||
|
||||
### 扩展运算符 (...)
|
||||
|
||||
```dart
|
||||
// 将多个值插入到集合中
|
||||
var list = [1, 2, 3];
|
||||
var list2 = [0, ...list];
|
||||
print(list2.length); // 打印: 4
|
||||
```
|
||||
|
||||
另见
|
||||
----
|
||||
|
||||
- [Dart 官方文档](https://dart.dev/) _(dart.dev)_
|
@@ -17,17 +17,20 @@ $ pip --version
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
如果你没有安装 PIP,你可以从这个页面下载并安装它:https://pypi.org/project/pip/
|
||||
如果你没有安装 PIP,你可以从这个页面下载并安装它:<https://pypi.org/project/pip/>
|
||||
|
||||
### 入门
|
||||
<!--rehype:wrap-class=row-span-4-->
|
||||
|
||||
- 创建虚拟环境
|
||||
|
||||
```bash
|
||||
$ py -m venv myproject # Windows
|
||||
$ python -m venv myproject # Unix/MacOS
|
||||
```
|
||||
|
||||
- 其中包含子文件夹和文件,如下所示
|
||||
|
||||
```bash
|
||||
myproject
|
||||
├┈Include
|
||||
@@ -35,21 +38,27 @@ $ pip --version
|
||||
├┈Scripts
|
||||
╰┈pyvenv.cfg
|
||||
```
|
||||
|
||||
- 以下命令来激活环境
|
||||
|
||||
```bash
|
||||
# Windows:
|
||||
myproject\Scripts\activate.bat
|
||||
# Unix/MacOS:
|
||||
source myproject/bin/activate
|
||||
```
|
||||
|
||||
- 提示符中看到以下结果:
|
||||
|
||||
```bash
|
||||
# Windows:
|
||||
(myproject) C:\Users\Your Name>
|
||||
# Unix/MacOS:
|
||||
(myproject) ... $
|
||||
```
|
||||
|
||||
- 安装 Django
|
||||
|
||||
```bash
|
||||
# Windows:
|
||||
(myproject) C:\Users\Name>py -m pip install Django
|
||||
@@ -762,9 +771,6 @@ function myFunction() {
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
|
||||
|
||||
|
||||
另见
|
||||
----
|
||||
|
||||
|
@@ -21,7 +21,6 @@ $ docker run -d -p 80:80 docker/getting-started
|
||||
- `-p 80:80` - 将端口 80 映射到容器中的端口 80
|
||||
- `docker/getting-started` - 要使用的镜像
|
||||
|
||||
|
||||
在前台创建并运行容器
|
||||
|
||||
```shell
|
||||
@@ -86,7 +85,6 @@ Docker 容器
|
||||
`docker stats nginx-server` | 容器资源使用
|
||||
`docker diff nginx-server` | 列出对容器所做的更改
|
||||
|
||||
|
||||
### 创建容器
|
||||
|
||||
```shell
|
||||
|
@@ -3,7 +3,6 @@ Electron 备忘清单
|
||||
|
||||
此快速参考备忘单提供了 Electron v21 API 说明和使用示例。
|
||||
|
||||
|
||||
入门
|
||||
----
|
||||
|
||||
@@ -15,11 +14,14 @@ Electron 备忘清单
|
||||
#### 创建你的应用程序
|
||||
|
||||
- 安装
|
||||
|
||||
```bash
|
||||
mkdir my-app && cd my-app
|
||||
npm init
|
||||
```
|
||||
|
||||
在项目根目录会生成 `package.json`
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "my-app",
|
||||
@@ -30,22 +32,30 @@ Electron 备忘清单
|
||||
"license": "MIT"
|
||||
}
|
||||
```
|
||||
|
||||
- 安装依赖包
|
||||
|
||||
```bash
|
||||
npm install --save-dev electron
|
||||
```
|
||||
|
||||
- 添加开发模式打开您的应用命令
|
||||
|
||||
```js
|
||||
"scripts": {
|
||||
"start": "electron ."
|
||||
}
|
||||
```
|
||||
|
||||
- 运行命令,启动应用程序
|
||||
|
||||
```bash
|
||||
npm start
|
||||
```
|
||||
|
||||
入口都是 `main` 文件。这个文件控制了主进程,它运行在一个完整的Node.js环境中
|
||||
- 创建 `index.html` 页面
|
||||
|
||||
```html
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
@@ -60,7 +70,9 @@ Electron 备忘清单
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
- 窗口中打开您的页面
|
||||
|
||||
```js
|
||||
const {
|
||||
app,
|
||||
@@ -684,7 +696,6 @@ child.once('ready-to-show', () => {
|
||||
`win.setTitleBarOverlay(options)` _(win)_ | 在已开启 Window Controls Overlay 的窗口上,此方法将更新标题栏叠加层的样式 [#](https://www.electronjs.org/zh/docs/latest/api/browser-window#winsettitlebaroverlayoptions-windows)
|
||||
<!--rehype:className=style-list-->
|
||||
|
||||
|
||||
### 静态方法
|
||||
<!--rehype:wrap-class=col-span-3-->
|
||||
|
||||
|
@@ -522,5 +522,3 @@ With prefix argument LINE, put point on LINE."
|
||||
0
|
||||
(prefix-numeric-value line))))
|
||||
```
|
||||
|
||||
|
||||
|
@@ -3,7 +3,6 @@ Emmet 备忘清单
|
||||
|
||||
[Emmet](https://emmet.io/) 是一个用于提升 [HTML](./html.md) 和 CSS 代码编写的 Web 开发人员工具包,它允许您使用著名的 CSS 选择器以光速编写大型 HTML 代码块。
|
||||
|
||||
|
||||
Emmet 语法
|
||||
---------------
|
||||
|
||||
@@ -16,7 +15,6 @@ Emmet 语法
|
||||
- [Emmet for Coda](https://emmet.io/download/coda/) _(emmet.io)_
|
||||
- [Emmet for Atom](https://github.com/emmetio/emmet-atom#readme) _(github.com)_
|
||||
|
||||
|
||||
### 乘法:*
|
||||
|
||||
`ul>li*5`
|
||||
@@ -81,7 +79,7 @@ p>{Click }+a{here}+{ 继续}
|
||||
### ID 和 CLASS 属性
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
#header
|
||||
\# header
|
||||
|
||||
```html
|
||||
<div id="header"></div>
|
||||
@@ -199,7 +197,6 @@ ul>li.item$@2*3
|
||||
</ul>
|
||||
```
|
||||
|
||||
|
||||
### 上一层: ^
|
||||
|
||||
div+div>p>span+em^bq
|
||||
@@ -793,7 +790,6 @@ select
|
||||
|
||||
select:disabled, select:d 别名 select[disabled.]
|
||||
|
||||
|
||||
```html
|
||||
<select name="" id="" disabled="disabled"></select>
|
||||
```
|
||||
@@ -1162,7 +1158,7 @@ html:4s 别名 !!!4s+doc4[lang=${lang}]
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
html:xt 别名 !!!xt+doc4[xmlns=http://www.w3.org/1999/xhtml xml:lang=${lang}]
|
||||
html:xt 别名 !!!xt+doc4[xmlns=<http://www.w3.org/1999/xhtml> xml:lang=${lang}]
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
```html
|
||||
@@ -1179,7 +1175,7 @@ html:xt 别名 !!!xt+doc4[xmlns=http://www.w3.org/1999/xhtml xml:lang=${lang}]
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
html:xs 别名 !!!xs+doc4[xmlns=http://www.w3.org/1999/xhtml xml:lang=${lang}]
|
||||
html:xs 别名 !!!xs+doc4[xmlns=<http://www.w3.org/1999/xhtml> xml:lang=${lang}]
|
||||
|
||||
```html
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
@@ -1195,7 +1191,7 @@ html:xs 别名 !!!xs+doc4[xmlns=http://www.w3.org/1999/xhtml xml:lang=${lang}]
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
html:xxs 别名 !!!xxs+doc4[xmlns=http://www.w3.org/1999/xhtml xml:lang=${lang}]
|
||||
html:xxs 别名 !!!xxs+doc4[xmlns=<http://www.w3.org/1999/xhtml> xml:lang=${lang}]
|
||||
|
||||
```html
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
||||
@@ -1968,6 +1964,7 @@ CSS
|
||||
font-weight: normal;
|
||||
}
|
||||
```
|
||||
|
||||
#### @i, @import
|
||||
|
||||
```css
|
||||
@@ -2057,7 +2054,7 @@ CSS
|
||||
`bfv:h` | backface-visibility:hidden;
|
||||
`bfv:v` | backface-visibility:visible;
|
||||
`bg:ie` | filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='x.png',sizingMethod='crop');
|
||||
`cm` | /* ${child} */
|
||||
`cm` | /\* ${child} */
|
||||
`colm` | columns:;
|
||||
`colmc` | column-count:;
|
||||
`colmf` | column-fill:;
|
||||
@@ -2384,7 +2381,7 @@ choose+ A别名 xsl:choose>xsl:when+xsl:otherwise
|
||||
</xsl:choose>
|
||||
```
|
||||
|
||||
xsl 别名 !!!+xsl:stylesheet[version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform]>{ | }
|
||||
xsl 别名 !!!+xsl:stylesheet[version=1.0 xmlns:xsl=<http://www.w3.org/1999/XSL/Transform>]>{ | }
|
||||
|
||||
```xml
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
@@ -2401,4 +2398,4 @@ xsl 别名 !!!+xsl:stylesheet[version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/T
|
||||
另见
|
||||
--------
|
||||
|
||||
* [Emmet Cheat sheet](https://docs.emmet.io/cheat-sheet/) _(docs.emmet.io)_
|
||||
- [Emmet Cheat sheet](https://docs.emmet.io/cheat-sheet/) _(docs.emmet.io)_
|
||||
|
92
docs/es6.md
92
docs/es6.md
@@ -149,6 +149,40 @@ class Circle extends Shape {
|
||||
原型的语法糖。
|
||||
请参阅: [类](https://babeljs.io/learn-es2015/#classes)
|
||||
|
||||
### 私有类
|
||||
|
||||
javascript 默认字段是公共的(`public`),如果需要注明私有,可以使用(`#`)
|
||||
|
||||
```js
|
||||
class Dog {
|
||||
#name;
|
||||
constructor(name) {
|
||||
this.#name = name;
|
||||
}
|
||||
printName() {
|
||||
//只能在类内部调用私有字段
|
||||
console.log(`你的名字是${this.#name}`)
|
||||
}
|
||||
}
|
||||
|
||||
const dog = new Dog("putty")
|
||||
//console.log(this.#name)
|
||||
//Private identifiers are not allowed outside class bodies.
|
||||
dog.printName()
|
||||
```
|
||||
|
||||
#### 静态私有类
|
||||
|
||||
```js
|
||||
class ClassWithPrivate {
|
||||
static #privateStaticField;
|
||||
static #privateStaticFieldWithInitializer = 42;
|
||||
|
||||
static #privateStaticMethod() {
|
||||
// …
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Promises
|
||||
--------
|
||||
@@ -237,7 +271,9 @@ let {title, author} = {
|
||||
const scores = [22, 33]
|
||||
const [math = 50, sci = 50, arts = 50] = scores
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
```js
|
||||
// Result:
|
||||
// math === 22, sci === 33, arts === 50
|
||||
@@ -252,7 +288,9 @@ function greet({ name, greeting }) {
|
||||
console.log(`${greeting}, ${name}!`)
|
||||
}
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
```js
|
||||
greet({ name: 'Larry', greeting: 'Ahoy' })
|
||||
```
|
||||
@@ -266,7 +304,9 @@ function greet({ name = 'Rauno' } = {}) {
|
||||
console.log(`Hi ${name}!`);
|
||||
}
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
```js
|
||||
greet() // Hi Rauno!
|
||||
greet({ name: 'Larry' }) // Hi Larry!
|
||||
@@ -279,7 +319,9 @@ function printCoordinates({ left: x, top: y }) {
|
||||
console.log(`x: ${x}, y: ${y}`)
|
||||
}
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
```js
|
||||
printCoordinates({ left: 25, top: 90 })
|
||||
```
|
||||
@@ -448,6 +490,13 @@ function foo() {}
|
||||
foo.name // "foo"
|
||||
```
|
||||
|
||||
### length 属性
|
||||
|
||||
```js
|
||||
function foo(a, b){}
|
||||
foo.length // 2
|
||||
```
|
||||
|
||||
Objects
|
||||
-------
|
||||
|
||||
@@ -456,7 +505,9 @@ Objects
|
||||
```js
|
||||
module.exports = { hello, bye }
|
||||
```
|
||||
|
||||
同下:
|
||||
|
||||
```js
|
||||
module.exports = {
|
||||
hello: hello, bye: bye
|
||||
@@ -524,22 +575,30 @@ Modules 模块
|
||||
import 'helpers'
|
||||
// 又名: require('···')
|
||||
```
|
||||
---
|
||||
|
||||
----
|
||||
|
||||
```js
|
||||
import Express from 'express'
|
||||
// 又名: const Express = require('···').default || require('···')
|
||||
```
|
||||
---
|
||||
|
||||
----
|
||||
|
||||
```js
|
||||
import { indent } from 'helpers'
|
||||
// 又名: const indent = require('···').indent
|
||||
```
|
||||
---
|
||||
|
||||
----
|
||||
|
||||
```js
|
||||
import * as Helpers from 'helpers'
|
||||
// 又名: const Helpers = require('···')
|
||||
```
|
||||
---
|
||||
|
||||
----
|
||||
|
||||
```js
|
||||
import { indentSpaces as indent } from 'helpers'
|
||||
// 又名: const indent = require('···').indentSpaces
|
||||
@@ -554,12 +613,16 @@ import { indentSpaces as indent } from 'helpers'
|
||||
export default function () { ··· }
|
||||
// 又名: module.exports.default = ···
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
```js
|
||||
export function mymethod () { ··· }
|
||||
// 又名: module.exports.mymethod = ···
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
```js
|
||||
export const pi = 3.14159
|
||||
// 又名: module.exports.pi = ···
|
||||
@@ -643,6 +706,22 @@ new URL('data.txt', import.meta.url)
|
||||
|
||||
Node.js 环境中,`import.meta.url`返回的总是本地路径,即 `file:URL` 协议的字符串,比如 `file:///home/user/foo.js`
|
||||
|
||||
### 导入断言(Import Assertions)
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
#### 静态导入
|
||||
|
||||
```js
|
||||
import json from "./package.json" assert {type: "json"}
|
||||
// 导入 json 文件中的所有对象
|
||||
```
|
||||
|
||||
#### 动态导入
|
||||
|
||||
```js
|
||||
const json =
|
||||
await import("./package.json", { assert: { type: "json" } })
|
||||
```
|
||||
|
||||
Generators
|
||||
----------
|
||||
@@ -655,7 +734,9 @@ function* idMaker () {
|
||||
while (true) { yield id++ }
|
||||
}
|
||||
```
|
||||
---
|
||||
|
||||
----
|
||||
|
||||
```js
|
||||
let gen = idMaker()
|
||||
gen.next().value // → 0
|
||||
@@ -707,7 +788,6 @@ gen[Symbol.iterator] = function* () {
|
||||
|
||||
`Generator` 函数赋值给 `Symbol.iterator` 属性,从而使得 `gen` 对象具有了 `Iterator` 接口,可以被 `...` 运算符遍历了
|
||||
|
||||
|
||||
### Symbol.iterator 属性
|
||||
|
||||
```js
|
||||
|
@@ -10,16 +10,21 @@ Express 备忘清单
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
- 创建项目,添加 `package.json` 配置
|
||||
|
||||
```bash
|
||||
$ mkdir myapp # 创建目录
|
||||
$ cd myapp # 进入目录
|
||||
$ npm init -y # 初始化一个配置
|
||||
```
|
||||
|
||||
- 安装依赖
|
||||
|
||||
```bash
|
||||
$ npm install express # 安装依赖
|
||||
```
|
||||
|
||||
- 入口文件 `index.js` 添加代码:
|
||||
|
||||
```js
|
||||
const express = require('express')
|
||||
const app = express()
|
||||
@@ -31,7 +36,9 @@ Express 备忘清单
|
||||
console.log(`监听端口${port}示例应用`)
|
||||
})
|
||||
```
|
||||
|
||||
- 使用以下命令运行应用程序
|
||||
|
||||
```bash
|
||||
$ node index.js
|
||||
```
|
||||
|
382
docs/ffmpeg.md
382
docs/ffmpeg.md
@@ -103,7 +103,6 @@ $ ffmpeg -i movie.webm movie.mp4
|
||||
`Mi` | 220 | 1048576 | 兆字节 Mebibyte
|
||||
`Gi` | 230 | 1073741824 | Gibibyte
|
||||
|
||||
|
||||
### 音频参数
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
@@ -122,33 +121,17 @@ $ ffmpeg -i movie.webm movie.mp4
|
||||
---
|
||||
<!--rehype:body-class=cols-2-->
|
||||
|
||||
### 裁剪
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
### 剪切视频部分
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
```bash
|
||||
$ ffmpeg -i <input> -filter:v "crop=640:480:100:25" <output>
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
通过从输入视频中复制偏移 `x=100px` `y=25px` 的相应窗口来创建 `640x480` 大小的输出视频
|
||||
|
||||
```bash
|
||||
# 裁剪到宽度 360,高度 640
|
||||
$ ffmpeg -i input.mov -filter:v 'crop=360:640:0:0' -codec:a copy output.mov
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
裁剪到宽度 360,高度 640,从坐标 (10, 20) 开始
|
||||
|
||||
```bash
|
||||
$ ffmpeg -i input.mov -filter:v 'crop=360:640:10:20' -codec:a copy output.mov
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 缩放
|
||||
|
||||
```bash
|
||||
$ ffmpeg -i <输入> -vf scale=640:480 <输出>
|
||||
# 从1分45秒开始剪切2分35秒
|
||||
$ ffmpeg -i <input> -ss 00:01:45 -t 00:02:35 -vcodec copy -acodec copy <output>
|
||||
# 从1分45秒开始剪切到第4分20秒,与上一行等效
|
||||
$ ffmpeg -i <input> -ss 00:01:45 -to 00:04:20 -codec copy <output>
|
||||
$ ffmpeg -ss 00:00:30 -i orginalfile.mpg -t 00:00:05 -vcodec copy -acodec copy newfile.mpg
|
||||
# 从 4.5 秒开始的 5 秒长的视频
|
||||
$ ffmpeg -i in.mp4 -ss 4.5 -t 5 out.mp4
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
@@ -166,17 +149,6 @@ $ ffmpeg -r 1 -i input.m2v -r 24 output.avi
|
||||
|
||||
将输入文件的帧速率(仅对原始格式有效)强制为 1 fps,将输出文件的帧速率强制为 24 fps
|
||||
|
||||
### 剪切视频部分
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
```bash
|
||||
$ ffmpeg -i <input> -ss 00:01:45 -t 00:02:35 -vcodec copy -acodec copy <output>
|
||||
$ ffmpeg -ss 00:00:30 -i orginalfile.mpg -t 00:00:05 -vcodec copy -acodec copy newfile.mpg
|
||||
# 从 4.5 秒开始的 5 秒长的视频
|
||||
$ ffmpeg -i in.mp4 -ss 4.5 -t 5 out.mp4
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### H265 2-pass 编码
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
@@ -210,14 +182,6 @@ $ ffmpeg -i <input> -c copy -metadata:s:v:0 rotate=90 <output>
|
||||
|
||||
不要为旋转重新编码,而是简单地为旋转角度添加一个视频元数据字段
|
||||
|
||||
### 放慢视频速度
|
||||
|
||||
```bash
|
||||
$ ffmpeg -i in.mp4 -filter:v "setpts=4.0*PTS" out.mp4
|
||||
```
|
||||
|
||||
使用过滤器减慢视频。 此示例将视频减慢四倍
|
||||
|
||||
### 缩放到特定宽度
|
||||
|
||||
```bash
|
||||
@@ -232,28 +196,17 @@ $ ffmpeg -i in.mp4 -filter:v scale="538:trunc(ow/a/2)*2" -c:a copy out.mp4
|
||||
### 提取音频流
|
||||
|
||||
```bash
|
||||
$ ffmpeg -i file.mp4 -vn -acodec copy output.aac
|
||||
$ ffmpeg -i file.mp4 -vn -c copy output.aac
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
将`-vn`(无视频)与 `-acodec copy` 结合起来。请注意,输出文件扩展名必须与输入文件中的音频编解码器匹配,`-acodec copy` 才能工作。
|
||||
`-vn` (过滤视频),使用 `-c copy`,不会重新解码和编码,加快速度。
|
||||
|
||||
### 创建缩略图
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
在 10 秒时创建一个缩略图
|
||||
### 提取视频流
|
||||
|
||||
```bash
|
||||
$ ffmpeg -ss 10 -i <input file> -vframes 1 -vcodec png -an thumb.png
|
||||
$ ffmpeg -i file.mp4 -an -c copy output.mp4
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
例如,要每 `n` 秒创建一次缩略图,请使用 `-vf fps=1/n`
|
||||
|
||||
```bash
|
||||
$ ffmpeg -i <input file> -vf fps=1/60 thumbnails/thumb%03d.png
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 处理 id3 标签
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
@@ -281,8 +234,51 @@ $ ffmpeg -i file.aac -acodec mp3 -ar 44100 -ab 128000 output.mp3
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 将输入文件转码为 DVD PAL 格式
|
||||
|
||||
```bash
|
||||
$ ffmpeg -y -threads 8 -i inFile -target pal-dvd -ac 2 -aspect 16:9 -acodec mp2 -ab 224000 -vf pad=0:0:0:0 outFile
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### -map 命令
|
||||
<!--rehype:wrap-class=col-span-2 row-span-2-->
|
||||
|
||||
`-map` 命令用于指定索引文件,以及索引文件中流类型和它的索引
|
||||
|
||||
----
|
||||
|
||||
```bash
|
||||
-map index:stram_type:stream_index
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
:- | -
|
||||
:- | -
|
||||
`input_file_index` | 输入的文件索引(从 0 开始)
|
||||
`stream_type` | 指定文件流的类型(a -> 音频,v -> 视频,s -> 字幕)
|
||||
`stream_index` | 指定流类型的索引(从 0 开始)
|
||||
|
||||
将第一个输入文件的第二个音频拷贝到 out.mp3
|
||||
|
||||
```bash
|
||||
$ ffmpeg -i input.mp4 -map 0:a:1 -c copy out.mp3
|
||||
```
|
||||
|
||||
将第一个输入文件的视频流和第二个输入文件的音频流拷贝到 out.mp4
|
||||
|
||||
```bash
|
||||
$ ffmpeg -i i1.mp4 -i i2.mp4 -map 0:v -map 0:a -c copy out.mp4
|
||||
```
|
||||
|
||||
#### 反向 -map 命令
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
反向的 map 命令(在 map 命令的参数前加负号)。例如,`-map -0:a:0`,忽略第一个文件中的第一个音频流。
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 切换容器(转换类型)
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
将容器从 `MKV` 更改为 `MP4`
|
||||
|
||||
@@ -314,22 +310,63 @@ $ ffmpeg -i input.mov -itsoffset 3 -i input.mov -map 1:v -map 0:a -codec:a copy
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
|
||||
### 图片中的视频
|
||||
|
||||
如果您有多个编号的图像 image1.jpg、image2.jpg... 像这样从它们创建一个视频
|
||||
|
||||
```bash
|
||||
$ ffmpeg -f image2 -i image%d.jpg video.mp4
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
多个编号的图像 image1.jpg、image2.jpg... 像这样从它们创建一个视频
|
||||
|
||||
### 将视频拆分为图像
|
||||
|
||||
```bash
|
||||
$ ffmpeg -i video.mp4 image%d.jpg
|
||||
```
|
||||
|
||||
### 录屏
|
||||
<!--rehype:wrap-class=col-span-2 row-span-2-->
|
||||
|
||||
#### 查找所有可用设备
|
||||
|
||||
```bash
|
||||
$ ffmpeg -f avfoundation -list_devices true -i ""
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
<span style="color:red">一定要选择好设备,根据设备进行配置。</sapn>
|
||||
|
||||
#### windows 下录屏
|
||||
|
||||
```bash
|
||||
$ ffmpeg -hide_banner -loglevel error -stats -f gdigrab -framerate 60 \
|
||||
-offset_x 0 -offset_y 0 -video_size 1920x1080 -draw_mouse 1 -i deskop \
|
||||
-c:v libx264 -r 60 -preset ultrafast -pix_fmt yuv420p -y screen_record.mp4
|
||||
```
|
||||
|
||||
#### mac 下录屏
|
||||
|
||||
```bash
|
||||
$ ffmpeg -f avfoundation -i 1:0 -preset ultrafast out.mkv
|
||||
```
|
||||
|
||||
### 合并音频与图片
|
||||
|
||||
合并多个音频,自定义背景图片,生成视频音乐
|
||||
|
||||
```bash
|
||||
# mylist.txt >>>
|
||||
file '1.mp3'
|
||||
file '2.mp3'
|
||||
file '3.mp3'
|
||||
|
||||
# OBS: 46500 = 25:50 minutes * 60 * 30fps
|
||||
# echo "00:25:50" | awk -F: '{ print (($1 * 3600) + ($2 * 60) + $3) * 30 }'
|
||||
$ ffmpeg -y -loop 1 -i cover.jpg -f concat -i mylist.txt -c:v libx264 -r 30 -pix_fmt yuv420p -vframes 46500 -c:a aac -b:a 192k -strict experimental -shortest output.mp4
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 转换为 Gif
|
||||
<!--rehype:wrap-class=col-span-2 row-span-3-->
|
||||
|
||||
@@ -349,27 +386,24 @@ $ ffmpeg -i input.gif output.mov
|
||||
$ ffmpeg -i input.mov -codec:v copy -codec:a copy output.mp4
|
||||
```
|
||||
|
||||
### 移除音频
|
||||
|
||||
```bash
|
||||
$ ffmpeg -i input.mov -codec:v copy -an output.mov
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 将输入文件转码为 DVD PAL 格式
|
||||
|
||||
```bash
|
||||
$ ffmpeg -y -threads 8 -i inFile -target pal-dvd -ac 2 -aspect 16:9 -acodec mp2 -ab 224000 -vf pad=0:0:0:0 outFile
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
|
||||
### 转换为灰度
|
||||
|
||||
```bash
|
||||
$ ffmpeg -y -i inFile -flags gray outFile
|
||||
```
|
||||
|
||||
### 字幕格式转换
|
||||
|
||||
```bash
|
||||
# srt -> ass
|
||||
$ ffmpeg -i subtitle.srt subtitle.ass
|
||||
# ass -> vtt
|
||||
$ ffmpeg -i subtitle.ass subtitle.vtt
|
||||
```
|
||||
|
||||
srt、ass、vtt 等格式之间可以相互转换
|
||||
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 字幕
|
||||
<!--rehype:wrap-class=col-span-2 row-span-2-->
|
||||
@@ -494,6 +528,196 @@ $ ffmpeg -i audioS.mp4 -i videoS.mp4 -c copy -map 0:a -map 1:v outFile.mp4
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 合并视频
|
||||
|
||||
<!--rehype:wrap-class=col-span-3 row-span-3-->
|
||||
|
||||
合并相同规格(解码/分辨率/帧率)视频
|
||||
|
||||
```bash
|
||||
# mylist.txt >>>
|
||||
file '1.mp4'
|
||||
file '2.mp4'
|
||||
file '3.mp4'
|
||||
|
||||
# 这些文件是相对路径,如使用绝对路径需要添加 `-safe 0` 参数
|
||||
$ ffmpeg -f concat -i mylist.txt -c copy output.mp4
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
合并当前目录下所有视频
|
||||
|
||||
```bash
|
||||
$ ffmpeg -f concat -safe 0 -i <(for f in ./*.mp4; do echo "file '$PWD/$f'"; done) -c copy output.mp4
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
合并不同规格视频,保证视频不变形
|
||||
|
||||
```bash
|
||||
$ ffmpeg -i 1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts tmp1.ts
|
||||
$ ffmpeg -i 2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts tmp2.ts
|
||||
$ ffmpeg -i 3.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts tmp3.ts
|
||||
|
||||
$ ffmpeg -threads 2 -i "concat:tmp1.ts|tmp2.ts|tmp3.ts" -vf "scale=720:1080:force_original_aspect_ratio=decrease,pad=720:1080:(ow-iw)/2:(oh-ih)/2" -pix_fmt yuvj420p -shortest -y output.mp4
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
合并不同解码视频
|
||||
|
||||
```bash
|
||||
$ ffmpeg -i input1.mp4 -i input2.webm -i input3.mov \
|
||||
-filter_complex "[0:v:0][0:a:0][1:v:0][1:a:0][2:v:0][2:a:0]concat=n=3:v=1:a=1[outv][outa]" \
|
||||
-map "[outv]" -map "[outa]" output.mkv
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
合并视频并重新编码音频
|
||||
|
||||
```bash
|
||||
$ ffmpeg -f concat -i mylist.txt -c:v copy -c:a flac -strict -2 output.mp4
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
视频过滤器
|
||||
---
|
||||
|
||||
### 格式
|
||||
|
||||
如果一个 fliter 有多个参数,需要使用 `,` 分隔
|
||||
|
||||
```bash
|
||||
$ ffmpeg -i test.avi -c:v libx264 -vf "scale=1024:-1,transpose=1,crop=iw/3:ih/3" output.mp4
|
||||
```
|
||||
|
||||
### 缩放
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```bash
|
||||
$ ffmpeg -i input.mp4 -vf "scale=640:480" out.mp4
|
||||
# -1 → 指根据另一个参数帮我们推断
|
||||
$ ffmpeg -i input.mp4 -vf "scale=720:-1" out.mp4
|
||||
# 宽度和高度
|
||||
ffmpeg -i input.mp4 -vf "scale=w=800:h=600" output.mp4
|
||||
# in_w\in_h 输入尺寸
|
||||
ffmpeg -i input.mkv -vf "scale=w=1/2*in_w:h=1/2*in_h" output.mkv
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 裁剪
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
从左上角开始,复制 `x=0px` `y=0px` 的相应窗口来创建 `1280x720` 大小的输出视频
|
||||
|
||||
```bash
|
||||
ffmpeg -i input.mp4 -vf "crop=w=1280:h=720:x=0:y=0" output.mp4
|
||||
```
|
||||
|
||||
裁剪到宽度 360,高度 640,从坐标 (10, 20) 开始
|
||||
|
||||
```bash
|
||||
$ ffmpeg -i input.mov -vf 'crop=360:640:10:20' output.mov
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 去除水印
|
||||
|
||||
设置一个矩形覆盖区域 x=10:y=10:w=120:h=45
|
||||
|
||||
```bash
|
||||
# show=1 为可选参数,设置显示边框,方便调试用的
|
||||
ffmpeg -i 1.mp4 -b:v 548k -vf delogo=x=10:y=10:w=120:h=45:show=1 output.mp4
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 创建缩略图
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
在 10 秒时创建一个缩略图
|
||||
|
||||
```bash
|
||||
$ ffmpeg -ss 10 -i <input file> -vframes 1 -vcodec png -an thumb.png
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
例如,要每 `n` 秒创建一次缩略图,请使用 `-vf fps=1/n`
|
||||
|
||||
```bash
|
||||
$ ffmpeg -i <input file> -vf fps=1/60 thumbnails/thumb%03d.png
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 添加水印
|
||||
|
||||
在视频左上方 20,20 的位置插入 logo.png 图片
|
||||
|
||||
```bash
|
||||
# -b:v 548k 可选参数,设置视频比特率,默认 200k 最好设置与原视频一致
|
||||
ffmpeg -i 1.mp4 -acodec copy -b:v 548k -vf "movie=logo.png[watermark];[in][watermark]overlay=20:20" output.mp4
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 视频旋转
|
||||
|
||||
```bash
|
||||
# 顺时针旋转 90
|
||||
$ ffmpeg -i input.avi -vf "rotate=90*PI/180" out.mp4
|
||||
# 顺时针旋转 180,翻转 90
|
||||
$ ffmpeg -i input.mp4 -vf "rotate=PI" out.mp4
|
||||
```
|
||||
|
||||
### 更改视频播放速度
|
||||
|
||||
```bash
|
||||
# 加速 2 倍
|
||||
$ ffmpeg -i input.mkv -vf "setpts=0.5*PTS" output.mkv
|
||||
# 减速 2 倍
|
||||
$ ffmpeg -i input.mp4 -vf "setpts=2*PTS" output.mp4
|
||||
```
|
||||
|
||||
### 添加背景音乐
|
||||
|
||||
```bash
|
||||
# -t 10 文件时长,单位为秒,建议取值原始视频总时长
|
||||
$ ffmpeg -i 1.mp4 -i test.mp3 \
|
||||
-filter_complex "[1:a]aloop=loop=-1:size=2e+09[out];[out][0:a]amix" \
|
||||
-t 10 out.mp4
|
||||
```
|
||||
|
||||
音频过滤器
|
||||
---
|
||||
|
||||
### 调节音量
|
||||
|
||||
```bash
|
||||
# 增大音量
|
||||
$ ffmpeg -i test.mp4 -af "volumn=1.5" out.mp4
|
||||
```
|
||||
|
||||
### 更改音频速度
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```bash
|
||||
$ ffmpeg -i input.wav -af "atempo=0.75" output.wav
|
||||
# 加速 4 倍
|
||||
$ ffmpeg -i input.mp3 -af "atempo=2.0,atempo=2.0" ouutput.mp3
|
||||
```
|
||||
|
||||
`atempo` 它只接受 `0.5`(半速) 到 `2` (倍速)之间的值。为了越过这个限制,你可以链式使用这个过滤器
|
||||
|
||||
### 统一视频的音量
|
||||
|
||||
```bash
|
||||
$ ffmpeg -i test.mp4 -af "loudnorm=I=-5:LRA=1" out.mp4
|
||||
```
|
||||
|
||||
### 重新映射通道数
|
||||
|
||||
```bash
|
||||
# 使左右耳的声音同时出现
|
||||
$ ffmpeg -i input.mp3 -af "channelmap=1-0|1-1" output.mp3
|
||||
```
|
||||
|
||||
另见
|
||||
---
|
||||
|
||||
|
@@ -39,7 +39,6 @@ $ find . -name "json_*"
|
||||
| `-mindepth` | find / -mindepth 3 -maxdepth 5 -name pass | 在子目录级别 2 和 4 之间 |
|
||||
<!--rehype:className=show-header-->
|
||||
|
||||
|
||||
### 类型
|
||||
|
||||
| | |
|
||||
@@ -224,7 +223,6 @@ $ find . -type d -empty
|
||||
$ find . -type f -empty -delete
|
||||
```
|
||||
|
||||
|
||||
查找日期和时间
|
||||
-------------
|
||||
|
||||
|
75
docs/git.md
75
docs/git.md
@@ -185,6 +185,7 @@ $ git tag my_tag
|
||||
```shell
|
||||
$ git checkout -b <branch-name> origin/<branch-name>
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 临时提交
|
||||
|
||||
@@ -236,6 +237,55 @@ $ git diff branchB...branchA
|
||||
$ git show [SHA]
|
||||
```
|
||||
|
||||
### 忽略文件
|
||||
<!--rehype:wrap-class=row-span-4-->
|
||||
|
||||
文件 `.gitignore` 指定了 `Git` 应该忽略的 **未跟踪的** 文件
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
行首 `#` | 全行注释,不支持行尾类注释 _(转义 `\#`)_
|
||||
行首 **`!`** | 否定模式 _(转义 `\!`)_
|
||||
`**` | 匹配任意路径
|
||||
`*` | 匹配任意多个字符
|
||||
`?` | 匹配任意一个字符
|
||||
`doc/**` | 匹配 `doc` 文件夹下的全部内容
|
||||
`doc/**/a` | 匹配任意深度路径下的 `a` 文件或文件夹
|
||||
`/` | 表示路径分隔符,不区分操作系统
|
||||
`/` 结尾 | 仅会匹配文件夹,否则会匹配文件和文件夹
|
||||
空行 | 不匹配任何文件
|
||||
行尾空格 | 默认被忽略,可使用`\`进行转义
|
||||
行首空格 | 被正常处理,不会被忽略
|
||||
|
||||
当前 `.gitignore` 文件定义规则的优先级高于上级路径 `.gitignore` 定义规则的优先级;后定义的规则优先级高于前面定义规则的优先级
|
||||
|
||||
```gitignore showLineNumbers
|
||||
# 忽略当前目录logs文件夹下的全部内容
|
||||
/logs/
|
||||
/logs/*
|
||||
/logs/**
|
||||
# 上述几条规则等效
|
||||
|
||||
# 忽略 Mac 系统文件,包括任意子路径下的同名文件(夹)
|
||||
.DS_store
|
||||
|
||||
# 忽略 node_modules 文件夹,包括任意子路径下的同名文件夹
|
||||
node_modules/
|
||||
|
||||
# 忽略任意子路径下build、target文件夹,
|
||||
# 但不忽略src/main、src/test下的build、target文件夹
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
target/
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
# 使用 ! 重新包含指定文件(夹)
|
||||
!logs/.gitkeep
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 重构文件名
|
||||
|
||||
```bash
|
||||
@@ -339,23 +389,8 @@ $ git mv [existing-path] [new-path]
|
||||
$ git log --stat -M
|
||||
```
|
||||
|
||||
### 忽略文件
|
||||
|
||||
```gitignore showLineNumbers
|
||||
/logs/*
|
||||
# “!” 意思是不要忽视
|
||||
!logs/.gitkeep
|
||||
# 忽略 Mac 系统文件
|
||||
.DS_store
|
||||
# 忽略 node_modules 文件夹
|
||||
node_modules
|
||||
# 忽略 SASS 配置文件
|
||||
.sass-cache
|
||||
```
|
||||
|
||||
`.gitignore` 文件指定了 Git 应该忽略的未跟踪的文件
|
||||
|
||||
### git 配置 ssh 代理
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
```bash
|
||||
$ cat ~/.ssh/config
|
||||
@@ -374,15 +409,20 @@ Git 技巧
|
||||
### 重命名分支
|
||||
|
||||
- **重命名**为`new`
|
||||
|
||||
```shell
|
||||
$ git branch -m <new>
|
||||
$ git branch -m <old> <new> #重命名分支
|
||||
```
|
||||
|
||||
- **推送**并重置
|
||||
|
||||
```shell
|
||||
$ git push origin -u <new>
|
||||
```
|
||||
|
||||
- **删除**远程分支
|
||||
|
||||
```shell
|
||||
$ git push origin --delete <old> #方法1
|
||||
$ git push origin :oldBranchName #方法2
|
||||
@@ -674,6 +714,7 @@ $ git blame <file-name>
|
||||
```bash
|
||||
$ git commit --amend --author='Author Name <email@address.com>'
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 修改远程仓库的 url
|
||||
|
||||
@@ -753,6 +794,7 @@ $ git rebase --autostash
|
||||
```bash
|
||||
$ git fetch origin pull/<id>/head:<branch-name>
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 详细展示一行中的修改
|
||||
|
||||
@@ -827,7 +869,6 @@ $ git config --global --unset http.https://github.com.proxy
|
||||
$ git config --global --unset https.https://github.com.proxy
|
||||
```
|
||||
|
||||
|
||||
### clone 最新一次提交
|
||||
|
||||
```bash
|
||||
|
@@ -212,6 +212,7 @@ jobs:
|
||||
```shell
|
||||
jobs.<job_id>.environment
|
||||
```
|
||||
|
||||
使用单一环境名称的示例
|
||||
|
||||
```yml
|
||||
@@ -251,7 +252,6 @@ steps:
|
||||
|
||||
设置环境变量的示例
|
||||
|
||||
|
||||
```yml
|
||||
env:
|
||||
MY_ENV_VAR: ${{ <expression> }}
|
||||
|
@@ -86,7 +86,6 @@ Gmail 快捷键
|
||||
`g` 然后 `k` | 前往任务
|
||||
<!--rehype:className=shortcuts-->
|
||||
|
||||
|
||||
### Gmail 主题列表选择
|
||||
|
||||
:- | :-
|
||||
|
@@ -23,7 +23,7 @@ $ go run hello.go
|
||||
Hello, world!
|
||||
```
|
||||
|
||||
或者在 [Go repl](https://repl.it/languages/go) 中尝试一下
|
||||
或者在 [Go repl](https://repl.it/languages/go) 中尝试一,`go` 命令[参考](#go-命令)
|
||||
|
||||
### 变量
|
||||
|
||||
@@ -89,7 +89,7 @@ Golang 基本类型
|
||||
s1 := "Hello" + "World"
|
||||
s2 := `A "raw" string literal
|
||||
can include line breaks.`
|
||||
// 输出:11
|
||||
// 输出:10
|
||||
fmt.Println(len(s1))
|
||||
// 输出:Hello
|
||||
fmt.Println(string(s1[0:5]))
|
||||
@@ -247,7 +247,6 @@ s := strconv.Itoa(i)
|
||||
fmt.Println(s) // Outputs: 90
|
||||
```
|
||||
|
||||
|
||||
Golang 字符串
|
||||
--------
|
||||
|
||||
@@ -317,7 +316,7 @@ func main() {
|
||||
### 函数实例
|
||||
|
||||
| 实例 | Result |
|
||||
|-------------------------------|-------------|
|
||||
| ----------------------------- | ----------- |
|
||||
| Contains("test", "es") | true |
|
||||
| Count("test", "t") | 2 |
|
||||
| HasPrefix("test", "te") | true |
|
||||
@@ -569,6 +568,7 @@ sum(nums...) // => [1 2 3 4] 10
|
||||
```go
|
||||
import --> const --> var --> init()
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```go
|
||||
@@ -725,7 +725,7 @@ func main() {
|
||||
### WaitGroup
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```golang
|
||||
```go
|
||||
package main
|
||||
import (
|
||||
"fmt"
|
||||
@@ -916,6 +916,7 @@ func main() {
|
||||
-------------
|
||||
|
||||
### 关键字(Keywords)
|
||||
|
||||
- break
|
||||
- default
|
||||
- func
|
||||
@@ -954,8 +955,57 @@ func main() {
|
||||
| `%` | `>>` | `%=` | `>>=` | `--` | `!` | `...` | `.` | `:` |
|
||||
| | `&^` | `&^=` | | | | | | |
|
||||
|
||||
Go 命令
|
||||
---
|
||||
|
||||
### Go 编译器命令
|
||||
|
||||
:- | --
|
||||
:- | --
|
||||
`go command [参数]` | go 命令 [参数]
|
||||
`go build` | 编译包和依赖包
|
||||
`go clean` | 移除对象和缓存文件
|
||||
`go doc` | 显示包的文档
|
||||
`go env` | 打印go的环境变量信息
|
||||
`go bug` | 报告bug
|
||||
`go fix` | 更新包使用新的api
|
||||
`go fmt` | 格式规范化代码
|
||||
`go generate` | 通过处理资源生成go文件
|
||||
`go get` | 下载并安装包及其依赖
|
||||
`go install` | 编译和安装包及其依赖
|
||||
`go list` | 列出所有包
|
||||
`go run` | 编译和运行go程序
|
||||
`go test` | 测试
|
||||
`go tool` | 运行给定的go工具
|
||||
`go version` | 显示go当前版本
|
||||
`go vet` | 发现代码中可能的错误
|
||||
|
||||
### ENV
|
||||
|
||||
:- | --
|
||||
:- | --
|
||||
`GOOS` | 编译系统
|
||||
`GOARCH` | 编译arch
|
||||
`GO111MODULE` | gomod开关
|
||||
`GOPROXY` | go代理 <https://goproxy.io> <https://goproxy.cn>
|
||||
`GOSSAFUNC` | 生成 `SSA.html` 文件,展示代码优化的每一步 `GOSSAFUNC=func_name go build`
|
||||
<!--rehype:className=style-list-arrow-->
|
||||
|
||||
### Module
|
||||
|
||||
:- | --
|
||||
:- | --
|
||||
`go mod init` | 初始化当前文件夹,创建go.mod文件
|
||||
`go mod download` | 下载依赖的module到本地
|
||||
`go mod tidy` | 增加缺少的module,删除无用的module
|
||||
`go mod vendor` | 将依赖复制到vendor下
|
||||
文件 `go.mod` | 依赖列表和版本约束
|
||||
文件 `go.sum` | 记录 `module` 文件 `hash` 值,用于安全校验
|
||||
<!--rehype:className=style-list-arrow-->
|
||||
|
||||
另见
|
||||
--------
|
||||
|
||||
- [Devhints](https://devhints.io/go) _(devhints.io)_
|
||||
- [A tour of Go](https://tour.golang.org/welcome/1) _(tour.golang.org)_
|
||||
- [Golang wiki](https://github.com/golang/go/wiki/) _(github.com)_
|
||||
|
653
docs/graphql.md
Normal file
653
docs/graphql.md
Normal file
@@ -0,0 +1,653 @@
|
||||
GraphQL 备忘清单
|
||||
===
|
||||
|
||||
这份快速参考备忘单提供了 [GraphQL](https://graphql.org/) 的简要概述
|
||||
|
||||
入门
|
||||
---
|
||||
|
||||
### 概述
|
||||
|
||||
- RESTful API 的另一种方法
|
||||
- GraphQL 是一种 API 查询语言
|
||||
- 使用清晰的共享术语轻松描述 GraphQL API 的形状。
|
||||
- 客户端发出查询/突变以读取和更新数据
|
||||
- GraphQL 语法可以表达复杂的实体关系
|
||||
- 用 [不同语言](https://graphql.org/code/) 实现 GraphQL 的库
|
||||
|
||||
[GraphQL](https://graphql.org/)
|
||||
|
||||
### Schema
|
||||
|
||||
:-|-
|
||||
:-|-
|
||||
`schema` | GraphQL 架构定义
|
||||
`query` | 读取和遍历数据
|
||||
`mutation` | 修改数据或触发动作
|
||||
`subscription` | 发生事件时运行查询
|
||||
|
||||
### 内置标量类型
|
||||
|
||||
:-|-
|
||||
:-|-
|
||||
`Int` | 有符号 32 位整数
|
||||
`Float` | 有符号双精度浮点值
|
||||
`String` | UTF-8 字符序列
|
||||
`Boolean` | 对或错布尔值类型
|
||||
`ID` | 唯一标识符
|
||||
|
||||
### 类型定义
|
||||
|
||||
:-|-
|
||||
:-|-
|
||||
`scalar` | 标量类型
|
||||
`type` | 对象类型
|
||||
`interface` | 接口类型
|
||||
`union` | 联合类型
|
||||
`enum` | 枚举类型
|
||||
`input` | 输入对象类型
|
||||
|
||||
### 类型修饰符
|
||||
|
||||
:-|-
|
||||
:-|-
|
||||
`String` | 可空字符串
|
||||
`String!` | 非空字符串
|
||||
`[String]` | 可空字符串列表
|
||||
`[String]!` | 可空字符串的非空列表
|
||||
`[String!]!` | 非空字符串的非空列表
|
||||
|
||||
### 输入参数
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
#### 基本输入
|
||||
|
||||
```graphql
|
||||
type Query {
|
||||
users(limit: Int): [User]
|
||||
}
|
||||
```
|
||||
|
||||
#### 输入默认值
|
||||
|
||||
```graphql
|
||||
type Query {
|
||||
users(limit: Int = 10): [User]
|
||||
}
|
||||
```
|
||||
|
||||
#### 具有多个参数的输入
|
||||
|
||||
```graphql
|
||||
type Query {
|
||||
users(limit: Int, sort: String): [User]
|
||||
}
|
||||
```
|
||||
|
||||
#### 具有多个参数和默认值的输入
|
||||
|
||||
```graphql
|
||||
type Query {
|
||||
users(limit: Int = 10, sort: String): [User]
|
||||
}
|
||||
type Query {
|
||||
users(limit: Int, sort: String = "asc"): [User]
|
||||
}
|
||||
type Query {
|
||||
users(limit: Int = 10, sort: String = "asc"): [User]
|
||||
}
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 输入类型
|
||||
|
||||
```graphql
|
||||
input ListUsersInput {
|
||||
limit: Int
|
||||
since_id: ID
|
||||
}
|
||||
```
|
||||
|
||||
```graphql
|
||||
type Mutation {
|
||||
users(params: ListUsersInput): [User]!
|
||||
}
|
||||
```
|
||||
|
||||
### 自定义标量
|
||||
|
||||
```graphql
|
||||
scalar Url
|
||||
type User {
|
||||
name: String
|
||||
homepage: Url
|
||||
}
|
||||
```
|
||||
|
||||
### 接口
|
||||
|
||||
```graphql
|
||||
interface Foo {
|
||||
is_foo: Boolean
|
||||
}
|
||||
interface Goo {
|
||||
is_goo: Boolean
|
||||
}
|
||||
type Bar implements Foo {
|
||||
is_foo: Boolean
|
||||
is_bar: Boolean
|
||||
}
|
||||
type Baz implements Foo, Goo {
|
||||
is_foo: Boolean
|
||||
is_goo: Boolean
|
||||
is_baz: Boolean
|
||||
}
|
||||
```
|
||||
|
||||
实现一个或多个接口的对象
|
||||
|
||||
### 联合
|
||||
|
||||
```graphql
|
||||
type Foo {
|
||||
name: String
|
||||
}
|
||||
type Bar {
|
||||
is_bar: String
|
||||
}
|
||||
union SingleUnion = Foo
|
||||
union MultipleUnion = Foo | Bar
|
||||
type Root {
|
||||
single: SingleUnion
|
||||
multiple: MultipleUnion
|
||||
}
|
||||
```
|
||||
|
||||
一个或多个对象的联合
|
||||
|
||||
### 枚举
|
||||
|
||||
```graphql
|
||||
enum USER_STATE {
|
||||
NOT_FOUND
|
||||
ACTIVE
|
||||
INACTIVE
|
||||
SUSPENDED
|
||||
}
|
||||
type Root {
|
||||
stateForUser(userID: ID!): USER_STATE!
|
||||
users(state: USER_STATE, limit: Int = 10): [User]
|
||||
}
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
查询和变更(Mutations)
|
||||
---
|
||||
|
||||
### 字段
|
||||
|
||||
```graphql
|
||||
{
|
||||
hero {
|
||||
name
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
结果:
|
||||
|
||||
```json
|
||||
{
|
||||
"data": {
|
||||
"hero": {
|
||||
"name": "R2-D2"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 查询可以有注释
|
||||
|
||||
```graphql
|
||||
{
|
||||
hero {
|
||||
name
|
||||
# 查询可以有注释!
|
||||
friends {
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
结果:
|
||||
|
||||
```json
|
||||
{
|
||||
"data": {
|
||||
"hero": {
|
||||
"name": "R2-D2",
|
||||
"friends": [
|
||||
{ "name": "Luke Skywalker" },
|
||||
{ "name": "Han Solo" }
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 参数 Arguments
|
||||
|
||||
```graphql
|
||||
{
|
||||
human(id: "1000") {
|
||||
name
|
||||
height
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
结果:
|
||||
|
||||
```json
|
||||
{
|
||||
"data": {
|
||||
"human": {
|
||||
"name": "Luke Skywalker",
|
||||
"height": 1.72
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 不同类型的参数
|
||||
|
||||
```graphql
|
||||
{
|
||||
human(id: "1000") {
|
||||
name
|
||||
height(unit: FOOT)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
结果:
|
||||
|
||||
```json
|
||||
{
|
||||
"data": {
|
||||
"human": {
|
||||
"name": "Luke Skywalker",
|
||||
"height": 5.6430448
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 别名(Aliases)
|
||||
|
||||
```graphql
|
||||
{
|
||||
empireHero: hero(episode: EMPIRE) {
|
||||
name
|
||||
}
|
||||
jediHero: hero(episode: JEDI) {
|
||||
name
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
结果:
|
||||
|
||||
```json
|
||||
{
|
||||
"data": {
|
||||
"empireHero": {
|
||||
"name": "Luke Skywalker"
|
||||
},
|
||||
"jediHero": {
|
||||
"name": "R2-D2"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 片段(Fragments)
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```graphql
|
||||
{
|
||||
leftComparison: hero(episode: EMPIRE) {
|
||||
...comparisonFields
|
||||
}
|
||||
rightComparison: hero(episode: JEDI) {
|
||||
...comparisonFields
|
||||
}
|
||||
}
|
||||
|
||||
fragment comparisonFields on Character {
|
||||
name
|
||||
appearsIn
|
||||
friends {
|
||||
name
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
结果:
|
||||
|
||||
```json
|
||||
{
|
||||
"data": {
|
||||
"leftComparison": {
|
||||
"name": "Luke Skywalker",
|
||||
"appearsIn": [
|
||||
"NEWHOPE",
|
||||
"EMPIRE",
|
||||
"JEDI"
|
||||
],
|
||||
"friends": [
|
||||
{ "name": "Han Solo" },
|
||||
{ "name": "Leia Organa" },
|
||||
{ "name": "C-3PO" },
|
||||
{ "name": "R2-D2" }
|
||||
]
|
||||
},
|
||||
"rightComparison": {
|
||||
"name": "R2-D2",
|
||||
"appearsIn": [
|
||||
"NEWHOPE",
|
||||
"EMPIRE",
|
||||
"JEDI"
|
||||
],
|
||||
"friends": [
|
||||
{ "name": "Luke Skywalker" },
|
||||
{ "name": "Han Solo" },
|
||||
{ "name": "Leia Organa" }
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 在片段内使用变量
|
||||
<!--rehype:wrap-class=row-span-3-->
|
||||
|
||||
```graphql
|
||||
query HeroComparison($first: Int = 3) {
|
||||
leftComparison: hero(episode: EMPIRE) {
|
||||
...comparisonFields
|
||||
}
|
||||
rightComparison: hero(episode: JEDI) {
|
||||
...comparisonFields
|
||||
}
|
||||
}
|
||||
|
||||
fragment comparisonFields on Character {
|
||||
name
|
||||
friendsConnection(first: $first) {
|
||||
totalCount
|
||||
edges {
|
||||
node {
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
结果:
|
||||
|
||||
```json
|
||||
{
|
||||
"data": {
|
||||
"leftComparison": {
|
||||
"name": "Luke Skywalker",
|
||||
"friendsConnection": {
|
||||
"totalCount": 4,
|
||||
"edges": [
|
||||
{
|
||||
"node": {
|
||||
"name": "Han Solo"
|
||||
}
|
||||
},
|
||||
{
|
||||
"node": {
|
||||
"name": "Leia Organa"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"rightComparison": {
|
||||
"name": "R2-D2",
|
||||
"friendsConnection": {
|
||||
"totalCount": 3,
|
||||
"edges": [
|
||||
{
|
||||
"node": {
|
||||
"name": "Luke Skywalker"
|
||||
}
|
||||
},
|
||||
{
|
||||
"node": {
|
||||
"name": "Han Solo"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 操作名称(Operation name)
|
||||
|
||||
```graphql
|
||||
query HeroNameAndFriends {
|
||||
hero {
|
||||
name
|
||||
friends {
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
结果:
|
||||
|
||||
```json
|
||||
{
|
||||
"data": {
|
||||
"hero": {
|
||||
"name": "R2-D2",
|
||||
"friends": [
|
||||
{ "name": "Luke Skywalker" },
|
||||
{ "name": "Han Solo" },
|
||||
{ "name": "Leia Organa" }
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 变量(Variables)
|
||||
|
||||
```graphql
|
||||
# { "graphiql": true, "variables": { "episode": JEDI } }
|
||||
query HeroNameAndFriends($episode: Episode) {
|
||||
hero(episode: $episode) {
|
||||
name
|
||||
friends {
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
变量前缀必须为 `$`,后跟其类型
|
||||
|
||||
### 默认变量(Default variables)
|
||||
|
||||
```graphql
|
||||
query HeroNameAndFriends($episode: Episode = "JEDI") {
|
||||
hero(episode: $episode) {
|
||||
name
|
||||
friends {
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 指令(Directives)
|
||||
|
||||
```graphql
|
||||
query Hero($episode: Episode, $withFriends: Boolean!) {
|
||||
hero(episode: $episode) {
|
||||
name
|
||||
friends @include(if: $withFriends) {
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
----
|
||||
|
||||
```graphql
|
||||
{ "episode": "JEDI", "withFriends": false }
|
||||
```
|
||||
|
||||
结果:
|
||||
|
||||
```json
|
||||
{
|
||||
"data": { "hero": { "name": "R2-D2" } }
|
||||
}
|
||||
```
|
||||
|
||||
- `@include(if: Boolean)` 仅在参数为 `true` 时,包含此字段
|
||||
- `@skip(if: Boolean)` 如果参数为 `true`,跳过此字段
|
||||
|
||||
### 变更(Mutations)
|
||||
|
||||
```graphql
|
||||
mutation CreateReviewForEpisode($ep: Episode!, $review: ReviewInput!) {
|
||||
createReview(episode: $ep, review: $review) {
|
||||
stars
|
||||
commentary
|
||||
}
|
||||
}
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
----
|
||||
|
||||
```
|
||||
{
|
||||
"ep": "JEDI",
|
||||
"review": {
|
||||
"stars": 5,
|
||||
"commentary": "This is a great movie!"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
结果:
|
||||
|
||||
```json
|
||||
{
|
||||
"data": {
|
||||
"createReview": {
|
||||
"stars": 5,
|
||||
"commentary": "This is a great movie!"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 内联片段(Inline Fragments)
|
||||
|
||||
```graphql
|
||||
query HeroForEpisode($ep: Episode!) {
|
||||
hero(episode: $ep) {
|
||||
name
|
||||
... on Droid {
|
||||
primaryFunction
|
||||
}
|
||||
... on Human {
|
||||
height
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
```graphql
|
||||
{ "ep": "JEDI" }
|
||||
```
|
||||
|
||||
结果:
|
||||
|
||||
```json
|
||||
{
|
||||
"data": {
|
||||
"hero": {
|
||||
"name": "R2-D2",
|
||||
"primaryFunction": "Astromech"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 元字段(Meta fields)
|
||||
|
||||
```graphql
|
||||
{
|
||||
search(text: "an") {
|
||||
__typename
|
||||
... on Human {
|
||||
name
|
||||
}
|
||||
... on Droid {
|
||||
name
|
||||
}
|
||||
... on Starship {
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
结果:
|
||||
|
||||
```json
|
||||
{
|
||||
"data": {
|
||||
"search": [
|
||||
{
|
||||
"__typename": "Human",
|
||||
"name": "Han Solo"
|
||||
},
|
||||
{
|
||||
"__typename": "Human",
|
||||
"name": "Leia Organa"
|
||||
},
|
||||
{
|
||||
"__typename": "Starship",
|
||||
"name": "TIE Advanced x1"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
另见
|
||||
-------
|
||||
|
||||
- [GraphQL Schema Language Cheat Sheet](https://github.com/sogko/graphql-schema-language-cheat-sheet) _(github.com)_
|
@@ -3,7 +3,6 @@ Grep 备忘清单
|
||||
|
||||
本备忘单旨在快速提醒使用命令行程序 grep 所涉及的主要概念,并假设您已经了解其用法。
|
||||
|
||||
|
||||
入门
|
||||
------
|
||||
<!--rehype:body-class=cols-5-->
|
||||
@@ -31,7 +30,6 @@ $ grep 'mellon' myfile.txt
|
||||
|
||||
文件名中接受通配符。
|
||||
|
||||
|
||||
### 选项示例
|
||||
<!--rehype:wrap-class=col-span-3-->
|
||||
|
||||
@@ -51,7 +49,6 @@ $ grep 'mellon' myfile.txt
|
||||
| `-o` | grep -o search_string filename | 只显示字符串的匹配部分
|
||||
| `-n` | grep -n "go" demo.txt | 显示匹配的行号
|
||||
|
||||
|
||||
Grep 正则表达式
|
||||
-------
|
||||
|
||||
@@ -97,7 +94,6 @@ Grep 正则表达式
|
||||
`[0-9]` | 任何数字
|
||||
`[0-9A-Za-z]` | 任何大小写字母或数字
|
||||
|
||||
|
||||
### 位置
|
||||
|
||||
:- | :-
|
||||
|
@@ -3,7 +3,6 @@ HTML 字符实体备忘清单
|
||||
|
||||
此备忘清单是 HTML 实体及其编号和名称的完整列表。还包括可以用 HTML 表示的 ASCII 字符的完整列表。
|
||||
|
||||
|
||||
HTML 字符实体引用
|
||||
------
|
||||
<!--rehype:body-class=cols-1-->
|
||||
|
28
docs/html.md
28
docs/html.md
@@ -43,6 +43,7 @@ HTML 备忘清单
|
||||
<p>我来自快速参考</p>
|
||||
<p>分享快速参考备忘单。</p>
|
||||
```
|
||||
|
||||
请参阅:[段落元素](https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/p)
|
||||
|
||||
### HTML 链接
|
||||
@@ -68,8 +69,6 @@ HTML 备忘清单
|
||||
|
||||
请参阅:[\<a> 属性](https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/a#attributes)
|
||||
|
||||
|
||||
|
||||
### Image 标签
|
||||
|
||||
```html
|
||||
@@ -163,10 +162,8 @@ HTML 备忘清单
|
||||
src="https://www.openstreetmap.org/export/embed.html?bbox=-0.004017949104309083%2C51.47612752641776%2C0.00030577182769775396%2C51.478569861898606&layer=mapnik">
|
||||
</iframe>
|
||||
|
||||
|
||||
请参阅:[内联框架元素](https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/iframe)
|
||||
|
||||
|
||||
### HTML 中的 JavaScript
|
||||
|
||||
```html
|
||||
@@ -176,7 +173,6 @@ HTML 备忘清单
|
||||
</script>
|
||||
```
|
||||
|
||||
|
||||
#### 外部 JavaScript
|
||||
|
||||
```html
|
||||
@@ -186,7 +182,6 @@ HTML 备忘清单
|
||||
</body>
|
||||
```
|
||||
|
||||
|
||||
### HTML 中的 CSS
|
||||
|
||||
```html
|
||||
@@ -206,8 +201,6 @@ HTML 备忘清单
|
||||
</head>
|
||||
```
|
||||
|
||||
|
||||
|
||||
HTML5 标签
|
||||
-------------
|
||||
|
||||
@@ -227,7 +220,6 @@ HTML5 标签
|
||||
</body>
|
||||
```
|
||||
|
||||
|
||||
### 标题导航
|
||||
|
||||
```html
|
||||
@@ -242,7 +234,6 @@ HTML5 标签
|
||||
</header>
|
||||
```
|
||||
|
||||
|
||||
### HTML5 Tags
|
||||
<!--rehype:wrap-class=row-span-4-->
|
||||
|
||||
@@ -281,7 +272,6 @@ HTML5 标签
|
||||
[video](https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/video) | 嵌入视频
|
||||
[wbr](https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/wbr) | 换行机会
|
||||
|
||||
|
||||
### HTML5 Video
|
||||
|
||||
```html
|
||||
@@ -339,7 +329,6 @@ HTML5 标签
|
||||
音 <rp>(</rp><rt>yīn</rt><rp>)</rp>
|
||||
</ruby>
|
||||
|
||||
|
||||
### HTML5 kdi
|
||||
|
||||
```html
|
||||
@@ -358,7 +347,6 @@ HTML5 标签
|
||||
<li>User <bdi>إيان</bdi>: 90 points</li>
|
||||
</ul>
|
||||
|
||||
|
||||
### HTML5 progress
|
||||
|
||||
```html
|
||||
@@ -375,7 +363,6 @@ HTML5 标签
|
||||
|
||||
<p>我爱<mark>备忘清单</mark></p>
|
||||
|
||||
|
||||
HTML 表格
|
||||
--------------
|
||||
|
||||
@@ -517,7 +504,6 @@ HTML 表单
|
||||
<label for="ck">记住我</label>
|
||||
</form>
|
||||
|
||||
|
||||
HTML `<form>` 元素用于收集信息并将其发送到外部源。
|
||||
|
||||
### Form 属性
|
||||
@@ -602,13 +588,16 @@ Textarea 是一个多行文本输入控件
|
||||
单选按钮用于让用户只选择一个
|
||||
|
||||
### Checkboxes
|
||||
|
||||
```html
|
||||
<input type="checkbox" name="s" id="soc">
|
||||
<label for="soc">Soccer</label>
|
||||
<input type="checkbox" name="s" id="bas">
|
||||
<label for="bas">Baseball</label>
|
||||
```
|
||||
|
||||
#### ↓ 预览
|
||||
|
||||
<form style="padding: 20px;">
|
||||
<input type="checkbox" name="sports" id="soccer">
|
||||
<label for="soccer">Soccer</label>
|
||||
@@ -718,7 +707,6 @@ Textarea 是一个多行文本输入控件
|
||||
|
||||
`将数据提交到服务器` 重置为默认值
|
||||
|
||||
|
||||
HTML input 标签
|
||||
-----------
|
||||
<!--rehype:body-class=cols-2-->
|
||||
@@ -732,7 +720,7 @@ HTML input 标签
|
||||
<input type="text" name="?" value="?" minlength="6" required />
|
||||
```
|
||||
|
||||
----
|
||||
---
|
||||
|
||||
:-|:-
|
||||
:-|:-
|
||||
@@ -794,7 +782,6 @@ HTML input 标签
|
||||
| `type="search"` | <input type="search"> |
|
||||
| `type="range"` | <input type="range"> |
|
||||
|
||||
|
||||
### Input CSS 选择器
|
||||
|
||||
| | |
|
||||
@@ -820,6 +807,7 @@ meta 标记描述 HTML 文档中的元数据。它解释了关于 HTML 的其他
|
||||
<meta property="og:title" content="···">
|
||||
<meta name="twitter:title" content="···">
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```html
|
||||
@@ -828,6 +816,7 @@ meta 标记描述 HTML 文档中的元数据。它解释了关于 HTML 的其他
|
||||
<meta property="og:url" content="https://···">
|
||||
<meta name="twitter:url" content="https://···">
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```html
|
||||
@@ -836,6 +825,7 @@ meta 标记描述 HTML 文档中的元数据。它解释了关于 HTML 的其他
|
||||
<meta property="og:description" content="···">
|
||||
<meta name="twitter:description" content="···">
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```html
|
||||
@@ -843,12 +833,14 @@ meta 标记描述 HTML 文档中的元数据。它解释了关于 HTML 的其他
|
||||
<meta property="og:image" content="https://···">
|
||||
<meta name="twitter:image" content="https://···">
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```html
|
||||
<!-- ua -->
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```html
|
||||
|
@@ -17,63 +17,63 @@ HTTP 状态码
|
||||
### 2xx. 成功的
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
* [200: OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) _请求没问题_<!--rehype:tooltips-->
|
||||
* [201: Created](https://tools.ietf.org/html/rfc7231#section-6.3.2) _请求完成,并创建了一个新资源_<!--rehype:tooltips-->
|
||||
* [202: Accepted](https://tools.ietf.org/html/rfc7231#section-6.3.3) _接受请求进行处理,但处理未完成_<!--rehype:tooltips-->
|
||||
* [203: Non-Authoritative Information](https://tools.ietf.org/html/rfc7231#section-6.3.4) _实体标头中的信息来自本地或第三方副本,而不是来自原始服务器_<!--rehype:tooltips-->
|
||||
* [204: No Content](https://tools.ietf.org/html/rfc7231#section-6.3.5) _响应中给出了状态码和标头,但响应中没有实体主体_<!--rehype:tooltips-->
|
||||
* [205: Reset Content](https://tools.ietf.org/html/rfc7231#section-6.3.6) _浏览器应清除用于此事务的表单以获取其他输入_<!--rehype:tooltips-->
|
||||
* [206: Partial Content](https://tools.ietf.org/html/rfc7233#section-4.1) _服务器正在返回请求大小的部分数据。 用于响应指定 Range 标头的请求。 服务器必须使用 Content-Range 标头指定响应中包含的范围_<!--rehype:tooltips-->
|
||||
- [200: OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) _请求没问题_<!--rehype:tooltips-->
|
||||
- [201: Created](https://tools.ietf.org/html/rfc7231#section-6.3.2) _请求完成,并创建了一个新资源_<!--rehype:tooltips-->
|
||||
- [202: Accepted](https://tools.ietf.org/html/rfc7231#section-6.3.3) _接受请求进行处理,但处理未完成_<!--rehype:tooltips-->
|
||||
- [203: Non-Authoritative Information](https://tools.ietf.org/html/rfc7231#section-6.3.4) _实体标头中的信息来自本地或第三方副本,而不是来自原始服务器_<!--rehype:tooltips-->
|
||||
- [204: No Content](https://tools.ietf.org/html/rfc7231#section-6.3.5) _响应中给出了状态码和标头,但响应中没有实体主体_<!--rehype:tooltips-->
|
||||
- [205: Reset Content](https://tools.ietf.org/html/rfc7231#section-6.3.6) _浏览器应清除用于此事务的表单以获取其他输入_<!--rehype:tooltips-->
|
||||
- [206: Partial Content](https://tools.ietf.org/html/rfc7233#section-4.1) _服务器正在返回请求大小的部分数据。 用于响应指定 Range 标头的请求。 服务器必须使用 Content-Range 标头指定响应中包含的范围_<!--rehype:tooltips-->
|
||||
|
||||
### 4xx. 客户端错误
|
||||
<!--rehype:wrap-class=row-span-3-->
|
||||
|
||||
* [400: Bad Request](https://tools.ietf.org/html/rfc7231#section-6.5.1) _服务器不理解该请求_<!--rehype:tooltips-->
|
||||
* [401: Unauthorized](https://tools.ietf.org/html/rfc7235#section-3.1) _请求的页面需要用户名和密码_<!--rehype:tooltips-->
|
||||
* [402: Payment Required](https://tools.ietf.org/html/rfc7231#section-6.5.2) _您还不能使用此代码_<!--rehype:tooltips-->
|
||||
* [403: Forbidden](https://tools.ietf.org/html/rfc7231#section-6.5.3) _禁止访问请求的页面_<!--rehype:tooltips-->
|
||||
* [404: Not Found](https://tools.ietf.org/html/rfc7231#section-6.5.4) _服务器找不到请求的页面_<!--rehype:tooltips-->
|
||||
* [405: Method Not Allowed](https://tools.ietf.org/html/rfc7231#section-6.5.5) _请求中指定的方法是不允许的_<!--rehype:tooltips-->
|
||||
* [406: Not Acceptable](https://tools.ietf.org/html/rfc7231#section-6.5.6) _服务器只能生成客户端不接受的响应_<!--rehype:tooltips-->
|
||||
* [407: Proxy Authentication Required](https://tools.ietf.org/html/rfc7235#section-3.2) _您必须先通过代理服务器进行身份验证,然后才能提供此请求_<!--rehype:tooltips-->
|
||||
* [408: Request Timeout](https://tools.ietf.org/html/rfc7231#section-6.5.7) _请求花费的时间比服务器准备等待的时间长_<!--rehype:tooltips-->
|
||||
* [409: Conflict](https://tools.ietf.org/html/rfc7231#section-6.5.8) _由于冲突,请求无法完成_<!--rehype:tooltips-->
|
||||
* [410: Gone](https://tools.ietf.org/html/rfc7231#section-6.5.9) _请求的页面不再可用_<!--rehype:tooltips-->
|
||||
* [411: Length Required](https://tools.ietf.org/html/rfc7231#section-6.5.10) _“Content-Length”未定义。 没有它,服务器将不会接受请求_<!--rehype:tooltips-->
|
||||
* [412: Precondition Failed](https://tools.ietf.org/html/rfc7232#section-4.2) _请求中给出的前提条件被服务器评估为 false_<!--rehype:tooltips-->
|
||||
* [413: Payload Too Large](https://tools.ietf.org/html/rfc7231#section-6.5.11) _服务器不会接受请求,因为请求实体太大_<!--rehype:tooltips-->
|
||||
* [414: URI Too Long](https://tools.ietf.org/html/rfc7231#section-6.5.12) _服务器不会接受请求,因为 url 太长。 当您将“发布”请求转换为具有长查询信息的“获取”请求时发生_<!--rehype:tooltips-->
|
||||
* [415: Unsupported Media Type](https://tools.ietf.org/html/rfc7231#section-6.5.13) _服务器不会接受请求,因为不支持媒体类型_<!--rehype:tooltips-->
|
||||
* [416: Range Not Satisfiable](https://tools.ietf.org/html/rfc7233#section-4.4) _请求的字节范围不可用且超出范围_<!--rehype:tooltips-->
|
||||
* [417: Expectation Failed](https://tools.ietf.org/html/rfc7231#section-6.5.14) _此服务器无法满足在 Expect 请求标头字段中给出的期望_<!--rehype:tooltips-->
|
||||
* [426: Upgrade Required](https://tools.ietf.org/html/rfc7231#section-6.5.15) _服务器拒绝使用当前协议执行请求,但在客户端升级到不同协议后可能愿意这样做_<!--rehype:tooltips-->
|
||||
* [451: Unavailable For Legal Reasons](https://datatracker.ietf.org/doc/html/rfc7725#section-3) _此状态代码表示服务器拒绝访问资源作为法律要求的结果_<!--rehype:tooltips-->
|
||||
- [400: Bad Request](https://tools.ietf.org/html/rfc7231#section-6.5.1) _服务器不理解该请求_<!--rehype:tooltips-->
|
||||
- [401: Unauthorized](https://tools.ietf.org/html/rfc7235#section-3.1) _请求的页面需要用户名和密码_<!--rehype:tooltips-->
|
||||
- [402: Payment Required](https://tools.ietf.org/html/rfc7231#section-6.5.2) _您还不能使用此代码_<!--rehype:tooltips-->
|
||||
- [403: Forbidden](https://tools.ietf.org/html/rfc7231#section-6.5.3) _禁止访问请求的页面_<!--rehype:tooltips-->
|
||||
- [404: Not Found](https://tools.ietf.org/html/rfc7231#section-6.5.4) _服务器找不到请求的页面_<!--rehype:tooltips-->
|
||||
- [405: Method Not Allowed](https://tools.ietf.org/html/rfc7231#section-6.5.5) _请求中指定的方法是不允许的_<!--rehype:tooltips-->
|
||||
- [406: Not Acceptable](https://tools.ietf.org/html/rfc7231#section-6.5.6) _服务器只能生成客户端不接受的响应_<!--rehype:tooltips-->
|
||||
- [407: Proxy Authentication Required](https://tools.ietf.org/html/rfc7235#section-3.2) _您必须先通过代理服务器进行身份验证,然后才能提供此请求_<!--rehype:tooltips-->
|
||||
- [408: Request Timeout](https://tools.ietf.org/html/rfc7231#section-6.5.7) _请求花费的时间比服务器准备等待的时间长_<!--rehype:tooltips-->
|
||||
- [409: Conflict](https://tools.ietf.org/html/rfc7231#section-6.5.8) _由于冲突,请求无法完成_<!--rehype:tooltips-->
|
||||
- [410: Gone](https://tools.ietf.org/html/rfc7231#section-6.5.9) _请求的页面不再可用_<!--rehype:tooltips-->
|
||||
- [411: Length Required](https://tools.ietf.org/html/rfc7231#section-6.5.10) _“Content-Length”未定义。 没有它,服务器将不会接受请求_<!--rehype:tooltips-->
|
||||
- [412: Precondition Failed](https://tools.ietf.org/html/rfc7232#section-4.2) _请求中给出的前提条件被服务器评估为 false_<!--rehype:tooltips-->
|
||||
- [413: Payload Too Large](https://tools.ietf.org/html/rfc7231#section-6.5.11) _服务器不会接受请求,因为请求实体太大_<!--rehype:tooltips-->
|
||||
- [414: URI Too Long](https://tools.ietf.org/html/rfc7231#section-6.5.12) _服务器不会接受请求,因为 url 太长。 当您将“发布”请求转换为具有长查询信息的“获取”请求时发生_<!--rehype:tooltips-->
|
||||
- [415: Unsupported Media Type](https://tools.ietf.org/html/rfc7231#section-6.5.13) _服务器不会接受请求,因为不支持媒体类型_<!--rehype:tooltips-->
|
||||
- [416: Range Not Satisfiable](https://tools.ietf.org/html/rfc7233#section-4.4) _请求的字节范围不可用且超出范围_<!--rehype:tooltips-->
|
||||
- [417: Expectation Failed](https://tools.ietf.org/html/rfc7231#section-6.5.14) _此服务器无法满足在 Expect 请求标头字段中给出的期望_<!--rehype:tooltips-->
|
||||
- [426: Upgrade Required](https://tools.ietf.org/html/rfc7231#section-6.5.15) _服务器拒绝使用当前协议执行请求,但在客户端升级到不同协议后可能愿意这样做_<!--rehype:tooltips-->
|
||||
- [451: Unavailable For Legal Reasons](https://datatracker.ietf.org/doc/html/rfc7725#section-3) _此状态代码表示服务器拒绝访问资源作为法律要求的结果_<!--rehype:tooltips-->
|
||||
|
||||
### 1xx. 信息
|
||||
|
||||
* [100: Continue](https://tools.ietf.org/html/rfc7231#section-6.2.1) _服务器只收到了请求的一部分,但只要没有被拒绝,客户端就应该继续请求_<!--rehype:tooltips-->
|
||||
* [101: Switching Protocols](https://tools.ietf.org/html/rfc7231#section-6.2.2) _服务器切换协议_<!--rehype:tooltips-->
|
||||
* [102: Processing](https://tools.ietf.org/html/rfc2518#section-10.1) _用于通知客户端服务器已接受完整请求但尚未完成的临时响应_<!--rehype:tooltips-->
|
||||
- [100: Continue](https://tools.ietf.org/html/rfc7231#section-6.2.1) _服务器只收到了请求的一部分,但只要没有被拒绝,客户端就应该继续请求_<!--rehype:tooltips-->
|
||||
- [101: Switching Protocols](https://tools.ietf.org/html/rfc7231#section-6.2.2) _服务器切换协议_<!--rehype:tooltips-->
|
||||
- [102: Processing](https://tools.ietf.org/html/rfc2518#section-10.1) _用于通知客户端服务器已接受完整请求但尚未完成的临时响应_<!--rehype:tooltips-->
|
||||
|
||||
### 3xx. 重定向
|
||||
|
||||
* [300: Multiple Choices](https://tools.ietf.org/html/rfc7231#section-6.4.1) _一个链接列表。 用户可以选择一个链接并转到该位置。 最多五个地址_<!--rehype:tooltips-->
|
||||
* [301: Moved Permanently](https://tools.ietf.org/html/rfc7231#section-6.4.2) _请求的页面已移至新的 url_<!--rehype:tooltips-->
|
||||
* [302: Found](https://tools.ietf.org/html/rfc7231#section-6.4.3) _请求的页面已临时移动到新的 url_<!--rehype:tooltips-->
|
||||
* [303: See Other](https://tools.ietf.org/html/rfc7231#section-6.4.4) _请求的页面可以在不同的 url 下找到_<!--rehype:tooltips-->
|
||||
* [304: Not Modified](https://tools.ietf.org/html/rfc7232#section-4.1) _这是对 If-Modified-Since 或 If-None-Match 标头的响应代码,其中 URL 自指定日期以来未修改_<!--rehype:tooltips-->
|
||||
* [305: Use Proxy](https://tools.ietf.org/html/rfc7231#section-6.4.5) _请求的 URL 必须通过 Location 标头中提到的代理访问_<!--rehype:tooltips-->
|
||||
* [306: Unused](https://tools.ietf.org/html/rfc7231#section-6.4.6) _此代码在以前的版本中使用过。 它不再使用,但代码被保留_<!--rehype:tooltips-->
|
||||
* [307: Temporary Redirect](https://tools.ietf.org/html/rfc7231#section-6.4.7) _请求的页面已临时移动到新的 url_<!--rehype:tooltips-->
|
||||
- [300: Multiple Choices](https://tools.ietf.org/html/rfc7231#section-6.4.1) _一个链接列表。 用户可以选择一个链接并转到该位置。 最多五个地址_<!--rehype:tooltips-->
|
||||
- [301: Moved Permanently](https://tools.ietf.org/html/rfc7231#section-6.4.2) _请求的页面已移至新的 url_<!--rehype:tooltips-->
|
||||
- [302: Found](https://tools.ietf.org/html/rfc7231#section-6.4.3) _请求的页面已临时移动到新的 url_<!--rehype:tooltips-->
|
||||
- [303: See Other](https://tools.ietf.org/html/rfc7231#section-6.4.4) _请求的页面可以在不同的 url 下找到_<!--rehype:tooltips-->
|
||||
- [304: Not Modified](https://tools.ietf.org/html/rfc7232#section-4.1) _这是对 If-Modified-Since 或 If-None-Match 标头的响应代码,其中 URL 自指定日期以来未修改_<!--rehype:tooltips-->
|
||||
- [305: Use Proxy](https://tools.ietf.org/html/rfc7231#section-6.4.5) _请求的 URL 必须通过 Location 标头中提到的代理访问_<!--rehype:tooltips-->
|
||||
- [306: Unused](https://tools.ietf.org/html/rfc7231#section-6.4.6) _此代码在以前的版本中使用过。 它不再使用,但代码被保留_<!--rehype:tooltips-->
|
||||
- [307: Temporary Redirect](https://tools.ietf.org/html/rfc7231#section-6.4.7) _请求的页面已临时移动到新的 url_<!--rehype:tooltips-->
|
||||
|
||||
### 5xx. 服务器错误
|
||||
|
||||
* [500: Internal Server Error](https://tools.ietf.org/html/rfc7231#section-6.6.1) _请求未完成。服务器遇到了意外情况_<!--rehype:tooltips-->
|
||||
* [501: Not Implemented](https://tools.ietf.org/html/rfc7231#section-6.6.2) _请求未完成。服务器不支持所需的功能_<!--rehype:tooltips-->
|
||||
* [502: Bad Gateway](https://tools.ietf.org/html/rfc7231#section-6.6.3) _请求未完成。服务器收到来自上游服务器的无效响应_<!--rehype:tooltips-->
|
||||
* [503: Service Unavailable](https://tools.ietf.org/html/rfc7231#section-6.6.4) _请求未完成。服务器暂时超载或停机_<!--rehype:tooltips-->
|
||||
* [504: Gateway Timeout](https://tools.ietf.org/html/rfc7231#section-6.6.5) _网关已超时_<!--rehype:tooltips-->
|
||||
* [505: HTTP Version Not Supported](https://tools.ietf.org/html/rfc7231#section-6.6.6) _服务器不支持“http 协议”版本_<!--rehype:tooltips-->
|
||||
- [500: Internal Server Error](https://tools.ietf.org/html/rfc7231#section-6.6.1) _请求未完成。服务器遇到了意外情况_<!--rehype:tooltips-->
|
||||
- [501: Not Implemented](https://tools.ietf.org/html/rfc7231#section-6.6.2) _请求未完成。服务器不支持所需的功能_<!--rehype:tooltips-->
|
||||
- [502: Bad Gateway](https://tools.ietf.org/html/rfc7231#section-6.6.3) _请求未完成。服务器收到来自上游服务器的无效响应_<!--rehype:tooltips-->
|
||||
- [503: Service Unavailable](https://tools.ietf.org/html/rfc7231#section-6.6.4) _请求未完成。服务器暂时超载或停机_<!--rehype:tooltips-->
|
||||
- [504: Gateway Timeout](https://tools.ietf.org/html/rfc7231#section-6.6.5) _网关已超时_<!--rehype:tooltips-->
|
||||
- [505: HTTP Version Not Supported](https://tools.ietf.org/html/rfc7231#section-6.6.6) _服务器不支持“http 协议”版本_<!--rehype:tooltips-->
|
||||
|
||||
### RESTful API
|
||||
|
||||
|
@@ -3,7 +3,6 @@ ISO 639-1 Language Code 备忘清单
|
||||
|
||||
这是一个符合 ISO 639-1 标准的 ISO 语言代码列表,它为多语言网站提供参考。
|
||||
|
||||
|
||||
入门
|
||||
----
|
||||
|
||||
|
63
docs/java.md
63
docs/java.md
@@ -73,6 +73,7 @@ for (char c: word.toCharArray()) {
|
||||
}
|
||||
// 输出: Q-u-i-c-k-R-e-f-
|
||||
```
|
||||
|
||||
查看: [Loops](#java-循环)
|
||||
|
||||
### 数组 Arrays
|
||||
@@ -85,6 +86,7 @@ String[] letters = {"A", "B", "C"};
|
||||
int[] mylist = {100, 200};
|
||||
boolean[] answers = {true, false};
|
||||
```
|
||||
|
||||
查看: [Arrays](#java-数组)
|
||||
|
||||
### Swap
|
||||
@@ -127,9 +129,10 @@ if (j == 10) {
|
||||
}
|
||||
```
|
||||
|
||||
查看: [Conditionals](#java-conditionals)
|
||||
查看: [Conditionals](#条件语句 Conditionals)
|
||||
|
||||
### 用户输入
|
||||
|
||||
```java
|
||||
Scanner in = new Scanner(System.in);
|
||||
String str = in.nextLine();
|
||||
@@ -175,48 +178,60 @@ StringBuilder sb = new StringBuilder(10);
|
||||
└───┴───┴───┴───┴───┴───┴───┴───┴───┘
|
||||
0 1 2 3 4 5 6 7 8 9
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```java
|
||||
sb.append("Reference");
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```java
|
||||
┌───┬───┬───┬───┬───┬───┬───┬───┬───┐
|
||||
| R | e | f | e | r | e | n | c | e |
|
||||
└───┴───┴───┴───┴───┴───┴───┴───┴───┘
|
||||
0 1 2 3 4 5 6 7 8 9
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```java
|
||||
sb.delete(3, 9);
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```java
|
||||
┌───┬───┬───┬───┬───┬───┬───┬───┬───┐
|
||||
| R | e | f | | | | | | |
|
||||
└───┴───┴───┴───┴───┴───┴───┴───┴───┘
|
||||
0 1 2 3 4 5 6 7 8 9
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```java
|
||||
sb.insert(0, "My ");
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```java
|
||||
┌───┬───┬───┬───┬───┬───┬───┬───┬───┐
|
||||
| M | y | | R | e | f | | | |
|
||||
└───┴───┴───┴───┴───┴───┴───┴───┴───┘
|
||||
0 1 2 3 4 5 6 7 8 9
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```java
|
||||
sb.append("!");
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```java
|
||||
┌───┬───┬───┬───┬───┬───┬───┬───┬───┐
|
||||
| M | y | | R | e | f | ! | | |
|
||||
@@ -286,7 +301,7 @@ System.out.println(concat);
|
||||
Java 数组
|
||||
-------
|
||||
|
||||
### 申明 Declare
|
||||
### 声明 Declare
|
||||
|
||||
```java
|
||||
int[] a1;
|
||||
@@ -370,7 +385,7 @@ Java 条件语句
|
||||
- `!` _(逻辑补码运算符;反转布尔值)_
|
||||
<!--rehype:className=style-round-->
|
||||
|
||||
----
|
||||
---
|
||||
|
||||
- `==` _(等于)_
|
||||
- `!=` _(不等于)_
|
||||
@@ -380,19 +395,19 @@ Java 条件语句
|
||||
- `<=` _(小于或等于)_
|
||||
<!--rehype:className=cols-2 style-round-->
|
||||
|
||||
----
|
||||
---
|
||||
|
||||
- `&&` _条件与_
|
||||
- `||` _条件或_
|
||||
- [?:](#三元运算符) _三元(if-then-else 语句的简写)_
|
||||
<!--rehype:className=style-round-->
|
||||
|
||||
----
|
||||
---
|
||||
|
||||
- `instanceof` _(将对象与指定类型进行比较)_
|
||||
<!--rehype:className=style-round-->
|
||||
|
||||
----
|
||||
---
|
||||
|
||||
- `~` _(一元按位补码)_
|
||||
- `<<` _(签名左移)_
|
||||
@@ -462,7 +477,7 @@ for (int i = 0; i < 10; i++) {
|
||||
// 输出: 0123456789
|
||||
```
|
||||
|
||||
------
|
||||
---
|
||||
|
||||
```java
|
||||
for (int i = 0,j = 0; i < 3; i++,j--) {
|
||||
@@ -768,6 +783,40 @@ try {
|
||||
}
|
||||
```
|
||||
|
||||
### 反射
|
||||
|
||||
```java
|
||||
/**
|
||||
* 利用反射动态加载依赖库
|
||||
* java9及以上版本可用
|
||||
* @param jar jar文件
|
||||
*/
|
||||
Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
|
||||
method.setAccessible(true);
|
||||
MethodHandle addURL = lookup.unreflect(method);
|
||||
URL url = jar.toURI().toURL();
|
||||
URLClassLoader urlClassLoader = new URLClassLoader(new URL[] {url});
|
||||
addURL.invoke(urlClassLoader, url);
|
||||
//java8
|
||||
Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
|
||||
method.setAccessible(true);
|
||||
method.invoke(classLoader, url);
|
||||
```
|
||||
|
||||
### util工具类
|
||||
|
||||
- `ArrayDeque` 提供 resizable-array 并实现 Deque 接
|
||||
- `Arrays` 包含一个静态工厂,允许将数组视为列表
|
||||
- `Collections` 包含对集合进行操作或返回集合的静态方法
|
||||
- `Date` 表示特定的时间瞬间,精度为毫秒
|
||||
- `Dictionary` 是任何类的抽象父类,例如 Hashtable,它将键映射到值
|
||||
- `EnumMap` 一个专门用于枚举键的 Map 实现
|
||||
- `EnumSet` 一个专门用于枚举键的 Set 实现
|
||||
- `Formatter` 提供对布局对齐和对齐、数字、字符串和日期/时间数据的常用格式以及特定于语言环境的输出的支持
|
||||
- `SecureRandom` 实例用于生成安全的伪随机数流
|
||||
- `UUID` 表示一个不可变的通用唯一标识符
|
||||
- `Vector` 实现了一个可增长的对象数组
|
||||
|
||||
另见
|
||||
---
|
||||
|
||||
|
@@ -42,6 +42,7 @@ function potentiallyBuggyCode() {
|
||||
let amount = 6;
|
||||
let price = 4.99;
|
||||
let home = 1e2;
|
||||
let num = 1_000_000; // 位数过多可以用 _ 分割
|
||||
let m = 0644; // 八进制数字 420
|
||||
```
|
||||
|
||||
@@ -54,7 +55,6 @@ count = 10;
|
||||
console.log(count); // => 10
|
||||
```
|
||||
|
||||
|
||||
### const 关键字
|
||||
|
||||
```javascript
|
||||
@@ -148,8 +148,19 @@ abc.charCodeAt(2);
|
||||
abc.split(",");
|
||||
// 分割字符
|
||||
abc.split("");
|
||||
// 匹配开头字符串,如果忽略第二个参数,则从索引 0 开始匹配
|
||||
abc.startsWith("bc", 1);
|
||||
// 匹配结尾的字符串,如果忽略第二个参数,则默认是原字符串长度
|
||||
abc.endsWith("wxy", abc.length - 1);
|
||||
// padEnd 和 padStart 都用于填充长度,默认填充对象是空格
|
||||
"200".padEnd(5); // "200 "
|
||||
"200".padEnd(5, "."); // "200.."
|
||||
// 重复字符
|
||||
"abc".repeat(2); // "abcabc"
|
||||
// trim、trimEnd 和 trimStart 用于去除首尾空格
|
||||
" ab c ".trim(); // "ab c"
|
||||
// 数字转为十六进制 (16)、八进制 (8) 或二进制 (2)
|
||||
128.toString(16);
|
||||
(128).toString(16);
|
||||
```
|
||||
|
||||
### 数字
|
||||
@@ -220,9 +231,9 @@ String(23);
|
||||
(23).toString();
|
||||
// 从字符串返回数字
|
||||
Number("23");
|
||||
// 解码 URI。 结果:“我的 page.asp”
|
||||
// 解码 URI。 结果:“my page.asp”
|
||||
decodeURI(enc);
|
||||
// 编码 URI。 结果:“my%page.asp”
|
||||
// 编码 URI。 结果:“my%20page.asp”
|
||||
encodeURI(uri);
|
||||
// 解码 URI 组件
|
||||
decodeURIComponent(enc);
|
||||
@@ -238,11 +249,9 @@ parseFloat();
|
||||
parseInt();
|
||||
```
|
||||
|
||||
|
||||
JavaScript 条件
|
||||
----
|
||||
|
||||
|
||||
### 操作符
|
||||
<!--rehype:wrap-class=row-span-3-->
|
||||
|
||||
@@ -273,7 +282,7 @@ true && false; // false
|
||||
1 === '1' // false
|
||||
```
|
||||
|
||||
#### 逻辑运算符 !
|
||||
#### 逻辑运算符
|
||||
|
||||
```javascript
|
||||
let lateToWork = true;
|
||||
@@ -727,7 +736,6 @@ numbers.concat(newFirstNumber)
|
||||
|
||||
如果你想避免改变你的原始数组,你可以使用 concat。
|
||||
|
||||
|
||||
### 方法 .splice()
|
||||
|
||||
```javascript
|
||||
@@ -1182,6 +1190,100 @@ console.log(myCat.name);
|
||||
myCat.name = 'Yankee';
|
||||
```
|
||||
|
||||
JavaScript this 绑定
|
||||
----
|
||||
|
||||
### 隐式绑定
|
||||
|
||||
```js
|
||||
function foo() {
|
||||
console.log(this)
|
||||
}
|
||||
let obj1 = {
|
||||
name: "obj1",
|
||||
foo: foo
|
||||
}
|
||||
let obj2 = {
|
||||
name: "obj2",
|
||||
obj1: obj1
|
||||
}
|
||||
obj2.obj1.foo() // [Object obj1]
|
||||
```
|
||||
|
||||
#### 隐式丢失
|
||||
|
||||
```js
|
||||
let a = obj2.obj1.foo()
|
||||
a() // Window
|
||||
```
|
||||
|
||||
- 指定隐式绑定:必须在调用的对象内部有一个对函数的引用(比如一个属性)
|
||||
- 将以上调用赋值给一个变量,结果最终会是 Window
|
||||
- 在 a 被调用的位置没有进行过任何显示绑定,最终全局对象 window 会调用它(`Window.a`)
|
||||
<!--rehype:className=style-round-->
|
||||
|
||||
### 显示绑定
|
||||
|
||||
```js
|
||||
function getName(a1, a2) {
|
||||
console.log("此人" + this.name, "岁数" + (a1 + a2))
|
||||
}
|
||||
let person = {
|
||||
name: "zhangsan"
|
||||
}
|
||||
```
|
||||
|
||||
#### call
|
||||
|
||||
call 第一个参数接受 this 作用域,剩余参数传递给其调用的函数
|
||||
|
||||
```js
|
||||
getName.call(person, 18, 12)
|
||||
```
|
||||
|
||||
#### apply
|
||||
|
||||
apply 第一个参数与 call 相同,第二个参数是其调用函数的参数数组
|
||||
|
||||
```js
|
||||
getName.apply(person, [18, 12])
|
||||
```
|
||||
|
||||
#### bind
|
||||
|
||||
bind 函数会返回一个新函数
|
||||
|
||||
```js
|
||||
getName.bind(person,18,12)()
|
||||
//或者可以这样
|
||||
getName.bind(person)(18, 12)
|
||||
//或者这样
|
||||
getName.bind(person).bind(null, 18)(12)
|
||||
```
|
||||
|
||||
### 内置函数中的 this
|
||||
|
||||
数组中的一些方法,类似于 map、forEach 等,可以自己设置绑定 this
|
||||
|
||||
```js
|
||||
const obj = {
|
||||
name: "zhangsan"
|
||||
}
|
||||
const array = [1, 2, 3];
|
||||
array.map(function(value){
|
||||
console.log(this.name)
|
||||
}, obj)
|
||||
// zhangsan x3
|
||||
```
|
||||
|
||||
其中一些全局对象,如 setTimeout 等,它们和未显示绑定 this 的部分数组方法一样,都会指向全局对象(`Window`)
|
||||
|
||||
```js
|
||||
setTimeout(function(){
|
||||
console.log(this)
|
||||
}, 1000) // Window
|
||||
```
|
||||
|
||||
JavaScript Classes
|
||||
----
|
||||
|
||||
@@ -1295,7 +1397,6 @@ class Song {
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
JavaScript Modules
|
||||
----
|
||||
<!--rehype:body-class=cols-2-->
|
||||
|
@@ -546,7 +546,6 @@ test('async test', () => {
|
||||
|
||||
从你的测试中 _返回_ 一个 `Promise`
|
||||
|
||||
|
||||
## 模拟
|
||||
|
||||
### 模拟函数
|
||||
@@ -800,7 +799,6 @@ const fs = require('fs')
|
||||
const fs = require.requireActual('fs')
|
||||
```
|
||||
|
||||
|
||||
数据驱动测试(Jest 23+)
|
||||
----
|
||||
|
||||
@@ -886,7 +884,6 @@ test('第二个文本', () => {
|
||||
|
||||
`Node.js` 和 `Jest` 会缓存你需要的模块。 要测试具有副作用的模块,您需要在测试之间重置模块注册表
|
||||
|
||||
|
||||
另见
|
||||
----
|
||||
|
||||
|
236
docs/jq.md
Normal file
236
docs/jq.md
Normal file
@@ -0,0 +1,236 @@
|
||||
jq 备忘清单
|
||||
===
|
||||
|
||||
这个快速参考备忘单提供了使用 [jq](https://stedolan.github.io/jq/) 命令的各种方法。
|
||||
|
||||
入门
|
||||
----
|
||||
|
||||
### 介绍
|
||||
|
||||
jq 就像用于 JSON 数据的 [sed](./sed.md) - 您可以使用它来切片、过滤、映射和转换结构化数据
|
||||
|
||||
- [jq 官网](https://stedolan.github.io/jq/) _(stedolan.github.io)_
|
||||
- [jq 命令使用](https://jaywcjlove.github.io/linux-command/c/jq.html) _(jaywcjlove.github.io)_
|
||||
|
||||
安装
|
||||
|
||||
```bash
|
||||
$ sudo apt-get install jq # Debian& Ubuntu
|
||||
$ sudo dnf install jq # Fedora
|
||||
$ sudo zypper install jq # openSUSE
|
||||
$ sudo pacman -S jq # Arch
|
||||
$ brew install jq # macOS & Homebrew
|
||||
$ port install jq # macOS & MacPorts
|
||||
```
|
||||
|
||||
语法
|
||||
|
||||
```bash
|
||||
$ jq [options] <jq filter> [file...]
|
||||
$ jq [options] --args <jq filter> [strings...]
|
||||
$ jq [options] --jsonargs <jq filter> [JSON_TEXTS...]
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 选项
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
:- | -
|
||||
:- | -
|
||||
`-c` | 紧凑而不是漂亮的输出
|
||||
`-n` | 使用`null`作为单个输入值
|
||||
`-e` | 根据输出设置退出状态代码
|
||||
`-s` | 将所有输入读取(吸取)到数组中;应用过滤器
|
||||
`-r` | 输出原始字符串,而不是JSON文本
|
||||
`-R` | 读取原始字符串,而不是JSON文本
|
||||
`-C` | 为 JSON 着色
|
||||
`-M` | 单色(不要为JSON着色)
|
||||
`-S` | 在输出上排序对象的键
|
||||
`--tab` | 使用制表符进行缩进
|
||||
`--arg a v` | 将变量 `$a` 设置为 value `<v>`
|
||||
`--argjson a v` | 将变量 `$a` 设置为 JSON value `<v>`
|
||||
`--slurpfile a f` | 将变量 `$a` 设置为从`<f>`读取的JSON文本数组
|
||||
`--rawfile a f` | 将变量 `$a` 设置为包含`<f>`内容的字符串
|
||||
`--args` | 其余参数是字符串参数,而不是文件
|
||||
`--jsonargs` | 其余的参数是JSON参数,而不是文件
|
||||
`--` | 终止参数处理
|
||||
|
||||
学习示例
|
||||
---
|
||||
|
||||
### 获取一个键的值
|
||||
|
||||
```bash
|
||||
$ echo '{"foo": 42, "bar": "less interesting data"}' | jq '.foo'
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
输出结果
|
||||
|
||||
```bash
|
||||
42
|
||||
```
|
||||
|
||||
### 数组运算
|
||||
|
||||
```bash
|
||||
$ echo '[{"name":"JSON", "good":true}, {"name":"XML", "good":false}]' | jq '.[1]'
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
输出结果
|
||||
|
||||
```bash
|
||||
{
|
||||
"name": "XML",
|
||||
"good": false
|
||||
}
|
||||
```
|
||||
|
||||
### 构造一个数组/对象
|
||||
|
||||
```bash
|
||||
$ echo '{"user":"stedolan","titles":["JQ Primer", "More JQ"]}' | jq '{user, title: .titles[]}'
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
输出结果
|
||||
|
||||
```bash
|
||||
{
|
||||
"user": "stedolan",
|
||||
"title": "JQ Primer"
|
||||
}
|
||||
{
|
||||
"user": "stedolan",
|
||||
"title": "More JQ"
|
||||
}
|
||||
```
|
||||
|
||||
### 计算一个值的长度
|
||||
|
||||
```bash
|
||||
$ echo '[[1,2], "string", {"a":2}, null]' | jq '.[] | length'
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
输出结果
|
||||
|
||||
```bash
|
||||
2
|
||||
6
|
||||
1
|
||||
0
|
||||
```
|
||||
|
||||
### 取出数组中的键
|
||||
|
||||
```bash
|
||||
$ echo '{"abc": 1, "abcd": 2, "Foo": 3}' | jq 'keys'
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
输出结果
|
||||
|
||||
```bash
|
||||
[
|
||||
"Foo",
|
||||
"abc",
|
||||
"abcd"
|
||||
]
|
||||
```
|
||||
|
||||
### 使用多个过滤器
|
||||
|
||||
```bash
|
||||
$ echo '{ "foo": 42, "bar": "something else", "baz": true}' | jq '.foo, .bar'
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
输出结果
|
||||
|
||||
```bash
|
||||
42
|
||||
"something else"
|
||||
```
|
||||
|
||||
### 管道传递给下一个过滤器
|
||||
|
||||
```bash
|
||||
$ echo '[{"name":"JSON", "good":true}, {"name":"XML", "good":false}]' | jq '.[] | .name'
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
输出结果
|
||||
|
||||
```bash
|
||||
"JSON"
|
||||
"XML"
|
||||
```
|
||||
|
||||
### 条件语句判断
|
||||
|
||||
```bash
|
||||
$ echo '[1,5,3,0,7]' | jq 'map(select(. >= 2))'
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
输出结果
|
||||
|
||||
```bash
|
||||
[
|
||||
5,
|
||||
3,
|
||||
7
|
||||
]
|
||||
```
|
||||
|
||||
### 每个输入调用过滤器
|
||||
|
||||
```bash
|
||||
$ echo '[1,2,3]' | jq 'map(.+1)'
|
||||
```
|
||||
|
||||
输出结果
|
||||
|
||||
```bash
|
||||
[
|
||||
2,
|
||||
3,
|
||||
4
|
||||
]
|
||||
```
|
||||
|
||||
### 条件判断
|
||||
|
||||
```bash
|
||||
$ echo '2' | jq 'if . == 0 then "zero" elif . == 1 then "one" else "many" end'
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
输出结果
|
||||
|
||||
```bash
|
||||
"many"
|
||||
```
|
||||
|
||||
### 字符串插入值并进行运算
|
||||
|
||||
```bash
|
||||
$ echo '42' | jq '"The input was \(.), which is one less than \(.+1)"'
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
输出结果
|
||||
|
||||
```bash
|
||||
"The input was 42, which is one less than 43"
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
另见
|
||||
----
|
||||
|
||||
- [jq 官网](https://stedolan.github.io/jq/) _(stedolan.github.io)_
|
||||
- [jq 命令使用](https://jaywcjlove.github.io/linux-command/c/jq.html) _(jaywcjlove.github.io)_
|
@@ -75,8 +75,8 @@ JSON 备忘清单
|
||||
```json
|
||||
{ "foo": 'bar' }
|
||||
```
|
||||
Have to be delimited by double quotes
|
||||
|
||||
Have to be delimited by double quotes
|
||||
|
||||
### 数字
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
@@ -297,6 +297,7 @@ let myArray = [
|
||||
}
|
||||
];
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
| | |
|
||||
@@ -320,7 +321,7 @@ let myArray = [
|
||||
];
|
||||
```
|
||||
|
||||
-----
|
||||
----
|
||||
|
||||
| | |
|
||||
|--------------|-----------|
|
||||
@@ -328,7 +329,6 @@ let myArray = [
|
||||
| `myArray[5]` | true |
|
||||
| `myArray[6]` | undefined |
|
||||
|
||||
|
||||
另见
|
||||
----
|
||||
|
||||
|
681
docs/julia.md
Normal file
681
docs/julia.md
Normal file
@@ -0,0 +1,681 @@
|
||||
Julia 备忘清单
|
||||
===
|
||||
|
||||
本备忘清单旨在快速理解 [Julia](https://mysql.com) 一份简单而粗略的语言概览,供您参考。
|
||||
|
||||
入门
|
||||
---
|
||||
|
||||
### Julia 是什么?
|
||||
<!--rehype:wrap-class=row-span-3-->
|
||||
|
||||
- **`Julia`** 是一种为科学计算而生的,开源、多平台、高性能的高级编程语言
|
||||
- **`Julia`** 有一个基于 LLVM 的 JIT 编译器,这让使用者无需编写底层的代码也能拥有像 C 与 FORTRAN 那样的性能。因为代码在运行中编译,你可以在 shell 或 REPL 中运行代码,这也是一种推荐的工作流程
|
||||
- **`Julia`** 是动态类型的。并且提供了为并行计算和分布式运算设计的多重派发机制
|
||||
- **`Julia`** 自带包管理器
|
||||
- **`Julia`** 有许多内置的数学函数,包括特殊函数 (例如:Gamma 函数)。并且支持开箱即用的复数运算
|
||||
- **`Julia`** 允许你通过类似 Lisp 的宏来自动生成代码
|
||||
- **`Julia`** 诞生于 2012 年
|
||||
|
||||
### 赋值语句
|
||||
|
||||
```julia
|
||||
answer = 42
|
||||
x, y, z = 1, [1:10; ], "A string"
|
||||
x, y = y, x # 交换 x, y
|
||||
```
|
||||
|
||||
### 常量定义
|
||||
|
||||
```julia
|
||||
const DATE_OF_BIRTH = 2012
|
||||
```
|
||||
|
||||
### 行尾注释
|
||||
|
||||
```julia
|
||||
i = 1 # 这是一行注释
|
||||
# 多行注释
|
||||
#= 这是另一行注释 =#
|
||||
```
|
||||
|
||||
### 链式操作
|
||||
|
||||
```julia
|
||||
x = y = z = 1 # 从右向左
|
||||
0 < x < 3 # true
|
||||
5 < x != y < 5 # false
|
||||
```
|
||||
|
||||
### 函数定义
|
||||
|
||||
```julia
|
||||
function add_one(i)
|
||||
return i + 1
|
||||
end
|
||||
```
|
||||
|
||||
### 插入 LaTeX 符号
|
||||
|
||||
```julia
|
||||
\delta + [Tab] # δ
|
||||
```
|
||||
|
||||
### 运算符
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
基本算数运算 | `+`,`-`,`*`,`/`
|
||||
幂运算 | `2^3` => 8
|
||||
除法 | `3/12` => 0.25
|
||||
反向除法 | `7\3 == 3/7` => true
|
||||
取余 | `x % y` 或 `rem(x,y)`
|
||||
取反 | `!true` => false
|
||||
等于 | `a == b`
|
||||
不等于 | `a != b` 或 `a ≠ b`
|
||||
小于与大于 | `<` 与 `>`
|
||||
小于等于 | `<=` 或 `≤`
|
||||
大于等于 | `>=` 或 `≥`
|
||||
逐元素运算(点运算) | `[1, 2, 3] .+ [1, 2, 3] == [2, 4, 6]` => true<br /> `[1, 2, 3] .* [1, 2, 3] == [1, 4, 9]` => true
|
||||
检测非数值(NaN) | `isnan(NaN)` => true <br />而不是 `NaN == NaN` => false
|
||||
三元运算符 | `a == b ? "Equal" : "Not equal"`
|
||||
短路 AND 和 OR 表达式 | `a && b` 和 `a \|\| b`
|
||||
对象等价 | `a === b`
|
||||
|
||||
### shell/REPL 环境
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
上一次运算的结果 | `ans`
|
||||
中断命令执行 | <kbd>Ctrl</kbd> + <kbd>C</kbd>
|
||||
清屏 | <kbd>Ctrl</kbd> + <kbd>L</kbd>
|
||||
运行程序文件 | `include("filename.jl")`
|
||||
查找 func 相关的帮助 | `?func`
|
||||
查找 func 的所有定义 | `apropos("func")`
|
||||
命令行模式 | `;`
|
||||
包管理模式 | `]`
|
||||
帮助模式 | `?`
|
||||
查找特殊符号输入方式 | `?☆ # "☆" can be typed by \bigwhitestar<tab>`
|
||||
退出特殊模式,返回到 REPL | 在空行上按 <kbd>Backspace</kbd>
|
||||
退出 REPL | `exit()` 或 <kbd>Ctrl</kbd> + <kbd>D</kbd>
|
||||
|
||||
### 缺失值与空值
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
空值(Null) | `nothing`
|
||||
缺失数据 | `missing`
|
||||
浮点数的非数值 | `NaN`
|
||||
滤除缺失值 | `collect(skipmissing([1, 2, missing])) == [1,2]`
|
||||
替换缺失值 | `collect((df[:col], 1))`
|
||||
检查是否有缺失值 | `ismissing(x)` 而不是 `x == missing`
|
||||
|
||||
### 自我检查与反射
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
类型 | `typeof(name)`
|
||||
类型检查 | `isa(name, TypeName)`
|
||||
列出子类型 | `subtypes(TypeName)`
|
||||
列出超类型 | `supertype(TypeName)`
|
||||
函数方法 | `methods(func)`
|
||||
即时编译的字节码 | `code_llvm(expr)`
|
||||
汇编代码 | `code_native(expr)`
|
||||
|
||||
### 随机数
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
设置随机数种子 | `Random.seed!(seed)`
|
||||
产生随机数 | `rand()` # 均匀分布 [0,1)<br/>`randn()` # 正态分布 (-Inf, Inf)
|
||||
产生特定分布的随机数 | `using Distributions`<br/>`my_dist = Bernoulli(0.2)` 举例<br/>`rand(my_dist)`
|
||||
以概率 p 从 A 中进行伯努利抽样 | `randsubseq(A, p)`
|
||||
随机重排 A 中的元素 | `shuffle(A)`
|
||||
|
||||
许多随机数函数都需要 `using Random`
|
||||
|
||||
### 异常处理
|
||||
<!--rehype:wrap-class=row-span-3-->
|
||||
|
||||
```julia
|
||||
# 抛出异常 SomeExcep
|
||||
throw(SomeExcep())
|
||||
# 再次引发当前的异常
|
||||
rethrow()
|
||||
```
|
||||
|
||||
定义新异常 NewExcep
|
||||
|
||||
```julia
|
||||
struct NewExcep <: Exception
|
||||
v::String
|
||||
end
|
||||
Base.showerror(io::IO, e::NewExcep) = print(io, "A problem with $(e.v)!")
|
||||
|
||||
throw(NewExcep("x"))
|
||||
# 抛出带文本的异常
|
||||
error(msg)
|
||||
```
|
||||
|
||||
异常处理流程
|
||||
|
||||
```julia
|
||||
try
|
||||
# 进行一些可能会失败的操作
|
||||
catch ex
|
||||
if isa(ex, SomeExcep)
|
||||
# 处理异常 SomeExcep
|
||||
elseif isa(ex, AnotherExcep)
|
||||
# 处理另一个异常 AnotherExcep
|
||||
else
|
||||
# 处理其余的异常
|
||||
end
|
||||
finally
|
||||
# 永远执行这些语句
|
||||
end
|
||||
```
|
||||
|
||||
### 类型
|
||||
<!--rehype:wrap-class=row-span-4-->
|
||||
|
||||
```julia
|
||||
# 类型注释
|
||||
var::TypeName
|
||||
# 类型声明
|
||||
struct Programmer
|
||||
name::String
|
||||
birth_year::UInt16
|
||||
fave_language::AbstractString
|
||||
end
|
||||
# 可变类型声明
|
||||
将 struct 替换为 mutable struct
|
||||
# 类型别名
|
||||
const Nerd = Programmer
|
||||
# 类型构造器
|
||||
methods(TypeName)
|
||||
# 类型实例
|
||||
me = Programmer("Ian", 1984, "Julia")
|
||||
me = Nerd("Ian", 1984, "Julia")
|
||||
# 子类型声明
|
||||
abstract type Bird end
|
||||
struct Duck <: Bird
|
||||
pond::String
|
||||
end
|
||||
# 参数化类型
|
||||
struct Point{T <: Real}
|
||||
x::T
|
||||
y::T
|
||||
end
|
||||
|
||||
p = Point{Float64}(1,2)
|
||||
# 联合类型
|
||||
Union{Int, String}
|
||||
# 遍历类型层级
|
||||
supertype(TypeName) 和 subtypes(TypeName)
|
||||
# 默认的超类型
|
||||
Any
|
||||
# 所有字段
|
||||
fieldnames(TypeName)
|
||||
# 所有字段类型
|
||||
TypeName.types
|
||||
```
|
||||
|
||||
### 标准库
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
Random | `rand`, `randn`, `randsubseq`
|
||||
Statistics | `mean`, `std`, `cor`, `median`, `quantile`
|
||||
LinearAlgebra | `I`, `eigvals`, `eigvecs`, `det`, `cholesky`
|
||||
SparseArrays | `sparse`, `SparseVector`, `SparseMatrixCSC`
|
||||
Distributed | `@distributed`, `pmap`, `addprocs`
|
||||
Dates | `DateTime`, `Date`
|
||||
|
||||
### 表达式
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
使用引用 `:( ... )` 或块引用 `quote ... end` 可以创建一个表达式,就像 `parse(str)`,和 `Expr(:call, ...)`。
|
||||
|
||||
```julia
|
||||
x = 1
|
||||
line = "1 + $x" # 一些代码
|
||||
expr = Meta.parse(line) # 生成一个 Expr 对象
|
||||
typeof(expr) == Expr # true
|
||||
dump(expr) # 打印生成抽象语法(AST)
|
||||
eval(expr) == 2 # 对 Expr 对象求值: true
|
||||
```
|
||||
|
||||
Julia 具有同像性:程序被表示为语言本身的数据结构。 实际上 `Julia` 语言里的任何东西都是一个表达式 `Expr`。符号(`Symbols`)即驻留字符串 ,以冒号 `:` 为前缀。相对于其他类型来说,符号效率更高。它也经常用作标识符、字典的键或者数据表里的列名。符号不能进行拼接。
|
||||
|
||||
### 输入/输出
|
||||
<!--rehype:wrap-class=row-span-3-->
|
||||
|
||||
读取流
|
||||
|
||||
```julia
|
||||
stream = stdin
|
||||
for line in eachline(stream)
|
||||
# 做点啥
|
||||
end
|
||||
```
|
||||
|
||||
读取文件
|
||||
|
||||
```julia
|
||||
open(filename) do file
|
||||
for line in eachline(file)
|
||||
# 做点啥
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
读取/写入 CSV 文件
|
||||
|
||||
```julia
|
||||
# 读取 CSV 文件
|
||||
using CSV
|
||||
data = CSV.File(filename)
|
||||
# 写入 CSV 文件
|
||||
[label](koajs.md)CSV.write(filename, data)
|
||||
```
|
||||
|
||||
读取/保存 Julia 对象
|
||||
|
||||
```julia
|
||||
using JLD
|
||||
# 保存 Julia 对象
|
||||
save(filename, "object_key", object, ...)
|
||||
# 读取 Julia 对象
|
||||
d = load(filename) # 返回对象的字典
|
||||
```
|
||||
|
||||
读取/保存 HDF5
|
||||
|
||||
```julia
|
||||
using HDF5
|
||||
# 保存 HDF5
|
||||
h5write(filename, "key", object)
|
||||
# 读取 HDF5
|
||||
h5read(filename, "key")
|
||||
```
|
||||
|
||||
### 宏
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
宏允许你在程序中自动生成代码(如:表达式)
|
||||
|
||||
```julia
|
||||
# 定义
|
||||
macro macroname(expr)
|
||||
# 做点啥
|
||||
end
|
||||
```
|
||||
|
||||
使用
|
||||
|
||||
```julia
|
||||
macroname(ex1, ex2, ...) 或 @macroname ex1, ex2, ...
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
内置的宏
|
||||
|
||||
```julia
|
||||
@assert # assert (单元测试)
|
||||
@which # 查看对特定参数使用的方法/查找函数所在的模块
|
||||
@time # 运行时间与内存分配统计
|
||||
@elapsed # 返回执行用时
|
||||
@allocated # 查看内存分配
|
||||
@async # 异步任务
|
||||
|
||||
using Test
|
||||
@test # 精确相等
|
||||
@test x ≈ y # 近似相等 isapprox(x, y)
|
||||
|
||||
using Profile
|
||||
@profile # 优化
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
创建 卫生宏 (hygienic macros)的规则:
|
||||
|
||||
- 在宏的内部只通过 `local` 声明本地变量
|
||||
- 在宏的内部不使用 `eval`
|
||||
- 转义插值表达式以避免宏变大:`$(esc(expr))`
|
||||
|
||||
### 并行计算
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
并行计算相关的工具可以在标准库 `Distributed` 里找到
|
||||
|
||||
```julia
|
||||
# 启动带 N 各 worker 的 REPL
|
||||
julia -p N
|
||||
# 可用的 worker 数量
|
||||
nprocs()
|
||||
# 添加 N 个 worker
|
||||
addprocs(N)
|
||||
# 查看所有 worker 的 pid
|
||||
for pid in workers()
|
||||
println(pid)
|
||||
end
|
||||
# 获得正在执行的 worker 的 id
|
||||
myid()
|
||||
# 移除 worker
|
||||
rmprocs(pid)
|
||||
# 在特定 pid 的 worker 上运行 f(args)
|
||||
r = remotecall(f, pid, args...)
|
||||
# 或:
|
||||
r = @spawnat pid f(args)
|
||||
...
|
||||
fetch(r)
|
||||
# 在特定 pid 的 worker 上运行 f(args) (更高效)
|
||||
remotecall_fetch(f, pid, args...)
|
||||
# 在任意 worker 上运行 f(args)
|
||||
r = @spawn f(args) ... fetch(r)
|
||||
# 在所有 worker 上运行 f(args)
|
||||
r = [@spawnat w f(args) for w in workers()] ... fetch(r)
|
||||
# 让表达式 expr 在所有 worker 上执行
|
||||
@everywhere expr
|
||||
# 并行化带规约函数 red 的循环
|
||||
sum = @distributed (red) for i in 1:10^6
|
||||
# 进行并行任务
|
||||
end
|
||||
# 将 f 用用到集合 coll 中的所有元素上
|
||||
pmap(f, coll)
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 数组
|
||||
<!--rehype:wrap-class=col-span-2 row-span-2-->
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
声明数组 | `arr = Float64[]`
|
||||
预分配内存 | `sizehint!(arr, 10^4)`
|
||||
访问与赋值 | `arr = Any[1,2]`<br/>`arr[1] = "Some text"`
|
||||
从 m 到 n 的子数组 | `arr[m:n]`
|
||||
n 个 `0.0` 填充的数组 | `zeros(n)`
|
||||
n 个 `1.0` 填充的数组 | `ones(n)`
|
||||
n 个随机 Int8 填充的数组 | `rand(Int8, n)`
|
||||
用值 val 填充数组 | `fill!(arr, val)`
|
||||
弹出最后一个元素 | `pop!(arr)`
|
||||
弹出第一个元素 | `popfirst!(a)`
|
||||
n 个 `#undef` 填充的数组 | `Vector{Type}(undef,n)`
|
||||
n 个从 `start` 到 `stop` 的等间距数 | `range(start,stop=stop,length=n)`
|
||||
将值 `val` 作为最后一个元素压入数组 | `push!(arr, val)`
|
||||
将值 `val` 作为第一个元素压入数组 | `pushfirst!(arr, val)`
|
||||
删除指定索引值的元素 | `deleteat!(arr, idx)`
|
||||
数组排序 | `sort!(arr)`
|
||||
将 `b` 连接到 `a` 后 | `append!(a,b)`
|
||||
转化为字符串,并以 delim 分隔 | `join(arr, delim)`
|
||||
<!--rehype:className=left-align-->
|
||||
|
||||
---
|
||||
|
||||
```julia
|
||||
# 数组比较
|
||||
a = [1:10;]
|
||||
b = a # b 指向 a
|
||||
a[1] = -99
|
||||
a == b # true
|
||||
# 复制元素(而不是地址)/深拷贝
|
||||
b = copy(a)
|
||||
b = deepcopy(a)
|
||||
# 检查值 val 是否在数组 arr 中
|
||||
in(val, arr) # 或
|
||||
val in arr
|
||||
# 改变维数
|
||||
reshape(1:6, 3, 2)' == [1 2 3; 4 5 6]
|
||||
```
|
||||
|
||||
### 线性代数
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
单位矩阵 | `I`
|
||||
定义矩阵 | `M = [1 0; 0 1]`
|
||||
矩阵维数 | `size(M)`
|
||||
选出第 i 行 | `M[i, :]`
|
||||
选出第 j 列 | `M[:, j]`
|
||||
水平拼接 | `M = [a b] 或 M = hcat(a, b)`
|
||||
竖直拼接 | `M = [a ; b]` 或 `M = vcat(a, b)`
|
||||
矩阵转置 | `transpose(M)`
|
||||
共轭转置 | `M'` 或 `adjoint(M)`
|
||||
迹(trace) | `tr(M)`
|
||||
行列式 | `det(M)`
|
||||
秩(rank) | `rank(M)`
|
||||
特征值 | `eigvals(M)`
|
||||
特征向量 | `eigvecs(M)`
|
||||
矩阵求逆 | `inv(M)`
|
||||
解矩阵方程 `M*x == v` | `M\v` 比 `inv(M)*v` 更好
|
||||
求 Moore-Penrose 伪逆 | `pinv(M)`
|
||||
<!--rehype:className=left-align-->
|
||||
|
||||
控制流与循环
|
||||
---
|
||||
|
||||
### 条件语句
|
||||
|
||||
```julia
|
||||
if x < y
|
||||
println("x is less than y")
|
||||
elseif x > y
|
||||
println("x is greater than y")
|
||||
else
|
||||
println("x is equal to y")
|
||||
end
|
||||
```
|
||||
|
||||
### for 循环
|
||||
|
||||
```julia
|
||||
for i in 1:10
|
||||
println(i)
|
||||
end
|
||||
```
|
||||
|
||||
### 嵌套循环
|
||||
|
||||
```julia
|
||||
for i in 1:10, j = 1:5
|
||||
println(i*j)
|
||||
end
|
||||
```
|
||||
|
||||
### 枚举
|
||||
|
||||
```julia
|
||||
for (idx, val) in enumerate(arr)
|
||||
println("the $idx-th element is $val")
|
||||
end
|
||||
```
|
||||
|
||||
### while 循环
|
||||
|
||||
```julia
|
||||
while bool_expr
|
||||
# 做点啥
|
||||
end
|
||||
```
|
||||
|
||||
### 退出循环
|
||||
|
||||
```julia {4}
|
||||
julia> i = 0
|
||||
julia> while true
|
||||
global i += 1
|
||||
i > 5 && break
|
||||
println(i)
|
||||
end
|
||||
```
|
||||
|
||||
### 退出本次循环
|
||||
|
||||
```julia {2}
|
||||
for i = 1:6
|
||||
iseven(i) && continue
|
||||
println(i)
|
||||
end
|
||||
```
|
||||
|
||||
数字相关
|
||||
---
|
||||
|
||||
### 整数类型
|
||||
|
||||
`IntN` 和 `UIntN`, 且 `N ∈ {8, 16, 32, 64, 128}`, `BigInt`
|
||||
|
||||
### 浮点类型
|
||||
|
||||
`FloatN` 且 `N ∈ {16, 32, 64}`
|
||||
`BigFloat`
|
||||
|
||||
### 类型的最大和最小值
|
||||
|
||||
```julia
|
||||
typemin(Int8)
|
||||
typemax(Int64)
|
||||
```
|
||||
|
||||
### 复数类型
|
||||
|
||||
```julia
|
||||
Complex{T<:Real}
|
||||
```
|
||||
|
||||
### 虚数单位
|
||||
|
||||
```julia
|
||||
im
|
||||
```
|
||||
|
||||
### 机器精度
|
||||
|
||||
```julia
|
||||
eps() # 等价于 eps(Float64)
|
||||
```
|
||||
|
||||
### 圆整
|
||||
|
||||
```julia
|
||||
round() # 浮点数圆整
|
||||
round(Int, x) # 整数圆整
|
||||
```
|
||||
|
||||
### 类型转换
|
||||
|
||||
```julia
|
||||
# 尝试进行转换/可能会报错
|
||||
convert(TypeName, val)
|
||||
# 调用类型构造器转换
|
||||
TypeName(val)
|
||||
```
|
||||
|
||||
### 全局常量
|
||||
|
||||
```julia
|
||||
pi # 3.1415...
|
||||
π # 3.1415...
|
||||
im # real(im * im) == -1
|
||||
```
|
||||
|
||||
### 更多常量
|
||||
|
||||
```julia
|
||||
using Base.MathConstants
|
||||
```
|
||||
|
||||
模块
|
||||
---
|
||||
|
||||
### 定义
|
||||
|
||||
```julia
|
||||
module PackageName
|
||||
# 添加模块定义
|
||||
# 使用 export 让定义对外可见
|
||||
end
|
||||
```
|
||||
|
||||
### 包含文件 filename.jl
|
||||
|
||||
```julia
|
||||
include("filename.jl")
|
||||
```
|
||||
|
||||
### 加载
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```julia
|
||||
using ModuleName # 导出所有名称
|
||||
# 仅导出 x, y
|
||||
using ModuleName: x, y
|
||||
# 仅导出 x, y
|
||||
using ModuleName.x, ModuleName.y:
|
||||
# 仅导出 ModuleName
|
||||
import ModuleName
|
||||
# 仅导出 x, y
|
||||
import ModuleName: x, y
|
||||
# 仅导出 x, y
|
||||
import ModuleName.x, ModuleName.y
|
||||
```
|
||||
|
||||
`using` 和 `import` 只有一点区别:使用 `using` 时,你需要写 `function Foo.bar(..` 来给 `Foo` 模块的函数 `bar` 增添一个新方法; 而使用 `import Foo.bar` 时,只需写 `function bar(...` 就能达到同样的效果
|
||||
|
||||
### 导出
|
||||
|
||||
```julia
|
||||
# 得到模块导出名称的数组
|
||||
names(ModuleName)
|
||||
|
||||
# 包含未导出的、弃用的
|
||||
# 和编译器产生的名称
|
||||
names(ModuleName, all::Bool)
|
||||
# 也显示从其他模块显式导入的名称
|
||||
names(ModuleName, all::Bool, imported::Bool)
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
包管理
|
||||
---
|
||||
|
||||
### 介绍
|
||||
|
||||
一个程序包必须先[注册](https://github.com/JuliaRegistries/General),然后才能在包管理器中看到它。在 Julia 1.0 中,有两种使用包管理器的方法:
|
||||
|
||||
- 一是通过 `using Pkg` 导入 `Pkg` 模块,然后用它的函数管理其他包;
|
||||
- 或者在 REPL 中输入 `]`,然后按回车。进入特殊的交互式包管理模式。 (要从包管理模式返回 REPL,只需要在空行上按退格键 `BACKSPACE` 就行了)
|
||||
|
||||
注意新的工具总是先添加到交互式模式中,然后才会加入 `Pkg` 模块
|
||||
|
||||
### 在 Julia 会话中使用 Pkg 管理包
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
列出已安装的包 | `Pkg.status()`
|
||||
更新所有包 | `Pkg.update()`
|
||||
安装包 | `Pkg.add("PackageName")`
|
||||
重新构建包 | `Pkg.build("PackageName")`
|
||||
使用包 | `using PackageName`
|
||||
删除包 | `Pkg.rm("PackageName")`
|
||||
<!--rehype:className=left-align-->
|
||||
|
||||
### 交互式包管理模式
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
添加包 | `add PackageName`
|
||||
删除包 | `rm PackageName`
|
||||
更新包 | `update PackageName`
|
||||
使用开发版本 | `dev PackageName` 或 `dev GitRepoUrl`
|
||||
返回普通发行版 | `free PackageName`
|
||||
<!--rehype:className=left-align-->
|
||||
|
||||
另见
|
||||
---
|
||||
|
||||
- [快速入门一份简单而粗略的语言概览](https://cheatsheet.juliadocs.org/zh-cn/)
|
@@ -3,7 +3,6 @@ Koajs 备忘清单
|
||||
|
||||
基于 Node.js 平台的下一代 web 开发框架,包含 [Koa](https://koajs.com/) 的 API 参考列表和一些示例。
|
||||
|
||||
|
||||
入门
|
||||
---
|
||||
|
||||
@@ -13,6 +12,7 @@ Koajs 备忘清单
|
||||
[Koa](https://koajs.com/) 需要 [node v7.6.0](https://nodejs.org) 或更高版本来支持ES2015、异步方法,你可以安装自己支持的 `node` 版本
|
||||
|
||||
- 安装依赖
|
||||
|
||||
```bash
|
||||
$ mkdir myapp # 创建目录
|
||||
$ cd myapp # 进入目录
|
||||
@@ -20,7 +20,9 @@ Koajs 备忘清单
|
||||
$ npm init -y # 初始化一个配置
|
||||
$ npm install koa # 安装依赖
|
||||
```
|
||||
|
||||
- 入口文件 `index.js` 添加代码:
|
||||
|
||||
```js
|
||||
const Koa = require('koa');
|
||||
const app = new Koa();
|
||||
@@ -31,7 +33,9 @@ Koajs 备忘清单
|
||||
|
||||
app.listen(3000);
|
||||
```
|
||||
|
||||
- 使用以下命令运行应用程序
|
||||
|
||||
```bash
|
||||
$ node index.js
|
||||
```
|
||||
|
718
docs/kotlin.md
Normal file
718
docs/kotlin.md
Normal file
@@ -0,0 +1,718 @@
|
||||
Kotlin 备忘清单
|
||||
===
|
||||
|
||||
Kotlin 备忘清单是 [Kotlin](https://kotlinlang.org) 编程语言的单页参考表
|
||||
|
||||
Kotlin 简介
|
||||
----
|
||||
|
||||
### main() 函数
|
||||
|
||||
```kotlin
|
||||
fun main() {
|
||||
// Code goes here
|
||||
}
|
||||
```
|
||||
|
||||
main() 函数是每个 Kotlin 程序的起点,在执行之前必须包含在代码中
|
||||
|
||||
### 打印声明
|
||||
|
||||
```kotlin
|
||||
println("Greetings, earthling!")
|
||||
print("Take me to ")
|
||||
print("your leader.")
|
||||
|
||||
/*
|
||||
打印:
|
||||
Greetings, earthling!
|
||||
Take me to your leader.
|
||||
*/
|
||||
```
|
||||
|
||||
### 注释
|
||||
|
||||
```kotlin
|
||||
// 这是单行注释
|
||||
|
||||
/*
|
||||
这个
|
||||
注释
|
||||
用于
|
||||
多
|
||||
行
|
||||
*/
|
||||
```
|
||||
|
||||
### 执行顺序
|
||||
|
||||
```kotlin
|
||||
fun main() {
|
||||
println("I will be printed first.")
|
||||
println("I will be printed second.")
|
||||
println("I will be printed third.")
|
||||
}
|
||||
```
|
||||
|
||||
数据类型和变量
|
||||
---
|
||||
|
||||
### 可变变量
|
||||
|
||||
```kotlin
|
||||
var age = 25
|
||||
age = 26
|
||||
```
|
||||
|
||||
### 不可变变量
|
||||
|
||||
```kotlin
|
||||
val goldenRatio = 1.618
|
||||
```
|
||||
|
||||
### 类型推断
|
||||
|
||||
```kotlin
|
||||
// 以下变量在双引号内分配了一个文本值
|
||||
// 因此推断的类型是 String
|
||||
|
||||
var color = "Purple"
|
||||
```
|
||||
|
||||
### 字符串连接
|
||||
|
||||
```kotlin
|
||||
var streetAddress = "123 Main St."
|
||||
var cityState = "Brooklyn, NY"
|
||||
|
||||
println(streetAddress + " " + cityState)
|
||||
// 打印: 123 Main St. Brooklyn, NY
|
||||
```
|
||||
|
||||
### 字符串模板
|
||||
|
||||
```kotlin
|
||||
var address = "123 Main St."
|
||||
println("The address is $address")
|
||||
// 打印: The address is 123 Main St.
|
||||
```
|
||||
|
||||
### 内置属性和函数
|
||||
|
||||
```kotlin
|
||||
var monument = "the Statue of Liberty"
|
||||
|
||||
println(monument.capitalize())
|
||||
// 打印: The Statue of Liberty
|
||||
println(monument.length)
|
||||
// 打印: 21
|
||||
```
|
||||
|
||||
### 字符转义序列
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```kotlin
|
||||
print("\"Excellent!\" I cried. \"Elementary,\" said he.")
|
||||
|
||||
// 打印: "Excellent!" I cried. "Elementary," said he.
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
- `\n` 插入新行
|
||||
- `\t` 插入标签
|
||||
- `\r` 插入回车
|
||||
- `\'` 插入单引号
|
||||
- `\"` 插入双引号
|
||||
- `\\` 插入反斜杠
|
||||
- `\$` 插入美元符号
|
||||
|
||||
### 算术运算符
|
||||
|
||||
```kotlin
|
||||
5 + 7 // 12
|
||||
9 - 2 // 7
|
||||
8 * 4 // 32
|
||||
25 / 5 // 5
|
||||
31 % 2 // 1
|
||||
```
|
||||
|
||||
`+` 加法、`-` 减法、`*` 乘法、`/` 除法和 `%` 模数
|
||||
|
||||
### 操作顺序
|
||||
|
||||
```kotlin
|
||||
5 + 8 * 2 / 4 - 3 // 6
|
||||
3 + (4 + 4) / 2 // 7
|
||||
4 * 2 + 1 * 7 // 15
|
||||
3 + 18 / 2 * 1 // 12
|
||||
6 - 3 % 2 + 2 // 7
|
||||
```
|
||||
|
||||
### 增强赋值运算符
|
||||
|
||||
```kotlin
|
||||
var batteryPercentage = 80
|
||||
|
||||
// 长语法
|
||||
batteryPercentage = batteryPercantage + 10
|
||||
|
||||
// 带有增广赋值运算符的短句法
|
||||
batteryPercentage += 10
|
||||
```
|
||||
|
||||
### 递增和递减运算符
|
||||
|
||||
```kotlin
|
||||
var year = 2019
|
||||
year++ // 2020
|
||||
year-- // 2019
|
||||
```
|
||||
|
||||
### 数学库
|
||||
|
||||
```kotlin
|
||||
Math.pow(2.0, 3.0) // 8.0
|
||||
Math.min(6, 9) // 6
|
||||
Math.max(10, 12) // 12
|
||||
Math.round(13.7) // 14
|
||||
```
|
||||
|
||||
条件表达式
|
||||
----
|
||||
|
||||
### if 表达式
|
||||
|
||||
```kotlin
|
||||
var morning = true
|
||||
|
||||
if (morning) {
|
||||
println("Rise and shine!")
|
||||
}
|
||||
// 打印: Rise and shine!
|
||||
```
|
||||
|
||||
### else 表达式
|
||||
|
||||
```kotlin
|
||||
var rained = false
|
||||
|
||||
if (rained) {
|
||||
println("今天不需要给植物浇水。")
|
||||
} else {
|
||||
println("植物需要浇水!")
|
||||
}
|
||||
// 打印: 植物需要浇水!
|
||||
```
|
||||
|
||||
### Else-If 表达式
|
||||
|
||||
```kotlin
|
||||
var age = 65
|
||||
|
||||
if (age < 18 ) {
|
||||
println("您被视为未成年人")
|
||||
} else if (age < 60) {
|
||||
println("您被视为成年人")
|
||||
} else {
|
||||
println("你被认为是高级")
|
||||
}
|
||||
|
||||
// 打印: 你被认为是高级
|
||||
```
|
||||
|
||||
### 比较运算符
|
||||
|
||||
```kotlin
|
||||
var myAge = 19
|
||||
var sisterAge = 11
|
||||
var cousinAge = 11
|
||||
|
||||
myAge > sisterAge // true
|
||||
myAge < cousinAge // false
|
||||
myAge >= cousinAge // true
|
||||
myAge <= sisterAge // false
|
||||
```
|
||||
|
||||
### 逻辑运算符
|
||||
|
||||
```kotlin
|
||||
var humid = true
|
||||
var raining = true
|
||||
var jacket = false
|
||||
|
||||
println(!humid)
|
||||
// 打印: false
|
||||
println(jacket && raining)
|
||||
// 打印: true
|
||||
println(humid || raining)
|
||||
// 打印: true
|
||||
```
|
||||
|
||||
### AND 运算符: &&
|
||||
|
||||
```kotlin
|
||||
var humid = true
|
||||
var raining = true
|
||||
var shorts = false
|
||||
var sunny = false
|
||||
|
||||
// true AND true
|
||||
println(humid && raining) // true
|
||||
// true AND false
|
||||
println(humid && shorts) // false
|
||||
// false AND true
|
||||
println(sunny && raining) // false
|
||||
// false AND false
|
||||
println(shorts && sunny) // false
|
||||
```
|
||||
|
||||
### 或运算符:||
|
||||
|
||||
```kotlin
|
||||
var late = true
|
||||
var skipBreakfast = true
|
||||
var underslept = false
|
||||
var checkEmails = false
|
||||
|
||||
// true OR true
|
||||
println(skipBreakfast || late) // true
|
||||
// true OR false
|
||||
println(late || checkEmails) // true
|
||||
// false OR true
|
||||
println(underslept || late) // true
|
||||
// false OR false
|
||||
println(checkEmails || underslept) // false
|
||||
```
|
||||
|
||||
### NOT 运算符
|
||||
|
||||
```kotlin
|
||||
var hungry = true
|
||||
var full = false
|
||||
|
||||
println(!hungry) // false
|
||||
println(!full) // true
|
||||
```
|
||||
|
||||
### 评估顺序
|
||||
|
||||
```kotlin
|
||||
!true && (false || true) // false
|
||||
/*
|
||||
(false || true) 被评估首先返回 true。
|
||||
然后,评估 !true && true 并返回最终结果 false
|
||||
*/
|
||||
|
||||
!false && true || false // true
|
||||
/*
|
||||
!false 被评估首先返回 true。
|
||||
然后评估 true && true,返回 true。
|
||||
那么,真|| 评估 false 最终返回 true
|
||||
*/
|
||||
```
|
||||
|
||||
### 嵌套条件
|
||||
|
||||
```kotlin
|
||||
var studied = true
|
||||
var wellRested = true
|
||||
|
||||
if (wellRested) {
|
||||
println("祝你今天好运!")
|
||||
if (studied) {
|
||||
println("你应该为考试做好准备!")
|
||||
} else {
|
||||
println("考试前花几个小时学习!")
|
||||
}
|
||||
}
|
||||
|
||||
// 打印: 祝你今天好运!
|
||||
// 打印: 你应该为考试做好准备!
|
||||
```
|
||||
|
||||
### 当表达式
|
||||
|
||||
```kotlin
|
||||
var grade = "A"
|
||||
|
||||
when(grade) {
|
||||
"A" -> println("很棒的工作!")
|
||||
"B" -> println("做得太好了!")
|
||||
"C" -> println("你通过了!")
|
||||
else -> println("关!下次一定要多准备!")
|
||||
}
|
||||
// 打印: 很棒的工作!
|
||||
```
|
||||
|
||||
### 范围运算符
|
||||
|
||||
```kotlin
|
||||
var height = 46 // inches
|
||||
|
||||
if (height in 1..53) {
|
||||
println("抱歉,您必须至少 54 英寸才能乘坐过山车")
|
||||
}
|
||||
// Prints: 抱歉,您必须至少 54 英寸才能乘坐过山车
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 等式运算符
|
||||
|
||||
```kotlin
|
||||
var myAge = 22
|
||||
var sisterAge = 21
|
||||
|
||||
myAge == sisterAge // false
|
||||
myAge !== sisterAge // true
|
||||
```
|
||||
|
||||
Collections
|
||||
---
|
||||
|
||||
### 不可变列表
|
||||
|
||||
```kotlin
|
||||
var programmingLanguages = listOf("C#", "Java", "Kotlin", "Ruby")
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 可变列表
|
||||
|
||||
```kotlin
|
||||
var fruits = mutableListOf("Orange", "Apple", "Banana", "Mango")
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 访问列表元素
|
||||
|
||||
```kotlin
|
||||
var cars = listOf("BMW", "Ferrari", "Volvo", "Tesla")
|
||||
|
||||
println(cars[2]) // Prints: Volvo
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 大小属性
|
||||
|
||||
```kotlin
|
||||
var worldContinents = listOf("Asia", "Africa", "North America", "South America", "Antarctica", "Europe", "Australia")
|
||||
|
||||
println(worldContinents.size) // Prints: 7
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 列表操作
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```kotlin
|
||||
var seas = listOf("Black Sea", "Caribbean Sea", "North Sea")
|
||||
println(seas.contains("North Sea")) // Prints: true
|
||||
|
||||
// contains() 函数对任何列表执行读取操作并确定元素是否存在
|
||||
seas.add("Baltic Sea") // 错误:无法对不可变列表执行写操作
|
||||
// add() 函数只能在可变列表上调用,因此上面的代码会引发错误
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 不可变集
|
||||
|
||||
```kotlin
|
||||
var primaryColors = setOf("Red", "Blue", "Yellow")
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 可变集
|
||||
|
||||
```kotlin
|
||||
var womenInTech = mutableSetOf("Ada Lovelace", "Grace Hopper", "Radia Perlman", "Sister Mary Kenneth Keller")
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 访问集合元素
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```kotlin
|
||||
var companies = setOf("Facebook", "Apple", "Netflix", "Google")
|
||||
|
||||
println(companies.elementAt(3))
|
||||
// Prints: Google
|
||||
println(companies.elementAt(4))
|
||||
// Returns and Error
|
||||
println(companies.elementAtOrNull(4))
|
||||
// Prints: null
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 不可变映射
|
||||
|
||||
```kotlin
|
||||
var averageTemp = mapOf("winter" to 35, "spring" to 60, "summer" to 85, "fall" to 55)
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 可变映射
|
||||
|
||||
```kotlin
|
||||
var europeanDomains = mutableMapOf("Germany" to "de", "Slovakia" to "sk", "Hungary" to "hu", "Norway" to "no")
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 检索映射键和值
|
||||
|
||||
```kotlin
|
||||
var oscarWinners = mutableMapOf("Parasite" to "Bong Joon-ho", "Green Book" to "Jim Burke", "The Shape Of Water" to "Guillermo del Toro")
|
||||
|
||||
println(oscarWinners.keys)
|
||||
// Prints: [Parasite, Green Book, The Shape Of Water]
|
||||
|
||||
println(oscarWinners.values)
|
||||
// Prints: [Bong Joon-ho, Jim Burke, Guillermo del Toro]
|
||||
|
||||
println(oscarWinners["Parasite"])
|
||||
// Prints: Bong Joon-ho
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 添加和删除地图条目
|
||||
|
||||
```kotlin
|
||||
var worldCapitals = mutableMapOf("United States" to "Washington D.C.", "Germany" to "Berlin", "Mexico" to "Mexico City", "France" to "Paris")
|
||||
|
||||
worldCapitals.put("Brazil", "Brasilia")
|
||||
println(worldCapitals)
|
||||
// Prints: {United States=Washington D.C., Germany=Berlin, Mexico=Mexico City, France=Paris, Brazil=Brasilia}
|
||||
|
||||
worldCapitals.remove("Germany")
|
||||
println(worldCapitals)
|
||||
// Prints: {United States=Washington D.C., Mexico=Mexico City, France=Paris, Brazil=Brasilia}
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
函数
|
||||
---
|
||||
|
||||
### 函数
|
||||
|
||||
```kotlin
|
||||
fun greet() {
|
||||
println("Hey there!")
|
||||
}
|
||||
|
||||
fun main() {
|
||||
// Function call
|
||||
greet() // Prints: Hey there!
|
||||
}
|
||||
```
|
||||
|
||||
### 函数参数
|
||||
|
||||
```kotlin
|
||||
fun birthday(name: String, age: Int) {
|
||||
println("Happy birthday $name! You turn $age today!")
|
||||
}
|
||||
|
||||
fun main() {
|
||||
birthday("Oscar", 26)
|
||||
// Prints: Happy birthday Oscar! You turn 25 today!
|
||||
birthday("Amarah", 30)
|
||||
// Prints: Happy birthday Amarah! You turn 30 today!
|
||||
}
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 默认参数
|
||||
|
||||
```kotlin
|
||||
fun favoriteLanguage(name, language = "Kotlin") {
|
||||
println("Hello, $name. Your favorite programming language is $language")
|
||||
}
|
||||
|
||||
fun main() {
|
||||
favoriteLanguage("Manon")
|
||||
// Prints: Hello, Manon. Your favorite programming language is Kotlin
|
||||
|
||||
favoriteLanguage("Lee", "Java")
|
||||
// Prints: Hello, Lee. Your favorite programming language is Java
|
||||
}
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 命名参数
|
||||
|
||||
```kotlin
|
||||
fun findMyAge(currentYear: Int, birthYear: Int) {
|
||||
var myAge = currentYear - birthYear
|
||||
println("I am $myAge years old.")
|
||||
}
|
||||
|
||||
fun main() {
|
||||
findMyAge(currentYear = 2020, birthYear = 1995)
|
||||
// Prints: I am 25 years old.
|
||||
findMyAge(birthYear = 1920, currentYear = 2020)
|
||||
// Prints: I am 100 years old.
|
||||
}
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 返回声明
|
||||
|
||||
```kotlin
|
||||
// Return type is declared outside the parentheses
|
||||
fun getArea(length: Int, width: Int): Int {
|
||||
var area = length * width
|
||||
|
||||
// return statement
|
||||
return area
|
||||
}
|
||||
|
||||
fun main() {
|
||||
var myArea = getArea(10, 8)
|
||||
println("The area is $myArea.")
|
||||
// Prints: The area is 80.
|
||||
}
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 单表达式函数
|
||||
|
||||
```kotlin
|
||||
fun fullName(firstName: String, lastName: String) = "$firstName $lastName"
|
||||
|
||||
fun main() {
|
||||
println(fullName("Ariana", "Ortega"))
|
||||
// Prints: Ariana Ortega
|
||||
println(fullName("Kai", "Gittens"))
|
||||
// Prints: Kai Gittens
|
||||
}
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 函数字面量
|
||||
|
||||
```kotlin
|
||||
fun main() {
|
||||
// Anonymous Function:
|
||||
var getProduct = fun(num1: Int, num2: Int): Int {
|
||||
return num1 * num2
|
||||
}
|
||||
println(getProduct(8, 3))
|
||||
// Prints: 24
|
||||
|
||||
// Lambda Expression
|
||||
var getDifference = { num1: Int, num2: Int -> num1 - num2 }
|
||||
println(getDifference(10, 3))
|
||||
// Prints: 7
|
||||
}
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
类
|
||||
---
|
||||
|
||||
### 类示例
|
||||
|
||||
```kotlin
|
||||
// 具有包含默认值的属性的类
|
||||
class Student {
|
||||
var name = "Lucia"
|
||||
var semester = "Fall"
|
||||
var gpa = 3.95
|
||||
}
|
||||
|
||||
// 没有类体的简写语法
|
||||
class Student
|
||||
```
|
||||
|
||||
### 类实例
|
||||
|
||||
```kotlin
|
||||
// Class
|
||||
class Student {
|
||||
var name = "Lucia"
|
||||
var semester = "Fall"
|
||||
var gpa = 3.95
|
||||
}
|
||||
|
||||
fun main() {
|
||||
var student = Student()
|
||||
// Instance
|
||||
println(student.name)
|
||||
// Prints: Lucia
|
||||
println(student.semester)
|
||||
// Prints: Fall
|
||||
println(student.gpa)
|
||||
// Prints: 3.95
|
||||
}
|
||||
```
|
||||
|
||||
### 主构造函数
|
||||
|
||||
```kotlin
|
||||
class Student(val name: String, val gpa: Double, val semester: String, val estimatedGraduationYear: Int)
|
||||
|
||||
fun main() {
|
||||
var student = Student("Lucia", 3.95, "Fall", 2022)
|
||||
println(student.name)
|
||||
// Prints: Lucia
|
||||
println(student.gpa)
|
||||
// Prints: 3.95
|
||||
println(student.semester)
|
||||
// Prints: Fall
|
||||
println(student.estimatedGraduationYear)
|
||||
// Prints: 2022
|
||||
}
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 初始化块
|
||||
|
||||
```kotlin
|
||||
class Student(val name: String, val gpa: Double, val semester: String, val estimatedGraduationYear: Int) {
|
||||
init {
|
||||
println("$name has ${estimatedGraduationYear - 2020} years left in college.")
|
||||
}
|
||||
}
|
||||
|
||||
fun main() {
|
||||
var student = Student("Lucia", 3.95, "Fall", 2022)
|
||||
// Prints: Lucia has 2 years left in college.
|
||||
}
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 成员函数
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
```kotlin
|
||||
class Student(val name: String, val gpa: Double, val semester: String, val estimatedGraduationYear: Int) {
|
||||
|
||||
init {
|
||||
println("$name has ${estimatedGraduationYear - 2020} years left in college.")
|
||||
}
|
||||
|
||||
// 成员函数
|
||||
fun calculateLetterGrade(): String {
|
||||
return when {
|
||||
gpa >= 3.0 -> "A"
|
||||
gpa >= 2.7 -> "B"
|
||||
gpa >= 1.7 -> "C"
|
||||
gpa >= 1.0 -> "D"
|
||||
else -> "E"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 创建实例并调用函数时,将执行 when 表达式并返回字母等级
|
||||
fun main() {
|
||||
var student = Student("Lucia", 3.95, "Fall", 2022)
|
||||
// Prints: Lucia has 2 years left in college.
|
||||
println("${student.name}'s letter grade is ${student.calculateLetterGrade()}.")
|
||||
// Prints: Lucia's letter grade is A.
|
||||
}
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
另见
|
||||
---
|
||||
|
||||
- [Kotlin 语言官方文档](https://kotlinlang.org/) _(kotlinlang.org)_
|
433
docs/latex.md
Normal file
433
docs/latex.md
Normal file
@@ -0,0 +1,433 @@
|
||||
LaTeX 备忘清单
|
||||
===
|
||||
|
||||
本备忘单总结了 [LaTeX](https://www.latex-project.org/) 常用显示数学符号的参考列表和一些 [KaTeX](https://katex.org/) 的应用示例。
|
||||
|
||||
入门
|
||||
---
|
||||
|
||||
### 介绍
|
||||
|
||||
[LaTeX](https://www.latex-project.org/) 基于 TEX 的排版系统,适用于生成高印刷质量的科技和数学、物理文档。
|
||||
|
||||
- [LaTeX 官网](https://www.latex-project.org/) _(latex-project.org)_
|
||||
- [KaTeX 官网](https://katex.org/) _(katex.org)_
|
||||
|
||||
而 [KaTeX](https://katex.org/) 只处理 LaTeX 的数学符号的一个更小的子集,用于 web 上展示
|
||||
|
||||
### 示例
|
||||
|
||||
```KaTeX
|
||||
% \f is defined as #1f(#2) using the macro
|
||||
f\relax(x) = \int_{-\infty}^\infty
|
||||
f\hat\xi\,e^{2 \pi i \xi x}
|
||||
\,d\xi
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```LaTeX
|
||||
% \f is defined as #1f(#2) using the macro
|
||||
f\relax(x) = \int_{-\infty}^\infty
|
||||
f\hat\xi\,e^{2 \pi i \xi x}
|
||||
\,d\xi
|
||||
```
|
||||
|
||||
### 行内展示
|
||||
|
||||
```markdown
|
||||
基于 KaTeX 在一行
|
||||
展示示例: `KaTeX:\int_0^\infty x^2 dx`
|
||||
```
|
||||
|
||||
基于 KaTeX 在一行展示示例: `KaTeX:\int_0^\infty x^2 dx`
|
||||
|
||||
Supported Functions
|
||||
---
|
||||
|
||||
### Accents
|
||||
<!--rehype:wrap-class=col-span-2 row-span-2-->
|
||||
|
||||
:- | :- | :-
|
||||
:- | :- | :-
|
||||
`KaTeX:a'` <pur>`a'`</pur> | `KaTeX:\tilde{a}` <pur>`\tilde{a}`</pur> | `KaTeX:\mathring{g}` <pur>`\mathring{g}`</pur>
|
||||
`KaTeX:a''` <pur>`a''`</pur> | `KaTeX:\widetilde{ac}` <pur>`\widetilde{ac}`</pur> | `KaTeX:\overgroup{AB}` <pur>`\overgroup{AB}`</pur>
|
||||
`KaTeX:a^{\prime}` <pur>`a^{\prime}`</pur> | `KaTeX:\utilde{AB}` <pur>`\utilde{AB}`</pur> | `KaTeX:\undergroup{AB}` <pur>`\undergroup{AB}`</pur>
|
||||
`KaTeX:\acute{a}` <pur>`\acute{a}`</pur> | `KaTeX:\vec{F}` <pur>`\vec{F}`</pur> | `KaTeX:\Overrightarrow{AB}` <pur>`\Overrightarrow{AB}`</pur>
|
||||
`KaTeX:\bar{y}` <pur>`\bar{y}`</pur> | `KaTeX:\overleftarrow{AB}` <pur>`\overleftarrow{AB}`</pur> | `KaTeX:\overrightarrow{AB}` <pur>`\overrightarrow{AB}`</pur>
|
||||
`KaTeX:\breve{a}` <pur>`\breve{a}`</pur> | `KaTeX:\underleftarrow{AB}` <pur>`\underleftarrow{AB}`</pur> | `KaTeX:\underrightarrow{AB}` <pur>`\underrightarrow{AB}`</pur>
|
||||
`KaTeX:\check{a}` <pur>`\check{a}`</pur> | `KaTeX:\overleftharpoon{ac}` <pur>`\overleftharpoon{ac}`</pur> | `KaTeX:\overrightharpoon{ac}` <pur>`\overrightharpoon{ac}`</pur>
|
||||
`KaTeX:\dot{a}` <pur>`\dot{a}`</pur> | `KaTeX:\overleftrightarrow{AB}` <pur>`\overleftrightarrow{AB}`</pur> | `KaTeX:\overbrace{AB}` <pur>`\overbrace{AB}`</pur>
|
||||
`KaTeX:\ddot{a}` <pur>`\ddot{a}`</pur> | `KaTeX:\underleftrightarrow{AB}` <pur>`\underleftrightarrow{AB}`</pur> | `KaTeX:\underbrace{AB}` <pur>`\underbrace{AB}`</pur>
|
||||
`KaTeX:\grave{a}` <pur>`\grave{a}`</pur> | `KaTeX:\overline{AB}` <pur>`\overline{AB}`</pur> | `KaTeX:\overlinesegment{AB}` <pur>`\overlinesegment{AB}`</pur>
|
||||
`KaTeX:\hat{\theta}` <pur>`\hat{\theta}`</pur> | `KaTeX:\underline{AB}` <pur>`\underline{AB}`</pur> | `KaTeX:\underlinesegment{AB}` <pur>`\underlinesegment{AB}`</pur>
|
||||
`KaTeX:\widehat{ac}` <pur>`\widehat{ac}`</pur> | `KaTeX:\widecheck{ac}` <pur>`\widecheck{ac}`</pur> | `KaTeX:\underbar{X}` <pur>`\underbar{X}`</pur>
|
||||
|
||||
### \text{…}中的强调功能
|
||||
|
||||
:- | :- | :-
|
||||
:- | :- | :-
|
||||
`KaTeX:\'{a}` <pur>`\'{a}`</pur> | `KaTeX:\~{a}` <pur>`\~{a}`</pur> |
|
||||
`KaTeX:\.{a}` <pur>`\.{a}`</pur> | `KaTeX:\H{a}` <pur>`\H{a}`</pur> |
|
||||
``KaTeX:\\\`{a}`` <pur><code>\\`{a}</code></pur> | `KaTeX:\={a}` <pur>`\={a}`</pur> |
|
||||
`KaTeX:\"{a}` <pur>`\"{a}`</pur> | `KaTeX:\v{a}` <pur>`\v{a}`</pur> |
|
||||
`KaTeX:\^{a}` <pur>`\^{a}`</pur> | `KaTeX:\u{a}` <pur>`\u{a}`</pur> |
|
||||
`KaTeX:\r{a}` <pur>`\r{a}`</pur> |
|
||||
|
||||
### Delimiter Sizing
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`KaTeX:\left(\LARGE{AB}\right)` | <pur>`\left(\LARGE{AB}\right)`</pur>
|
||||
`KaTeX:( \big( \Big( \bigg( \Bigg(`| <pur>`( \big( \Big( \bigg( \Bigg(`</pur>
|
||||
|
||||
---
|
||||
|
||||
:- | :- | :- | :- | :-
|
||||
:- | :- | :- | :- | :-
|
||||
`\left` | `\big` | `\bigl` | `\bigm` | `\bigr`
|
||||
`\middle` | `\Big` | `\Bigl` | `\Bigm` | `\Bigr`
|
||||
`\right` | `\bigg` | `\biggl` | `\biggm` | `\biggr`
|
||||
`` | `\Bigg` | `\Biggl` | `\Biggm` | `\Biggr`
|
||||
|
||||
### 分隔符 Delimiters
|
||||
<!--rehype:wrap-class=col-span-3-->
|
||||
|
||||
预览 | 方法 | 预览 | 方法 | 预览 | 方法 | 预览| 方法 | 预览 | 方法
|
||||
:- | :- | :- | :- | :- | :- | :- | :- | :- | :-
|
||||
| `KaTeX:()` | <pur>`()`</pur> | `KaTeX:\lparen \rparen` | <pur>`\lparen` `\rparen`</pur> | `KaTex:⌈ ⌉` | <pur>`⌈ ⌉`</pur> | `KaTex:\lceil \rceil` | <pur>`\lceil` `\rceil`</pur> | `KaTex:\uparrow` | <pur>`\uparrow`</pur> |
|
||||
| `KaTeX:[]` | <pur>`[]`</pur> | `KaTeX:\lbrack \rbrack` | <pur>`\lbrack` `\rbrack`</pur> | `KaTex:⌊ ⌋` | <pur>`⌊ ⌋`</pur> | `KaTex:\lfloor \rfloor` | <pur>`\lfloor` `\rfloor`</pur> | `KaTex:\downarrow` | <pur>`\downarrow`</pur> |
|
||||
| `KaTeX:\{ \}` | <pur>`{}`</pur> | `KaTex:\lbrace \rbrace` | <pur>`\lbrace` `\rbrace`</pur> | `KaTex:⎰⎱` | <pur>`⎰⎱`</pur> | `KaTex:\lmoustache \rmoustache` | <pur>`\lmoustache` `\rmoustache`</pur> | `KaTex:\updownarrow` | <pur>`\updownarrow`</pur> |
|
||||
| `KaTeX:⟨ ⟩` | <pur>`⟨⟩`</pur> | `KaTex:\langle \rangle` | <pur>`\langle` `\rangle`</pur> | `KaTex:⟮ ⟯` | <pur>`⟮ ⟯`</pur> | `KaTex:\lgroup \rgroup` | <pur>`\lgroup` `\rgroup`</pur> | `KaTex:\Uparrow` | <pur>`\Uparrow`</pur> |
|
||||
| `KaTeX:∣` | <pur>`\|`</pur> | `KaTex:\vert` | <pur>`\vert`</pur> | `KaTex:┌ ┐` | <pur>`┌ ┐`</pur> | `KaTex:\ulcorner \urcorner` | <pur>`\ulcorner` `\urcorner`</pur> | `KaTex:\Downarrow` | <pur>`\Downarrow`</pur> |
|
||||
| `KaTeX:\|` _(<red>MD语法冲突</red>)_ | <pur><code>\\|</code></pur> | `KaTex:\Vert` | <pur>`\Vert`</pur> | `KaTex:└ ┘` | <pur>`└ ┘`</pur> | `KaTex:\llcorner \lrcorner` | <pur>`\llcorner` `\lrcorner`</pur> | `KaTex:\Updownarrow` | <pur>`\Updownarrow`</pur> |
|
||||
| `KaTeX:∣ ∣` | <pur>`\lvert` `\rvert`</pur> | `KaTex:\lVert \rVert` | <pur>`\lVert` `\rVert`</pur> | | <pur>`\left.`</pur> | | <pur>`\right.`</pur> | `KaTex:\backslash` | <pur>`\backslash`</pur> |
|
||||
| `KaTeX:\lang` `KaTeX:\rang` | <pur>`\lang` `\rang`<pur> | `KaTeX:\lt \gt` | <pur>`\lt \gt`</pur> | `KaTex:⟦ ⟧` | <pur>`⟦ ⟧`</pur> | `KaTex:\llbracket \rrbracket` | <pur>`\llbracket` `\rrbracket`</pur> | `KaTex:\lBrace \rBrace` | <pur>`\lBrace \rBrace`</pur> |
|
||||
<!--rehype:className=show-header left-align-->
|
||||
|
||||
Environments
|
||||
---
|
||||
|
||||
### Environments 1
|
||||
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
|
||||
|
||||
```KaTeX
|
||||
\begin{matrix}
|
||||
a & b \\
|
||||
c & d
|
||||
\end{matrix}
|
||||
```
|
||||
<!--rehype:style=flex:1;-->
|
||||
|
||||
```LaTeX
|
||||
\begin{matrix}
|
||||
a & b \\
|
||||
c & d
|
||||
\end{matrix}
|
||||
```
|
||||
<!--rehype:style=flex:1;-->
|
||||
|
||||
### Environments 2
|
||||
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
|
||||
|
||||
```KaTeX
|
||||
\begin{array}{cc}
|
||||
a & b \\
|
||||
c & d
|
||||
\end{array}
|
||||
```
|
||||
<!--rehype:style=flex:1;-->
|
||||
|
||||
```LaTeX
|
||||
\begin{array}{cc}
|
||||
a & b \\
|
||||
c & d
|
||||
\end{array}
|
||||
```
|
||||
|
||||
### Environments 3
|
||||
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
|
||||
|
||||
```KaTeX
|
||||
\begin{pmatrix}
|
||||
a & b \\
|
||||
c & d
|
||||
\end{pmatrix}
|
||||
```
|
||||
<!--rehype:style=flex:1;-->
|
||||
|
||||
```LaTeX
|
||||
\begin{pmatrix}
|
||||
a & b \\
|
||||
c & d
|
||||
\end{pmatrix}
|
||||
```
|
||||
<!--rehype:style=flex:1;-->
|
||||
|
||||
### Environments 4
|
||||
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
|
||||
|
||||
```KaTeX
|
||||
\begin{bmatrix}
|
||||
a & b \\
|
||||
c & d
|
||||
\end{bmatrix}
|
||||
```
|
||||
|
||||
```LaTeX
|
||||
\begin{bmatrix}
|
||||
a & b \\
|
||||
c & d
|
||||
\end{bmatrix}
|
||||
```
|
||||
|
||||
### Environments 5
|
||||
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
|
||||
|
||||
```KaTeX
|
||||
\begin{vmatrix}
|
||||
a & b \\
|
||||
c & d
|
||||
\end{vmatrix}
|
||||
```
|
||||
<!--rehype:style=flex:1;-->
|
||||
|
||||
```LaTeX
|
||||
\begin{vmatrix}
|
||||
a & b \\
|
||||
c & d
|
||||
\end{vmatrix}
|
||||
```
|
||||
<!--rehype:style=flex:1;-->
|
||||
|
||||
### Environments 6
|
||||
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
|
||||
|
||||
```KaTeX
|
||||
\begin{Vmatrix}
|
||||
a & b \\
|
||||
c & d
|
||||
\end{Vmatrix}
|
||||
```
|
||||
<!--rehype:style=flex:1;-->
|
||||
|
||||
```LaTeX
|
||||
\begin{Vmatrix}
|
||||
a & b \\
|
||||
c & d
|
||||
\end{Vmatrix}
|
||||
```
|
||||
<!--rehype:style=flex:1;-->
|
||||
|
||||
### Environments 7
|
||||
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
|
||||
|
||||
```KaTeX
|
||||
\begin{Bmatrix}
|
||||
a & b \\
|
||||
c & d
|
||||
\end{Bmatrix}
|
||||
```
|
||||
|
||||
```LaTeX
|
||||
\begin{Bmatrix}
|
||||
a & b \\
|
||||
c & d
|
||||
\end{Bmatrix}
|
||||
```
|
||||
|
||||
### Environments 8
|
||||
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
|
||||
|
||||
```KaTeX
|
||||
\def\arraystretch{1.5}
|
||||
\begin{array}{c:c:c}
|
||||
a & b & c \\ \hline
|
||||
d & e & f \\
|
||||
\hdashline
|
||||
g & h & i
|
||||
\end{array}
|
||||
```
|
||||
<!--rehype:style=flex:1;-->
|
||||
|
||||
```LaTeX
|
||||
\def\arraystretch{1.5}
|
||||
\begin{array}{c:c:c}
|
||||
a & b & c \\ \hline
|
||||
d & e & f \\
|
||||
\hdashline
|
||||
g & h & i
|
||||
\end{array}
|
||||
```
|
||||
|
||||
### Environments 9
|
||||
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
|
||||
|
||||
```KaTeX
|
||||
x = \begin{cases}
|
||||
a &\text{if } b \\
|
||||
c &\text{if } d
|
||||
\end{cases}
|
||||
```
|
||||
|
||||
```LaTeX
|
||||
x = \begin{cases}
|
||||
a &\text{if } b \\
|
||||
c &\text{if } d
|
||||
\end{cases}
|
||||
```
|
||||
|
||||
### Environments 10
|
||||
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
|
||||
|
||||
```KaTeX
|
||||
\begin{rcases}
|
||||
a &\text{if } b \\
|
||||
c &\text{if } d
|
||||
\end{rcases}⇒…
|
||||
```
|
||||
|
||||
```LaTeX
|
||||
\begin{rcases}
|
||||
a &\text{if } b \\
|
||||
c &\text{if } d
|
||||
\end{rcases}⇒…
|
||||
```
|
||||
|
||||
### Environments 11
|
||||
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
|
||||
|
||||
```KaTeX
|
||||
\begin{smallmatrix}
|
||||
a & b \\
|
||||
c & d
|
||||
\end{smallmatrix}
|
||||
```
|
||||
<!--rehype:style=flex:1;-->
|
||||
|
||||
```LaTeX
|
||||
\begin{smallmatrix}
|
||||
a & b \\
|
||||
c & d
|
||||
\end{smallmatrix}
|
||||
```
|
||||
|
||||
### Environments 12
|
||||
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
|
||||
|
||||
```KaTeX
|
||||
\sum_{
|
||||
\begin{subarray}{l}
|
||||
i\in\Lambda\\
|
||||
0<j<n
|
||||
\end{subarray}}
|
||||
```
|
||||
<!--rehype:style=flex:1;-->
|
||||
|
||||
```LaTeX
|
||||
\sum_{
|
||||
\begin{subarray}{l}
|
||||
i\in\Lambda\\
|
||||
0<j<n
|
||||
\end{subarray}}
|
||||
```
|
||||
|
||||
### Environments 13
|
||||
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
|
||||
|
||||
```KaTeX
|
||||
\begin{equation}
|
||||
\begin{split} a &=b+c\\
|
||||
&=e+f
|
||||
\end{split}
|
||||
\end{equation}
|
||||
```
|
||||
<!--rehype:style=flex:1;-->
|
||||
|
||||
```LaTeX
|
||||
\begin{equation}
|
||||
\begin{split} a &=b+c\\
|
||||
&=e+f
|
||||
\end{split}
|
||||
\end{equation}
|
||||
```
|
||||
|
||||
### Environments 14
|
||||
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
|
||||
|
||||
```KaTeX
|
||||
\begin{align}
|
||||
a&=b+c \\
|
||||
d+e&=f
|
||||
\end{align}
|
||||
```
|
||||
<!--rehype:style=flex:1;-->
|
||||
|
||||
```LaTeX
|
||||
\begin{align}
|
||||
a&=b+c \\
|
||||
d+e&=f
|
||||
\end{align}
|
||||
```
|
||||
|
||||
### Environments 15
|
||||
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
|
||||
|
||||
```KaTeX
|
||||
\begin{gather}
|
||||
a=b \\
|
||||
e=b+c
|
||||
\end{gather}
|
||||
```
|
||||
<!--rehype:style=flex:1;-->
|
||||
|
||||
```LaTeX
|
||||
\begin{gather}
|
||||
a=b \\
|
||||
e=b+c
|
||||
\end{gather}
|
||||
```
|
||||
|
||||
### Environments 16
|
||||
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
|
||||
|
||||
```KaTeX
|
||||
\begin{alignat}{2}
|
||||
10&x+&3&y=2\\
|
||||
3&x+&13&y=4
|
||||
\end{alignat}
|
||||
```
|
||||
<!--rehype:style=flex:1;-->
|
||||
|
||||
```LaTeX
|
||||
\begin{alignat}{2}
|
||||
10&x+&3&y=2\\
|
||||
3&x+&13&y=4
|
||||
\end{alignat}
|
||||
```
|
||||
|
||||
### Environments 17
|
||||
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
|
||||
|
||||
```KaTeX
|
||||
\begin{CD}
|
||||
A @>a>> B \\
|
||||
@VbVV @AAcA \\
|
||||
C @= D
|
||||
\end{CD}
|
||||
```
|
||||
<!--rehype:style=flex:1;-->
|
||||
|
||||
```LaTeX
|
||||
\begin{CD}
|
||||
A @>a>> B \\
|
||||
@VbVV @AAcA \\
|
||||
C @= D
|
||||
\end{CD}
|
||||
```
|
||||
|
||||
另见
|
||||
----
|
||||
|
||||
- [LaTeX 官网](https://www.latex-project.org/) _(latex-project.org)_
|
||||
- [KaTeX 官网](https://katex.org/) _(katex.org)_
|
@@ -199,7 +199,7 @@ $ lerna publish --canary preminor
|
||||
}
|
||||
```
|
||||
|
||||
----
|
||||
---
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
@@ -239,7 +239,7 @@ $ lerna version -m "chore(doc): publish %v"
|
||||
- `prerelease` 预发行
|
||||
<!--rehype:className=cols-2-->
|
||||
|
||||
----
|
||||
---
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
@@ -311,7 +311,6 @@ $ lerna bootstrap --hoist
|
||||
`--force-local` [#](https://github.com/lerna/lerna/tree/main/commands/bootstrap#--force-local) | 此标志会导致引导命令始终对本地依赖项进行符号链接,而不管匹配的版本范围如何
|
||||
<!--rehype:className=style-list-arrow-->
|
||||
|
||||
|
||||
### info 本地环境信息
|
||||
|
||||
```bash
|
||||
@@ -424,13 +423,13 @@ lerna la
|
||||
- 如果不存在 `.gitignore`,则生成一个忽略文件
|
||||
<!--rehype:className=style-timeline-->
|
||||
|
||||
----
|
||||
---
|
||||
|
||||
```shell
|
||||
$ lerna init --independent
|
||||
```
|
||||
|
||||
----
|
||||
---
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
@@ -527,7 +526,6 @@ $ lerna diff package-name # 区分一个特定的包
|
||||
|
||||
类似于 `lerna changed`,此命令运行 `git diff`
|
||||
|
||||
|
||||
### clean
|
||||
|
||||
从所有包中删除 `node_modules` 目录
|
||||
|
@@ -72,7 +72,6 @@ $ lessc styles.less styles.css
|
||||
|
||||
另见: [混合(Mixin)的更多信息](https://lesscss.org/features/#mixins-feature)
|
||||
|
||||
|
||||
### 嵌套(Nesting)
|
||||
|
||||
```css
|
||||
|
@@ -78,7 +78,6 @@ $ kill -9 `lsof -t -u apache`
|
||||
$ kill -9 $(lsof -t -i :8080)
|
||||
```
|
||||
|
||||
|
||||
### 参数
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
@@ -109,13 +108,12 @@ lsof -p $pid
|
||||
lsof -i:9981 -P -t -sTCP:LISTEN
|
||||
```
|
||||
|
||||
### 列出打开文件的进程:
|
||||
### 列出打开文件的进程
|
||||
|
||||
```bash
|
||||
lsof $filename
|
||||
```
|
||||
|
||||
|
||||
示例
|
||||
---
|
||||
|
||||
@@ -219,7 +217,6 @@ migration 2 root txt unknown /proc/2/exe
|
||||
`NAME` | 打开文件的确切名称
|
||||
`REG` | 常规文件
|
||||
|
||||
|
||||
另见
|
||||
---
|
||||
|
||||
|
@@ -3,7 +3,6 @@ Markdown 备忘清单
|
||||
|
||||
这是 Markdown 语法的快速参考备忘单。
|
||||
|
||||
|
||||
Markdown 快速参考
|
||||
----
|
||||
|
||||
@@ -30,7 +29,6 @@ Header 2
|
||||
--------
|
||||
```
|
||||
|
||||
|
||||
### 块引用
|
||||
|
||||
```markdown
|
||||
@@ -64,6 +62,7 @@ Header 2
|
||||
+ Item 1
|
||||
+ Item 2
|
||||
```
|
||||
|
||||
或者**任务**列表
|
||||
|
||||
```markdown
|
||||
@@ -132,11 +131,13 @@ ___
|
||||
|
||||
### 代码
|
||||
|
||||
~~~markdown
|
||||
```markdown
|
||||
|
||||
```javascript
|
||||
console.log("This is a block code")
|
||||
```
|
||||
~~~
|
||||
|
||||
```
|
||||
|
||||
```markdown
|
||||
~~~css
|
||||
@@ -144,12 +145,10 @@ console.log("This is a block code")
|
||||
~~~
|
||||
```
|
||||
|
||||
|
||||
```markdown
|
||||
4 空格缩进做一个代码块
|
||||
```
|
||||
|
||||
|
||||
#### 内联代码
|
||||
|
||||
```markdown
|
||||
@@ -240,7 +239,7 @@ Markdown 表格生成器:[tableconvert.com](https://tableconvert.com/)
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
```html
|
||||
目前只支持部分段内 HTML 元素效果,包括 <kdb>, <b>, <i>, <em>, <sup>, <sub>, <br>
|
||||
目前只支持部分段内 HTML 元素效果,包括 <kbd>, <b>, <i>, <em>, <sup>, <sub>, <br>
|
||||
```
|
||||
|
||||
另见
|
||||
|
@@ -6,7 +6,6 @@ MATLAB 备忘清单
|
||||
入门
|
||||
---
|
||||
|
||||
|
||||
### 介绍
|
||||
|
||||
MATLAB 是 `matrix laboratory` 的缩写形式
|
||||
@@ -24,14 +23,18 @@ MATLAB 允许您使用单一的算术运算符或函数来处理矩阵中的所
|
||||
```matlab
|
||||
a + 10
|
||||
```
|
||||
|
||||
MATLAB 将执行上述语句,并返回以下结果:
|
||||
|
||||
```
|
||||
ans = 3×3
|
||||
11 13 15
|
||||
12 14 16
|
||||
17 18 20
|
||||
```
|
||||
---
|
||||
|
||||
----
|
||||
|
||||
```matlab
|
||||
sin(a)
|
||||
```
|
||||
@@ -50,7 +53,9 @@ ans = 3×3
|
||||
```matlab
|
||||
a'
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
```
|
||||
ans = 3×3
|
||||
1 2 7
|
||||
@@ -63,7 +68,9 @@ ans = 3×3
|
||||
```matlab
|
||||
p = a*inv(a)
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
```
|
||||
p = 3×3
|
||||
1.0000 0 0
|
||||
@@ -79,7 +86,9 @@ p = 3×3
|
||||
```matlab
|
||||
A = [a,a]
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
```
|
||||
A = 3×6
|
||||
|
||||
@@ -93,7 +102,9 @@ A = 3×6
|
||||
```matlab
|
||||
A = [a; a]
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
```
|
||||
A = 6×3
|
||||
|
||||
@@ -126,7 +137,9 @@ a = 1×4
|
||||
```matlab
|
||||
a = [1 3 5; 2 4 6; 7 8 10]
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
```
|
||||
a = 3×3
|
||||
1 3 5
|
||||
@@ -139,7 +152,9 @@ a = 3×3
|
||||
```matlab
|
||||
z = zeros(5,1)
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
```
|
||||
z = 5×1
|
||||
0
|
||||
@@ -156,6 +171,7 @@ z = 5×1
|
||||
```matlab
|
||||
sqrt(-1)
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
```
|
||||
@@ -167,7 +183,9 @@ ans = 0.0000 + 1.0000i
|
||||
```matlab
|
||||
c = [3+4i, 4+3j; -i, 10j]
|
||||
```
|
||||
|
||||
----
|
||||
|
||||
```
|
||||
c = 2×2 complex
|
||||
|
||||
@@ -198,7 +216,6 @@ c = 2×2 complex
|
||||
:- | :-
|
||||
[DisplayFormatOptions](https://ww2.mathworks.cn/help/matlab/ref/ans.html) | 命令行窗口中的输出显示格式
|
||||
|
||||
|
||||
### 矩阵和数组
|
||||
<!--rehype:wrap-class=row-span-5-->
|
||||
|
||||
@@ -478,7 +495,6 @@ c = 2×2 complex
|
||||
|
||||
### 字符串匹配模式 - 自定义模式显示
|
||||
|
||||
|
||||
:- | :- | :-
|
||||
:- | :- | :-
|
||||
[maskedPattern](https://ww2.mathworks.cn/help/matlab/ref/maskedpattern.html) | 具有指定显示名称的模式
|
||||
@@ -494,7 +510,6 @@ c = 2×2 complex
|
||||
[regexptranslate](https://ww2.mathworks.cn/help/matlab/ref/regexptranslate.html) | 将文本转换为正则表达式
|
||||
[regexpPattern](https://ww2.mathworks.cn/help/matlab/ref/regexppattern.html) | 匹配指定正则表达式的模式
|
||||
|
||||
|
||||
### 字符串匹配模式 - 联接和拆分
|
||||
|
||||
:- | :- | :-
|
||||
@@ -543,7 +558,6 @@ c = 2×2 complex
|
||||
[strncmp](https://ww2.mathworks.cn/help/matlab/ref/strncmp.html) | 比较字符串的前 <code class="literal">n</code> 个字符(区分大小写)
|
||||
[strncmpi](https://ww2.mathworks.cn/help/matlab/ref/strncmpi.html) | 比较字符串的前 <code class="literal">n</code> 个字符(不区分大小写)
|
||||
|
||||
|
||||
### 基本算术
|
||||
<!--rehype:wrap-class=row-span-3-->
|
||||
|
||||
@@ -620,7 +634,6 @@ c = 2×2 complex
|
||||
:- | :- | :-
|
||||
[bsxfun](https://ww2.mathworks.cn/help/matlab/ref/bsxfun.html) | 对两个数组应用按元素运算(启用隐式扩展)
|
||||
|
||||
|
||||
### 关系运算
|
||||
|
||||
值的比较
|
||||
@@ -688,7 +701,6 @@ true 或 false 条件
|
||||
[bitshift](https://ww2.mathworks.cn/help/matlab/ref/bitshift.html) | 将位移动指定位数
|
||||
[swapbytes](https://ww2.mathworks.cn/help/matlab/ref/swapbytes.html) | 交换字节顺序
|
||||
|
||||
|
||||
数据导入和导出
|
||||
---
|
||||
|
||||
@@ -824,7 +836,6 @@ true 或 false 条件
|
||||
|
||||
### NetCDF 库程序包 - 维度
|
||||
|
||||
|
||||
:- | :- | :-
|
||||
:- | :- | :-
|
||||
[netcdf.defDim](https://ww2.mathworks.cn/help/matlab/ref/netcdf.defdim.html) | 创建 netCDF 维度
|
||||
@@ -907,7 +918,6 @@ true 或 false 条件
|
||||
[h5write](https://ww2.mathworks.cn/help/matlab/ref/h5write.html) | 写入 HDF5 数据集
|
||||
[h5writeatt](https://ww2.mathworks.cn/help/matlab/ref/h5writeatt.html) | 写入 HDF5 属性
|
||||
|
||||
|
||||
### HDF5 库程序包
|
||||
<!--rehype:wrap-class=row-span-4-->
|
||||
|
||||
@@ -966,7 +976,6 @@ true 或 false 条件
|
||||
[hdfdf24](https://ww2.mathworks.cn/help/matlab/ref/hdfdf24.html) | HDF 24 位光栅图像 (DF24) 接口的入口
|
||||
[hdfdfr8](https://ww2.mathworks.cn/help/matlab/ref/hdfdfr8.html) | HDF 8 位光栅图像 (DFR8) 接口的入口
|
||||
|
||||
|
||||
### FITS 文件 - 函数
|
||||
|
||||
:- | :-
|
||||
@@ -1305,7 +1314,6 @@ true 或 false 条件
|
||||
[setRTS](https://ww2.mathworks.cn/help/matlab/ref/serialport.setrts.html) | 设置串行 RTS 引脚
|
||||
[setDTR](https://ww2.mathworks.cn/help/matlab/ref/serialport.setdtr.html) | 设置串行 DTR 引脚
|
||||
|
||||
|
||||
### TCP/IP 通信 - 连接和配置
|
||||
|
||||
:- | :-
|
||||
|
@@ -3,7 +3,6 @@ MIME 类型 备忘清单
|
||||
|
||||
此备忘单列出了一些常见的 Web MIME 类型。 您可以查看包含所有已注册 MIME 类型的 [IANA/MIME 媒体类型注册表](https://www.iana.org/assignments/media-types/media-types.xhtml)。
|
||||
|
||||
|
||||
入门
|
||||
----
|
||||
|
||||
@@ -17,7 +16,6 @@ MIME 类型 备忘清单
|
||||
- 对于 Internet 上的文件格式或格式内容
|
||||
<!--rehype:className=style-round-->
|
||||
|
||||
|
||||
MIME 类型列表
|
||||
--------
|
||||
|
||||
|
@@ -3,7 +3,6 @@ MySQL 备忘清单
|
||||
|
||||
本备忘单旨在快速理解 [MySQL](https://mysql.com) 所涉及的主要概念,提供了最常用的SQL语句,供您参考。
|
||||
|
||||
|
||||
入门
|
||||
---
|
||||
|
||||
@@ -174,6 +173,12 @@ ALTER TABLE t1 RENAME TO t2;
|
||||
ALTER TABLE t1 RENAME c1 TO c2 ;
|
||||
```
|
||||
|
||||
将列c1的数据类型改为datatype
|
||||
|
||||
```sql
|
||||
ALTER TABLE t1 MODIFY c1 datatype;
|
||||
```
|
||||
|
||||
删除表中的所有数据
|
||||
|
||||
```sql
|
||||
@@ -388,6 +393,7 @@ CREATE TABLE t(
|
||||
CHECK(c1> 0 AND c1 >= c2)
|
||||
);
|
||||
```
|
||||
|
||||
c2列中的设置值不为NULL
|
||||
|
||||
```sql
|
||||
@@ -556,7 +562,6 @@ DROP INDEX idx_name;
|
||||
MySQL 数据类型
|
||||
---------
|
||||
|
||||
|
||||
### Strings
|
||||
|
||||
| - | - |
|
||||
@@ -573,8 +578,8 @@ MySQL 数据类型
|
||||
| `ENUM` | One of preset options |
|
||||
| `SET` | Selection of preset options |
|
||||
|
||||
|
||||
### Date & time
|
||||
|
||||
| Data Type | Format |
|
||||
|-------------|---------------------|
|
||||
| `DATE` | yyyy-MM-dd |
|
||||
@@ -583,7 +588,6 @@ MySQL 数据类型
|
||||
| `TIMESTAMP` | yyyy-MM-dd hh:mm:ss |
|
||||
| `YEAR` | yyyy |
|
||||
|
||||
|
||||
### Numeric
|
||||
|
||||
| - | - |
|
||||
|
@@ -25,7 +25,6 @@ $ nc -lp port [host] [port]
|
||||
### 选项示例
|
||||
<!--rehype:wrap-class=col-span-3 row-span-2-->
|
||||
|
||||
|
||||
选项 | 示例 | 说明
|
||||
:- | :- | :-
|
||||
`-h` | nc -h | 帮助
|
||||
@@ -40,7 +39,6 @@ $ nc -lp port [host] [port]
|
||||
`-4` | nc -4 -l 8000 | 仅限 `IPv4`
|
||||
`-6` | nc -6 -l 8000 | 仅限 `IPv6`
|
||||
|
||||
|
||||
### 聊天客户端-服务器
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
|
@@ -42,7 +42,6 @@ $ netstat -h
|
||||
`netstat -au` | 所有 UDP 连接
|
||||
`netstat -ant` | 显示没有反向 DNS 查找的 IP 地址
|
||||
|
||||
|
||||
选项 | 说明
|
||||
:- | :-
|
||||
`netstat` | 活动连接
|
||||
@@ -53,7 +52,6 @@ $ netstat -h
|
||||
`netstat -tnl` | 监听 TCP 端口
|
||||
`netstat -unl` | 监听 UDP 端口
|
||||
|
||||
|
||||
### 网络
|
||||
|
||||
选项 | 说明
|
||||
@@ -65,7 +63,6 @@ $ netstat -h
|
||||
|
||||
### 路由
|
||||
|
||||
|
||||
选项 | 说明
|
||||
:- | :-
|
||||
`netstat -r` | 显示路由表
|
||||
|
@@ -313,7 +313,6 @@ server {
|
||||
|
||||
您可以使用 Let's Encrypt 轻松保护您的网站/应用程序。去 [lets-encrypt](https://certbot.eff.org/lets-encrypt/ubuntuxenial-nginx.html) 获取更多信息
|
||||
|
||||
|
||||
### 重定向(301永久)
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
|
195
docs/npm.md
195
docs/npm.md
@@ -21,6 +21,7 @@ npm 备忘清单
|
||||
`npm install <package_name>@<tag>` | 使用 `dist-tags` 安装包
|
||||
`npm install -g <package_name>` | 全局安装包
|
||||
`npm uninstall <package_name>` | 卸载包
|
||||
`npm uninstall -g <package_name>` | 全局卸载包
|
||||
<!--rehype:class=auto-wrap-->
|
||||
|
||||
### 安装
|
||||
@@ -86,11 +87,9 @@ $ npm cache verify # 验证缓存文件夹的内容,垃圾收集任何不需
|
||||
`npm update -g` | 更新全局包
|
||||
`npm update lodash` | 更新 `lodash` 包
|
||||
|
||||
|
||||
### 杂项功能
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
|
||||
```bash
|
||||
# 将某人添加为所有者
|
||||
$ npm owner add USERNAME PACKAGENAME
|
||||
@@ -156,6 +155,153 @@ $ nrm ls
|
||||
$ nrm use cnpm
|
||||
```
|
||||
|
||||
### init
|
||||
|
||||
用于设置新的或现有的 `npm` 包
|
||||
|
||||
```bash
|
||||
$ npm init <package-spec> # (如同 `npx <package-spec>)
|
||||
$ npm init <@scope> # (如同 `npx <@scope>/create`)
|
||||
```
|
||||
|
||||
别名: `create`, `innit`
|
||||
|
||||
:- | --
|
||||
:- | --
|
||||
`npm init foo` | `npm exec create-foo`
|
||||
`npm init @usr/foo` | `npm exec @usr/create-foo`
|
||||
`npm init @usr` | `npm exec @usr/create`
|
||||
`npm init @usr@2.0.0` | `npm exec @usr/create@2.0.0`
|
||||
`npm init @usr/foo@2.0.0` | `npm exec @usr/create-foo@2.0.0`
|
||||
<!--rehype:className=left-align-->
|
||||
|
||||
### exec
|
||||
|
||||
命令允许您在与通过 `npm run` 运行它类似的上下文中从 npm 包
|
||||
|
||||
```bash
|
||||
$ npm exec -- <pkg>[@<version>] [args...]
|
||||
$ npm exec --package=<pkg>[@<version>] -- <cmd> [args...]
|
||||
$ npm exec -c '<cmd> [args...]'
|
||||
$ npm exec --package=foo -c '<cmd> [args...]'
|
||||
```
|
||||
|
||||
别名: x
|
||||
|
||||
```bash
|
||||
$ npm exec --package yo --package generator-node --call "yo node"
|
||||
|
||||
$ npm exec --package=foo -- bar --bar-argument
|
||||
# ~ or ~
|
||||
$ npx --package=foo bar --bar-argument
|
||||
```
|
||||
|
||||
npx
|
||||
---
|
||||
|
||||
### 介绍
|
||||
|
||||
从本地或远程 npm 包运行命令
|
||||
|
||||
```bash
|
||||
npx -- <pkg>[@<version>] [args...]
|
||||
npx --package=<pkg>[@<version>] -- <cmd> [args...]
|
||||
npx -c '<cmd> [args...]'
|
||||
npx --package=foo -c '<cmd> [args...]'
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
`npx` 二进制文件在 `npm v7.0.0` 中被重写,并且当时不推荐使用独立的 `npx` 包
|
||||
|
||||
```bash
|
||||
$ npm install eslint
|
||||
# 运行:
|
||||
$ ./node_modules/.bin/eslint
|
||||
```
|
||||
|
||||
上面命令简化,直接运行下面👇命令
|
||||
|
||||
```bash
|
||||
$ npx eslint
|
||||
```
|
||||
|
||||
命令 `npx` 将自动安装并运行 `eslint`
|
||||
|
||||
### npx VS npm exec
|
||||
|
||||
```bash
|
||||
$ npx foo@latest bar --package=@npmcli/foo
|
||||
# npm 将解析 foo 包名,并运行以下命令:
|
||||
$ foo bar --package=@npmcli/foo
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
由于 npm 的参数解析逻辑,运行这个命令是不同的:
|
||||
|
||||
```bash
|
||||
$ npm exec foo@latest bar --package=@npmcli/foo
|
||||
# npm 将首先解析 --package 选项
|
||||
# 解析 @npmcli/foo 包
|
||||
# 然后,它将在该上下文中执行以下命令:
|
||||
$ foo@latest bar
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
下面命令是与 `npx` 等效的
|
||||
|
||||
```bash
|
||||
$ npm exec -- foo@latest bar --package=@npmcli/foo
|
||||
# 等效的
|
||||
$ npx foo@latest bar --package=@npmcli/foo
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### npx VS npm exec 示例
|
||||
|
||||
使用提供的参数在本地依赖项中运行 `tap` 版本:
|
||||
|
||||
```bash
|
||||
$ npm exec -- tap --bail test/foo.js
|
||||
$ npx tap --bail test/foo.js
|
||||
```
|
||||
|
||||
通过指定 `--package` 选项运行名称与包名称匹配的命令以外的命令:
|
||||
|
||||
```bash
|
||||
$ npm exec --package=foo -- bar --bar-argument
|
||||
# ~ or ~
|
||||
$ npx --package=foo bar --bar-argument
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
在当前项目的上下文中运行任意 `shell` 脚本:
|
||||
|
||||
```bash
|
||||
$ npm x -c 'eslint && say "hooray, lint passed"'
|
||||
$ npx -c 'eslint && say "hooray, lint passed"'
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 创建一个 React Naive 项目
|
||||
|
||||
```bash
|
||||
$ npx react-native init AwesomeProject
|
||||
$ npx react-native init AwesomeTSProject --template react-native-template-typescript
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
使用 `npx` 直接创建一个 [React Native](https://reactnative.dev/docs/environment-setup#creating-a-new-application) 应用
|
||||
|
||||
### 创建一个 React 应用
|
||||
|
||||
```bash
|
||||
$ npx create-react-app my-app
|
||||
$ npx create-react-app my-app --template typescript
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
使用 `npx` 跳过安装 [CRA](https://reactnative.dev/docs/environment-setup#creating-a-new-application),直接创建一个 [React](./react.md) 应用
|
||||
|
||||
配置
|
||||
---
|
||||
|
||||
@@ -168,7 +314,6 @@ $ nrm use cnpm
|
||||
`$PREFIX/etc/npmrc` | 全局配置文件
|
||||
`/path/to/npm/npmrc` | npm 内置配置文件
|
||||
|
||||
|
||||
### 配置内容
|
||||
|
||||
```ini
|
||||
@@ -180,17 +325,16 @@ $ nrm use cnpm
|
||||
|
||||
注释使用 `#`, `;` 放置到一行的开头, [`.npmrc`](https://docs.npmjs.com/cli/v8/configuring-npm/npmrc) 文件由指定此注释语法的 [`npm/ini`](https://github.com/npm/ini) 解析
|
||||
|
||||
|
||||
### registry
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`npm` | https://registry.npmjs.org/
|
||||
`yarn` | https://registry.yarnpkg.com/
|
||||
`tencent` | https://mirrors.cloud.tencent.com/npm/
|
||||
`cnpm` | https://r.cnpmjs.org/
|
||||
`taobao` | https://registry.npmmirror.com/
|
||||
`npmMirror` | https://skimdb.npmjs.com/registry/
|
||||
`npm` | <https://registry.npmjs.org/>
|
||||
`yarn` | <https://registry.yarnpkg.com/>
|
||||
`tencent` | <https://mirrors.cloud.tencent.com/npm/>
|
||||
`cnpm` | <https://r.cnpmjs.org/>
|
||||
`taobao` | <https://registry.npmmirror.com/>
|
||||
`npmMirror` | <https://skimdb.npmjs.com/registry/>
|
||||
|
||||
### `.npmignore`
|
||||
|
||||
@@ -261,8 +405,39 @@ ELECTRON_BUILDER_BINARIES_MIRROR=https://npmmirror.com/mirrors/electron-builder-
|
||||
//somewhere.com/another/:_authToken=MYTOKEN2
|
||||
```
|
||||
|
||||
纯 ESM 包
|
||||
----
|
||||
|
||||
### CommonJS 项目移动到 ESM
|
||||
<!--rehype:wrap-class=col-span-3-->
|
||||
|
||||
- 将 `"type": "module"` 添加到您的 [package.json](./package.json.md)
|
||||
- 将 [package.json](./package.json.md) 中的 `"main": "index.js"` 替换为 `"exports": "./index.js"`。
|
||||
- 将 [package.json](./package.json.md) 中的 `"engines"` 字段更新为 Node.js 14: `"node": ">=14.16"`。(不包括 <red>~~Node.js 12~~</red>,因为它不再受支持)
|
||||
- 删除 `"use strict"`;来自所有 JavaScript 文件
|
||||
- 将所有 `require()` / `module.export` 替换为 `import` / `export`
|
||||
- 仅使用完整的相对文件路径进行导入:`import x from '.';` → `import x from './index.js';`
|
||||
- 如果您有 `TypeScript` 类型定义(例如 `index.d.ts`),请将其更新为使用 ESM 导入/导出
|
||||
- 可选但推荐使用 `node:` 导入[协议](https://nodejs.org/api/esm.html#esm_node_imports)
|
||||
|
||||
### TypeScript 项目输出 ESM
|
||||
<!--rehype:wrap-class=col-span-3-->
|
||||
|
||||
- 确保您使用的是 TypeScript 4.7 或更高版本
|
||||
- 将 `"type": "module"` 添加到您的 [package.json](./package.json.md)
|
||||
- 将 [package.json](./package.json.md) 中的 `"main": "index.js"` 替换为 `"exports": "./index.js"`
|
||||
- 将 [package.json](./package.json.md) 中的 `"engines"` 字段更新为 Node.js 14: `"node": ">=14.16"`。 (不包括 <red>~~Node.js 12~~</red>,因为它不再受支持)
|
||||
- 将 `"module": "node16"`, `"moduleResolution": "node16"` 添加到您的 [tsconfig.json](./typescript.md) ([列子](https://github.com/sindresorhus/tsconfig/blob/main/tsconfig.json))
|
||||
- 仅使用完整的相对文件路径进行导入:`import x from '.';` → `import x from './index.js';`
|
||||
- 删除 `namespace` 使用并改用 `export`
|
||||
- 可选但推荐使用 `node:` 导入[协议](https://nodejs.org/api/esm.html#esm_node_imports)
|
||||
- **即使您正在导入 `.ts` 文件,也必须在相对导入中使用 `.js` 扩展名**
|
||||
|
||||
阅读[官方 ESM 指南](https://www.typescriptlang.org/docs/handbook/esm-node.html)
|
||||
|
||||
另见
|
||||
----
|
||||
|
||||
- [npm 仓库、网站和命令行界面的文档](https://docs.npmjs.com/) _(npmjs.com)_
|
||||
- [npmmirror 中国镜像站](https://npmmirror.com/) _(npmmirror.com)_
|
||||
- [Dev Cheatsheets npx](https://michaelcurrin.github.io/dev-cheatsheets/cheatsheets/package-managers/javascript/npm/commands/npx.html) _(michaelcurrin.github.io)_
|
||||
|
@@ -12,6 +12,8 @@ package.json 备忘清单
|
||||
|
||||
- [npm 文档](https://docs.npmjs.com/files/package.json) _(npmjs.com)_
|
||||
- [yarnpkg 文档](https://classic.yarnpkg.com/en/docs/package-json) _(yarnpkg.com)_
|
||||
- [packages 文档](https://nodejs.org/api/packages.html) _(nodejs.org)_
|
||||
- [npm 备忘清单(速查表)](./npm.md) _(jaywcjlove.github.io)_
|
||||
|
||||
### `name`
|
||||
|
||||
@@ -21,7 +23,7 @@ package.json 备忘清单
|
||||
}
|
||||
```
|
||||
|
||||
**规则**
|
||||
#### 规则
|
||||
|
||||
- 必须小于或等于214个字符(包括 `@scope/` 范围包)
|
||||
- 不能以点(`.`)或下划线(`_`)开头
|
||||
@@ -328,12 +330,100 @@ https://registry.npmjs.org/[包名]/-/[包名]-[version].tgz
|
||||
|
||||
字段由模块作者提供,作为 `JavaScript` 包或组件工具的提示,用于打包模块以供客户端使用。 提案就[在这里](https://github.com/defunctzombie/package-browser-field-spec)。
|
||||
|
||||
### `exports`
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "mod",
|
||||
"exports":{
|
||||
".": "./lib/index.js",
|
||||
"./lib/*": "./lib/*.js"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
使用最新的 `exports` 字段导出,可规避 `main` 字段局限性 [具体参考](https://nodejs.org/api/packages.html)
|
||||
|
||||
### exports 导出子路径中的模块
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "mod",
|
||||
"exports": {
|
||||
".": "./index.js",
|
||||
"./sub": "./src/sub.js"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
导入
|
||||
|
||||
```js
|
||||
import sub from "mod/sub"
|
||||
```
|
||||
|
||||
### exports 简写 (`.` 唯一的导出)
|
||||
|
||||
```json
|
||||
{
|
||||
"exports": {
|
||||
".": "./dist/index.js"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
简写
|
||||
|
||||
```json
|
||||
{
|
||||
"exports": "./dist/index.js"
|
||||
}
|
||||
```
|
||||
|
||||
### 条件导出(exports)
|
||||
<!--rehype:wrap-class=col-span-2 row-span-2-->
|
||||
|
||||
:- | -
|
||||
:- | -
|
||||
`export` | 通过 `import` 或 `import()` 或 `es` 模块加载的任何顶层导入或解析操作加载时,匹配。
|
||||
`require` | 当包通过 `require()` 加载时匹配。预期的格式包括 CommonJS、JSON 和本地插件。
|
||||
`node` | 匹配任何 `Node.js` 环境。可以是 `cjs` 或 `es` 模块文件。必须在 `import` 或 `require` 之后。
|
||||
`default` | 默认的降级条件。可以是一个 `cjs` 或 `es` 模块文件。这个条件应该总是排在最后。
|
||||
|
||||
```js
|
||||
{
|
||||
"exports": {
|
||||
".": {
|
||||
"import":"./dist/index.mjs",
|
||||
"require":"./dist/index.cjs", // 当包通过 `require()` 加载时匹配
|
||||
"node": "./dist/ployfill.js", // 匹配任何 `Node.js` 环境
|
||||
"default": "./dist/default.js" // 默认的降级条件
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<red>注意:</red>由于 `require` 和 `import` 互斥,所以 `require` 不能加载 `es` 的模块,`export` 不能加载 `cjs` 模块
|
||||
|
||||
### `main` Vs `exports`
|
||||
|
||||
```json
|
||||
{
|
||||
"main": "./index.js",
|
||||
"exports": "./index.js"
|
||||
}
|
||||
```
|
||||
|
||||
如果同时出现 <red>~~`main`~~</red> 和 `exports` 字段,只会读取 `exports` 字段
|
||||
|
||||
## 任务类字段
|
||||
|
||||
包里还可以包含一些可执行脚本或者其他配置信息。
|
||||
|
||||
### `scripts`
|
||||
|
||||
脚本是定义自动化开发相关任务的好方法,比如使用一些简单的构建过程或开发工具。 在 `scripts` 字段里定义的脚本,可以通过 `yarn run <script>` 命令来执行。 例如,下面 `build-project` 脚本可以通过 `yarn run build-project` 调用,并执行 `node build-project.js`。
|
||||
|
||||
```json
|
||||
{
|
||||
"scripts": {
|
||||
@@ -342,12 +432,14 @@ https://registry.npmjs.org/[包名]/-/[包名]-[version].tgz
|
||||
}
|
||||
```
|
||||
|
||||
脚本是定义自动化开发相关任务的好方法,比如使用一些简单的构建过程或开发工具。 在 `scripts` 字段里定义的脚本,可以通过 `yarn run <script>` 命令来执行。 例如,上述 `build-project` 脚本可以通过 `yarn run build-project` 调用,并执行 `node build-project.js`。
|
||||
|
||||
有一些特殊的脚本名称。 如果定义了 `preinstall` 脚本,它会在包安装前被调用。 出于兼容性考虑,`install`、`postinstall` 和 `prepublish` 脚本会在包完成安装后被调用。
|
||||
|
||||
----
|
||||
|
||||
`start` 脚本的默认值为 `node server.js`。
|
||||
|
||||
----
|
||||
|
||||
参考文档:[npm docs](https://docs.npmjs.com/files/package.json#default-values)
|
||||
|
||||
### 特定的 `scripts`
|
||||
@@ -355,24 +447,24 @@ https://registry.npmjs.org/[包名]/-/[包名]-[version].tgz
|
||||
|
||||
对于以下脚本,`npm` 支持 `package.json` 文件的 `scripts` 默认命令字段:
|
||||
|
||||
- `prepublish`: 在打包并发布包之前运行,以及在没有任何参数的本地 `npm` 安装之前运行。 (见下文)
|
||||
- `prepare`: 在打包和发布包之前运行,在没有任何参数的本地 `npm install` 上运行,以及安装 git 依赖项时(见下文)。 这是在 `preublish` 之后运行,但是在 `preublishOnly` 之前运行。
|
||||
- `prepublishOnly`: 在包准备和打包之前运行,仅限于npm发布。 (见下文。)
|
||||
- `prepublish`: 在打包并发布包之前运行,以及在没有任何参数的本地 `npm` 安装之前运行
|
||||
- `prepare`: 在打包和发布包之前运行,在没有任何参数的本地 `npm install` 上运行,以及安装 git 依赖项时。 这是在 `preublish` 之后运行,但是在 `preublishOnly` 之前运行
|
||||
- `prepublishOnly`: 在包准备和打包之前运行,仅限于npm发布
|
||||
- `prepack`: 在打包 `tarball` 之前运行(在 `npm pack`,`npm publish`,以及安装 git 依赖项时)
|
||||
- `postpack`: 在生成 `tarball` 之后运行并移动到其最终目标。
|
||||
- `publish`, `postpublish`: 在包发布后运行。
|
||||
- `preinstall`: 在安装软件包之前运行。
|
||||
- `install`, `postinstall`: 安装包后运行。
|
||||
- `preuninstall`, `uninstall`: 在卸载软件包之前运行。
|
||||
- `postuninstall`: 在卸载软件包之后运行。
|
||||
- `preversion`: 在改变包版本之前运行。
|
||||
- `version`: 改变包版本后运行,但提交之前。
|
||||
- `postversion`: 改变包版本后运行,然后提交。
|
||||
- `pretest`, `test`, `posttest`: 由 `npm test` 命令运行。
|
||||
- `prestop`, `stop`, `poststop`: 由 `npm stop` 命令运行。
|
||||
- `prestart`, `start`, `poststart`: 由 `npm start` 命令运行。
|
||||
- `prerestart`, `restart`, `postrestart`: 由 `npm restart` 命令运行。 注意:如果没有提供重启脚本,`npm restart` 将运行 `stop` 和`start` 脚本。
|
||||
- `preshrinkwrap`, `shrinkwrap`, `postshrinkwrap`: 由 `npm shrinkwrap` 命令运行。
|
||||
- `postpack`: 在生成 `tarball` 之后运行并移动到其最终目标
|
||||
- `publish`, `postpublish`: 在包发布后运行
|
||||
- `preinstall`: 在安装软件包之前运行
|
||||
- `install`, `postinstall`: 安装包后运行
|
||||
- `preuninstall`, `uninstall`: 在卸载软件包之前运行
|
||||
- `postuninstall`: 在卸载软件包之后运行
|
||||
- `preversion`: 在改变包版本之前运行
|
||||
- `version`: 改变包版本后运行,但提交之前
|
||||
- `postversion`: 改变包版本后运行,然后提交
|
||||
- `pretest`, `test`, `posttest`: 由 `npm test` 命令运行
|
||||
- `prestop`, `stop`, `poststop`: 由 `npm stop` 命令运行
|
||||
- `prestart`, `start`, `poststart`: 由 `npm start` 命令运行
|
||||
- `prerestart`, `restart`, `postrestart`: 由 `npm restart` 命令运行。 注意:如果没有提供重启脚本,`npm restart` 将运行 `stop` 和`start` 脚本
|
||||
- `preshrinkwrap`, `shrinkwrap`, `postshrinkwrap`: 由 `npm shrinkwrap` 命令运行
|
||||
|
||||
参考文档:[npm docs](https://docs.npmjs.com/misc/scripts).
|
||||
|
||||
@@ -577,7 +669,6 @@ https://registry.npmjs.org/[包名]/-/[包名]-[version].tgz
|
||||
|
||||
此选项指定你的包的操作系统兼容性,它会检查 `process.platform`。
|
||||
|
||||
|
||||
### `cpu`
|
||||
|
||||
```json
|
||||
@@ -624,6 +715,8 @@ Yarn
|
||||
|
||||
### `flat`
|
||||
|
||||
<!-- markdownlint-disable MD042 -->
|
||||
|
||||
如果你的包只允许给定依赖的一个版本,你想强制和命令行上 [yarn install --flat](#) 相同的行为,把这个值设为 `true`。
|
||||
|
||||
```json
|
||||
@@ -651,8 +744,11 @@ Yarn
|
||||
|
||||
注意,`yarn install --flat` 命令将会自动在 `package.json` 文件里加入 `resolutions` 字段。
|
||||
|
||||
|
||||
另见
|
||||
----
|
||||
|
||||
- [PACKAGE.JSON 中文说明](https://jaywcjlove.github.io/package.json) _(github.io)_
|
||||
- [npm 文档](https://docs.npmjs.com/files/package.json) _(npmjs.com)_
|
||||
- [yarnpkg 文档](https://classic.yarnpkg.com/en/docs/package-json) _(yarnpkg.com)_
|
||||
- [packages 文档](https://nodejs.org/api/packages.html) _(nodejs.org)_
|
||||
- [npm 备忘清单(速查表)](./npm.md) _(jaywcjlove.github.io)_
|
||||
|
972
docs/php.md
Normal file
972
docs/php.md
Normal file
@@ -0,0 +1,972 @@
|
||||
PHP 备忘清单
|
||||
===
|
||||
|
||||
这份 [PHP](https://www.php.net/manual/zh/index.php) 备忘单为快速查找最常用代码的正确语法提供了参考
|
||||
|
||||
入门
|
||||
------
|
||||
|
||||
### hello.php
|
||||
|
||||
```php
|
||||
<?php // 以 PHP 开放标签开头
|
||||
echo "Hello World\n";
|
||||
print("Hello quickref.me");
|
||||
?>
|
||||
```
|
||||
|
||||
PHP 运行命令
|
||||
|
||||
```shell
|
||||
$ php hello.php
|
||||
```
|
||||
|
||||
### 变量 Variables
|
||||
|
||||
```php
|
||||
$boolean1 = true;
|
||||
$boolean2 = True;
|
||||
$int = 12;
|
||||
$float = 3.1415926;
|
||||
unset($float); // 删除变量
|
||||
$str1 = "How are you?";
|
||||
$str2 = 'Fine, thanks';
|
||||
```
|
||||
|
||||
查看: [Types](#php-类型)
|
||||
|
||||
### 字符串 Strings
|
||||
|
||||
```php
|
||||
$url = "quickref.me";
|
||||
echo "I'm learning PHP at $url";
|
||||
// 连接字符串
|
||||
echo "I'm learning PHP at " . $url;
|
||||
$hello = "Hello, ";
|
||||
$hello .= "World!";
|
||||
echo $hello; # => Hello, World!
|
||||
```
|
||||
|
||||
查看: [Strings](#php-字符串)
|
||||
|
||||
### 数组 Arrays
|
||||
|
||||
```php
|
||||
$num = [1, 3, 5, 7, 9];
|
||||
$num[5] = 11;
|
||||
unset($num[2]); // 删除变量
|
||||
print_r($num); # => 1 3 7 9 11
|
||||
echo count($num); # => 5
|
||||
```
|
||||
|
||||
查看: [Arrays](#php-数组)
|
||||
|
||||
### 运算符 Operators
|
||||
|
||||
```php
|
||||
$x = 1;
|
||||
$y = 2;
|
||||
$sum = $x + $y;
|
||||
echo $sum; # => 3
|
||||
```
|
||||
|
||||
查看: [Operators](#php-运算符)
|
||||
|
||||
### Include
|
||||
<!--rehype:wrap-class=row-span-3-->
|
||||
|
||||
#### vars.php
|
||||
|
||||
```php
|
||||
<?php // 以 PHP 开放标签开头。
|
||||
$fruit = 'apple';
|
||||
echo "I was imported";
|
||||
return 'Anything you like.';
|
||||
?>
|
||||
```
|
||||
|
||||
#### test.php
|
||||
|
||||
```php
|
||||
<?php
|
||||
include 'vars.php';
|
||||
echo $fruit . "\n"; # => apple
|
||||
/* 与 include 相同,
|
||||
如果不能包含则导致错误*/
|
||||
require 'vars.php';
|
||||
// 也有效
|
||||
include('vars.php');
|
||||
require('vars.php');
|
||||
// 通过 HTTP 包含
|
||||
include 'http://x.com/file.php';
|
||||
// 包含和返回语句
|
||||
$result = include 'vars.php';
|
||||
echo $result; # => Anything you like.
|
||||
?>
|
||||
```
|
||||
|
||||
### 功能 Functions
|
||||
|
||||
```php
|
||||
function add($num1, $num2 = 1) {
|
||||
return $num1 + $num2;
|
||||
}
|
||||
echo add(10); # => 11
|
||||
echo add(10, 5); # => 15
|
||||
```
|
||||
|
||||
查看: [Functions](#php-函数)
|
||||
|
||||
### 注释 Comments
|
||||
|
||||
```php
|
||||
# 这是一个单行 shell 样式的注释
|
||||
// 这是一行 c++ 风格的注释
|
||||
/* 这是一个多行注释
|
||||
另一行注释 */
|
||||
```
|
||||
|
||||
### 常数 Constants
|
||||
|
||||
```php
|
||||
const MY_CONST = "hello";
|
||||
echo MY_CONST; # => hello
|
||||
|
||||
# => MY_CONST is: hello
|
||||
echo 'MY_CONST is: ' . MY_CONST;
|
||||
```
|
||||
|
||||
### 类 Classes
|
||||
|
||||
```php
|
||||
class Student {
|
||||
public function __construct($name) {
|
||||
$this->name = $name;
|
||||
}
|
||||
}
|
||||
$alex = new Student("Alex");
|
||||
```
|
||||
|
||||
查看: [Classes](#php-类)
|
||||
|
||||
PHP 类型
|
||||
------
|
||||
|
||||
### 布尔值 Boolean
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```php
|
||||
$boolean1 = true;
|
||||
$boolean2 = TRUE;
|
||||
$boolean3 = false;
|
||||
$boolean4 = FALSE;
|
||||
$boolean5 = (boolean) 1; # => true
|
||||
$boolean6 = (boolean) 0; # => false
|
||||
```
|
||||
|
||||
布尔值不区分大小写
|
||||
|
||||
### 整数 Integer
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```php
|
||||
$int1 = 28; # => 28
|
||||
$int2 = -32; # => -32
|
||||
$int3 = 012; # => 10 (octal)
|
||||
$int4 = 0x0F; # => 15 (hex)
|
||||
$int5 = 0b101; # => 5 (binary)
|
||||
# => 2000100000 (decimal, PHP 7.4.0)
|
||||
$int6 = 2_000_100_000;
|
||||
```
|
||||
|
||||
另见: [Integers](https://www.php.net/manual/en/language.types.integer.php)
|
||||
|
||||
### 字符串 Strings
|
||||
|
||||
```php
|
||||
echo 'this is a simple string';
|
||||
```
|
||||
|
||||
查看: [Strings](#php-字符串)
|
||||
|
||||
### 数组 Arrays
|
||||
|
||||
```php
|
||||
$arr = array("hello", "world", "!");
|
||||
```
|
||||
|
||||
查看: [Arrays](#php-数组)
|
||||
|
||||
### 浮点数 Float (Double)
|
||||
|
||||
```php
|
||||
$float1 = 1.234;
|
||||
$float2 = 1.2e7;
|
||||
$float3 = 7E-10;
|
||||
$float4 = 1_234.567; // as of PHP 7.4.0
|
||||
var_dump($float4); // float(1234.567)
|
||||
$float5 = 1 + "10.5"; # => 11.5
|
||||
$float6 = 1 + "-1.3e3"; # => -1299
|
||||
```
|
||||
|
||||
### Null
|
||||
|
||||
```php
|
||||
$a = null;
|
||||
$b = 'Hello php!';
|
||||
echo $a ?? 'a is unset'; # => a is unset
|
||||
echo $b ?? 'b is unset'; # => Hello php
|
||||
$a = array();
|
||||
$a == null # => true
|
||||
$a === null # => false
|
||||
is_null($a) # => false
|
||||
```
|
||||
|
||||
### 可迭代对象 Iterables
|
||||
|
||||
```php
|
||||
function bar(): iterable {
|
||||
return [1, 2, 3];
|
||||
}
|
||||
function gen(): iterable {
|
||||
yield 1;
|
||||
yield 2;
|
||||
yield 3;
|
||||
}
|
||||
foreach (bar() as $value) {
|
||||
echo $value; # => 123
|
||||
}
|
||||
```
|
||||
|
||||
PHP 字符串
|
||||
------
|
||||
|
||||
### 字符串 String
|
||||
|
||||
```php
|
||||
# => '$String'
|
||||
$sgl_quotes = '$String';
|
||||
# => 'This is a $String.'
|
||||
$dbl_quotes = "This is a $sgl_quotes.";
|
||||
# => a tab character.
|
||||
$escaped = "a \t tab character.";
|
||||
# => a slash and a t: \t
|
||||
$unescaped = 'a slash and a t: \t';
|
||||
```
|
||||
|
||||
### 多行 Multi-line
|
||||
|
||||
```php
|
||||
$str = "foo";
|
||||
// 未插值的多行
|
||||
$nowdoc = <<<'END'
|
||||
Multi line string
|
||||
$str
|
||||
END;
|
||||
// 将执行字符串插值
|
||||
$heredoc = <<<END
|
||||
Multi line
|
||||
$str
|
||||
END;
|
||||
```
|
||||
|
||||
### 操作 Manipulation
|
||||
|
||||
```php
|
||||
$s = "Hello Phper";
|
||||
echo strlen($s); # => 11
|
||||
echo substr($s, 0, 3); # => Hel
|
||||
echo substr($s, 1); # => ello Phper
|
||||
echo substr($s, -4, 3);# => hpe
|
||||
echo strtoupper($s); # => HELLO PHPER
|
||||
echo strtolower($s); # => hello phper
|
||||
echo strpos($s, "l"); # => 2
|
||||
var_dump(strpos($s, "L")); # => false
|
||||
```
|
||||
|
||||
另见: [字符串函数](https://www.php.net/manual/en/ref.strings.php)
|
||||
|
||||
PHP 数组
|
||||
------
|
||||
|
||||
### 定义
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```php
|
||||
$a1 = ["hello", "world", "!"]
|
||||
$a2 = array("hello", "world", "!");
|
||||
$a3 = explode(",", "apple,pear,peach");
|
||||
```
|
||||
|
||||
#### 混合 int 和 string 键
|
||||
|
||||
```php
|
||||
$array = array(
|
||||
"foo" => "bar",
|
||||
"bar" => "foo",
|
||||
100 => -100,
|
||||
-100 => 100,
|
||||
);
|
||||
var_dump($array);
|
||||
```
|
||||
|
||||
#### 短数组语法
|
||||
|
||||
```php
|
||||
$array = [
|
||||
"foo" => "bar",
|
||||
"bar" => "foo",
|
||||
];
|
||||
```
|
||||
|
||||
### 多阵列
|
||||
|
||||
```php
|
||||
$multiArray = [
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
[7, 8, 9],
|
||||
];
|
||||
print_r($multiArray[0][0]) # => 1
|
||||
print_r($multiArray[0][1]) # => 2
|
||||
print_r($multiArray[0][2]) # => 3
|
||||
```
|
||||
|
||||
### 多类型
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```php
|
||||
$array = array(
|
||||
"foo" => "bar",
|
||||
42 => 24,
|
||||
"multi" => array(
|
||||
"dim" => array(
|
||||
"a" => "foo"
|
||||
)
|
||||
)
|
||||
);
|
||||
# => string(3) "bar"
|
||||
var_dump($array["foo"]);
|
||||
# => int(24)
|
||||
var_dump($array[42]);
|
||||
# => string(3) "foo"
|
||||
var_dump($array["multi"]["dim"]["a"]);
|
||||
```
|
||||
|
||||
### 操作
|
||||
|
||||
```php
|
||||
$arr = array(5 => 1, 12 => 2);
|
||||
$arr[] = 56; // 附加
|
||||
$arr["x"] = 42; // 用键添加
|
||||
sort($arr); // 排序
|
||||
unset($arr[5]); // 消除
|
||||
unset($arr); // 移除所有
|
||||
```
|
||||
|
||||
查看: [数组函数](https://www.php.net/manual/en/ref.array.php)
|
||||
|
||||
### 索引迭代
|
||||
|
||||
```php
|
||||
$array = array('a', 'b', 'c');
|
||||
$count = count($array);
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
echo "i:{$i}, v:{$array[$i]}\n";
|
||||
}
|
||||
```
|
||||
|
||||
### 价值迭代
|
||||
|
||||
```php
|
||||
$colors = array('red', 'blue', 'green');
|
||||
foreach ($colors as $color) {
|
||||
echo "Do you like $color?\n";
|
||||
}
|
||||
```
|
||||
|
||||
### 关键迭代
|
||||
|
||||
```php
|
||||
$arr = ["foo" => "bar", "bar" => "foo"];
|
||||
foreach ( $arr as $key => $value )
|
||||
{
|
||||
echo "key: " . $key . "\n";
|
||||
echo "val: {$arr[$key]}\n";
|
||||
}
|
||||
```
|
||||
|
||||
### 串联阵列
|
||||
|
||||
```php
|
||||
$a = [1, 2];
|
||||
$b = [3, 4];
|
||||
// PHP 7.4 以后
|
||||
# => [1, 2, 3, 4]
|
||||
$result = [...$a, ...$b];
|
||||
```
|
||||
|
||||
### Into 函数
|
||||
|
||||
```php
|
||||
$array = [1, 2];
|
||||
function foo(int $a, int $b) {
|
||||
echo $a; # => 1
|
||||
echo $b; # => 2
|
||||
}
|
||||
foo(...$array);
|
||||
```
|
||||
|
||||
### Splat运算符
|
||||
|
||||
```php
|
||||
function foo($first, ...$other) {
|
||||
var_dump($first); # => a
|
||||
var_dump($other); # => ['b', 'c']
|
||||
}
|
||||
foo('a', 'b', 'c' /*, ...*/ );
|
||||
// 或
|
||||
function foo($first, string ...$other){}
|
||||
```
|
||||
|
||||
PHP 运算符
|
||||
-------
|
||||
|
||||
### 算术
|
||||
|
||||
:- | -
|
||||
:- | -
|
||||
`+` | 添加
|
||||
`-` | 减法
|
||||
`*` | 乘法
|
||||
`/` | 分配
|
||||
`%` | 取模
|
||||
`**` | 求幂
|
||||
|
||||
### 分配
|
||||
|
||||
:- | -
|
||||
:- | -
|
||||
`a += b` | 如同 `a = a + b`
|
||||
`a -= b` | 如同 `a = a – b`
|
||||
`a *= b` | 如同 `a = a * b`
|
||||
`a /= b` | 如同 `a = a / b`
|
||||
`a %= b` | 如同 `a = a % b`
|
||||
|
||||
### 比较
|
||||
|
||||
:- | -
|
||||
:- | -
|
||||
`==` | 平等的
|
||||
`===` | 完全相同的
|
||||
`!=` | 不相等
|
||||
`<>` | 不相等
|
||||
`!==` | 不相同
|
||||
`<` | 少于
|
||||
`>` | 比...更棒
|
||||
`<=` | 小于或等于
|
||||
`>=` | 大于或等于
|
||||
`<=>` | 小于/等于/大于
|
||||
|
||||
### 逻辑的
|
||||
|
||||
:- | -
|
||||
:- | -
|
||||
`and` | 和
|
||||
`or` | 或者
|
||||
`xor` | 独家或
|
||||
`!` | 不是
|
||||
`&&` | 和
|
||||
`\|\|` | 或者
|
||||
|
||||
### 算术
|
||||
|
||||
```php
|
||||
// 算术
|
||||
$sum = 1 + 1; // 2
|
||||
$difference = 2 - 1; // 1
|
||||
$product = 2 * 2; // 4
|
||||
$quotient = 2 / 1; // 2
|
||||
// 速记算术
|
||||
$num = 0;
|
||||
$num += 1; // 将 $num 增加 1
|
||||
echo $num++; // 打印 1(评估后的增量)
|
||||
echo ++$num; // 打印 3(评估前的增量)
|
||||
$num /= $float; // 将商除并分配给 $num
|
||||
```
|
||||
|
||||
### 按位
|
||||
|
||||
:- | -
|
||||
:- | -
|
||||
`&` | 和
|
||||
`|` | 或(包括或)
|
||||
`^` | 异或(异或)
|
||||
`~` | 不是
|
||||
`<<` | 左移
|
||||
`>>` | 右移
|
||||
|
||||
PHP 条件
|
||||
------
|
||||
|
||||
### If elseif else
|
||||
|
||||
```php
|
||||
$a = 10;
|
||||
$b = 20;
|
||||
if ($a > $b) {
|
||||
echo "a is bigger than b";
|
||||
} elseif ($a == $b) {
|
||||
echo "a is equal to b";
|
||||
} else {
|
||||
echo "a is smaller than b";
|
||||
}
|
||||
```
|
||||
|
||||
### Switch
|
||||
|
||||
```php
|
||||
$x = 0;
|
||||
switch ($x) {
|
||||
case '0':
|
||||
print "it's zero";
|
||||
break;
|
||||
case 'two':
|
||||
case 'three':
|
||||
// do something
|
||||
break;
|
||||
default:
|
||||
// do something
|
||||
}
|
||||
```
|
||||
|
||||
### 三元运算符
|
||||
|
||||
```php
|
||||
# => Does
|
||||
print (false ? 'Not' : 'Does');
|
||||
$x = false;
|
||||
# => Does
|
||||
print($x ?: 'Does');
|
||||
$a = null;
|
||||
$b = 'Does print';
|
||||
# => a is unsert
|
||||
echo $a ?? 'a is unset';
|
||||
# => print
|
||||
echo $b ?? 'b is unset';
|
||||
```
|
||||
|
||||
### 匹配
|
||||
|
||||
```php
|
||||
$statusCode = 500;
|
||||
$message = match($statusCode) {
|
||||
200, 300 => null,
|
||||
400 => '未找到',
|
||||
500 => '服务器错误',
|
||||
default => '已知状态码',
|
||||
};
|
||||
echo $message; # => 服务器错误
|
||||
```
|
||||
|
||||
查看: [Match](https://www.php.net/manual/en/control-structures.match.php)
|
||||
|
||||
### 匹配表达式
|
||||
|
||||
```php
|
||||
$age = 23;
|
||||
$result = match (true) {
|
||||
$age >= 65 => 'senior',
|
||||
$age >= 25 => 'adult',
|
||||
$age >= 18 => 'young adult',
|
||||
default => 'kid',
|
||||
};
|
||||
echo $result; # => young adult
|
||||
```
|
||||
|
||||
PHP 循环
|
||||
------
|
||||
|
||||
### while 循环
|
||||
|
||||
```php
|
||||
$i = 1;
|
||||
# => 12345
|
||||
while ($i <= 5) {
|
||||
echo $i++;
|
||||
}
|
||||
```
|
||||
|
||||
### do while 循环
|
||||
|
||||
```php
|
||||
$i = 1;
|
||||
# => 12345
|
||||
do {
|
||||
echo $i++;
|
||||
} while ($i <= 5);
|
||||
```
|
||||
|
||||
### for i 循环
|
||||
|
||||
```php
|
||||
# => 12345
|
||||
for ($i = 1; $i <= 5; $i++) {
|
||||
echo $i;
|
||||
}
|
||||
```
|
||||
|
||||
### break 跳出循环
|
||||
|
||||
```php
|
||||
# => 123
|
||||
for ($i = 1; $i <= 5; $i++) {
|
||||
if ($i === 4) {
|
||||
break;
|
||||
}
|
||||
echo $i;
|
||||
}
|
||||
```
|
||||
|
||||
### continue 继续
|
||||
|
||||
```php
|
||||
# => 1235
|
||||
for ($i = 1; $i <= 5; $i++) {
|
||||
if ($i === 4) {
|
||||
continue;
|
||||
}
|
||||
echo $i;
|
||||
}
|
||||
```
|
||||
|
||||
### foreach 循环
|
||||
|
||||
```php
|
||||
$a = ['foo' => 1, 'bar' => 2];
|
||||
# => 12
|
||||
foreach ($a as $k) {
|
||||
echo $k;
|
||||
}
|
||||
```
|
||||
|
||||
查看: [Array iteration](#关键迭代)
|
||||
|
||||
PHP 函数
|
||||
------
|
||||
|
||||
### 返回值
|
||||
|
||||
```php
|
||||
function square($x)
|
||||
{
|
||||
return $x * $x;
|
||||
}
|
||||
echo square(4); # => 16
|
||||
```
|
||||
|
||||
### 返回类型
|
||||
|
||||
```php
|
||||
// 基本返回类型声明
|
||||
function sum($a, $b): float {/*...*/}
|
||||
function get_item(): string {/*...*/}
|
||||
class C {}
|
||||
// 返回一个对象
|
||||
function getC(): C { return new C; }
|
||||
```
|
||||
|
||||
### 可空返回类型
|
||||
|
||||
```php
|
||||
// 在 PHP 7.1 中可用
|
||||
function nullOrString(int $v) : ?string
|
||||
{
|
||||
return $v % 2 ? "odd" : null;
|
||||
}
|
||||
echo nullOrString(3); # => odd
|
||||
var_dump(nullOrString(4)); # => NULL
|
||||
```
|
||||
|
||||
查看: [Nullable types](https://www.php.net/manual/en/migration71.new-features.php)
|
||||
|
||||
### 无效函数
|
||||
|
||||
```php
|
||||
// 在 PHP 7.1 中可用
|
||||
function voidFunction(): void
|
||||
{
|
||||
echo 'Hello';
|
||||
return;
|
||||
}
|
||||
voidFunction(); # => Hello
|
||||
```
|
||||
|
||||
### 变量函数
|
||||
|
||||
```php
|
||||
function bar($arg = '')
|
||||
{
|
||||
echo "In bar(); arg: '$arg'.\n";
|
||||
}
|
||||
$func = 'bar';
|
||||
$func('test'); # => In bar(); arg: test
|
||||
```
|
||||
|
||||
### 匿名函数
|
||||
|
||||
```php
|
||||
$greet = function($name)
|
||||
{
|
||||
printf("Hello %s\r\n", $name);
|
||||
};
|
||||
$greet('World'); # => Hello World
|
||||
$greet('PHP'); # => Hello PHP
|
||||
```
|
||||
|
||||
### 递归函数
|
||||
|
||||
```php
|
||||
function recursion($x)
|
||||
{
|
||||
if ($x < 5) {
|
||||
echo "$x";
|
||||
recursion($x + 1);
|
||||
}
|
||||
}
|
||||
recursion(1); # => 1234
|
||||
```
|
||||
|
||||
### 默认参数
|
||||
|
||||
```php
|
||||
function coffee($type = "cappuccino")
|
||||
{
|
||||
return "Making a cup of $type.\n";
|
||||
}
|
||||
# => 制作一杯卡布奇诺
|
||||
echo coffee();
|
||||
# => 制作一杯
|
||||
echo coffee(null);
|
||||
# => 制作一杯浓缩咖啡
|
||||
echo coffee("espresso");
|
||||
```
|
||||
|
||||
### 箭头函数
|
||||
|
||||
```php
|
||||
$y = 1;
|
||||
|
||||
$fn1 = fn($x) => $x + $y;
|
||||
// 相当于按值使用 $y:
|
||||
$fn2 = function ($x) use ($y) {
|
||||
return $x + $y;
|
||||
};
|
||||
echo $fn1(5); # => 6
|
||||
echo $fn2(5); # => 6
|
||||
```
|
||||
|
||||
PHP 类
|
||||
------
|
||||
|
||||
### 构造函数 Constructor
|
||||
|
||||
```php
|
||||
class Student {
|
||||
public function __construct($name) {
|
||||
$this->name = $name;
|
||||
}
|
||||
public function print() {
|
||||
echo "Name: " . $this->name;
|
||||
}
|
||||
}
|
||||
$alex = new Student("Alex");
|
||||
$alex->print(); # => Name: Alex
|
||||
```
|
||||
|
||||
### 继承 Inheritance
|
||||
|
||||
```php
|
||||
class ExtendClass extends SimpleClass
|
||||
{
|
||||
// 重新定义父方法
|
||||
function displayVar()
|
||||
{
|
||||
echo "Extending class\n";
|
||||
parent::displayVar();
|
||||
}
|
||||
}
|
||||
$extended = new ExtendClass();
|
||||
$extended->displayVar();
|
||||
```
|
||||
|
||||
### 类变量 Classes variables
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```php
|
||||
class MyClass
|
||||
{
|
||||
const MY_CONST = 'value';
|
||||
static $staticVar = 'static';
|
||||
// 可见度
|
||||
public static $var1 = 'pubs';
|
||||
// 仅限类
|
||||
private static $var2 = 'pris';
|
||||
// 类和子类
|
||||
protected static $var3 = 'pros';
|
||||
// 类和子类
|
||||
protected $var6 = 'pro';
|
||||
// 仅限类
|
||||
private $var7 = 'pri';
|
||||
}
|
||||
```
|
||||
|
||||
静态访问
|
||||
|
||||
```php
|
||||
echo MyClass::MY_CONST; # => value
|
||||
echo MyClass::$staticVar; # => static
|
||||
```
|
||||
|
||||
### 魔术方法
|
||||
|
||||
```php
|
||||
class MyClass
|
||||
{
|
||||
// 对象被视为字符串
|
||||
public function __toString()
|
||||
{
|
||||
return $property;
|
||||
}
|
||||
// 与 __construct() 相反
|
||||
public function __destruct()
|
||||
{
|
||||
print "Destroying";
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 接口
|
||||
|
||||
```php
|
||||
interface Foo
|
||||
{
|
||||
public function doSomething();
|
||||
}
|
||||
interface Bar
|
||||
{
|
||||
public function doSomethingElse();
|
||||
}
|
||||
class Cls implements Foo, Bar
|
||||
{
|
||||
public function doSomething() {}
|
||||
public function doSomethingElse() {}
|
||||
}
|
||||
```
|
||||
|
||||
各种各样的
|
||||
------
|
||||
|
||||
### 基本错误处理
|
||||
|
||||
```php
|
||||
try {
|
||||
// 做一点事
|
||||
} catch (Exception $e) {
|
||||
// 处理异常
|
||||
} finally {
|
||||
echo "Always print!";
|
||||
}
|
||||
```
|
||||
|
||||
### PHP 8.0 中的异常
|
||||
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
```php {.wrap}
|
||||
$nullableValue = null;
|
||||
try {
|
||||
$value = $nullableValue ?? throw new InvalidArgumentException();
|
||||
} catch (InvalidArgumentException) { // 变量是可选的
|
||||
// 处理我的异常
|
||||
echo "print me!";
|
||||
}
|
||||
```
|
||||
|
||||
### 自定义异常
|
||||
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
```php
|
||||
class MyException extends Exception {
|
||||
// 做一点事
|
||||
}
|
||||
```
|
||||
|
||||
用法
|
||||
|
||||
```php
|
||||
try {
|
||||
$condition = true;
|
||||
if ($condition) {
|
||||
throw new MyException('bala');
|
||||
}
|
||||
} catch (MyException $e) {
|
||||
// 处理我的异常
|
||||
}
|
||||
```
|
||||
|
||||
### Nullsafe 运算符
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
```php
|
||||
// 从 PHP 8.0.0 开始,这一行:
|
||||
$result = $repo?->getUser(5)?->name;
|
||||
// 相当于下面的代码:
|
||||
if (is_null($repo)) {
|
||||
$result = null;
|
||||
} else {
|
||||
$user = $repository->getUser(5);
|
||||
if (is_null($user)) {
|
||||
$result = null;
|
||||
} else {
|
||||
$result = $user->name;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
另见: [Nullsafe 运算符](https://wiki.php.net/rfc/nullsafe_operator)
|
||||
|
||||
### 常用表达
|
||||
|
||||
```php
|
||||
$str = "Visit Quickref.me";
|
||||
echo preg_match("/qu/i", $str); # => 1
|
||||
```
|
||||
|
||||
查看: [PHP中的正则表达式](./regex.md#php中的正则表达式)
|
||||
|
||||
### fopen() 模式
|
||||
|
||||
:- | -
|
||||
:- | -
|
||||
`r` | 读
|
||||
`r+` | 读写,前置
|
||||
`w` | 写入,截断
|
||||
`w+` | 读写,截断
|
||||
`a` | 写,追加
|
||||
`a+` | 读写,追加
|
||||
|
||||
### 运行时定义的常量
|
||||
|
||||
```php
|
||||
define("CURRENT_DATE", date('Y-m-d'));
|
||||
// 一种可能的表示
|
||||
echo CURRENT_DATE; # => 2021-01-05
|
||||
# => CURRENT_DATE is: 2021-01-05
|
||||
echo 'CURRENT_DATE is: ' . CURRENT_DATE;
|
||||
```
|
||||
|
||||
另见
|
||||
----
|
||||
|
||||
- [PHP 官方中文文档](https://www.php.net/manual/zh/index.php) _(php.net)_
|
||||
- [Learn X in Y minutes](https://learnxinyminutes.com/docs/php/) _(learnxinyminutes.com)_
|
629
docs/postgres.md
Normal file
629
docs/postgres.md
Normal file
@@ -0,0 +1,629 @@
|
||||
PostgreSQL 备忘清单
|
||||
===
|
||||
|
||||
[PostgreSQL](https://www.postgresql.org/docs/current/) 备忘清单为您提供了常用的 PostgreSQL 命令和语句。
|
||||
|
||||
入门
|
||||
---------------
|
||||
|
||||
### 入门
|
||||
|
||||
切换和连接
|
||||
|
||||
```shell
|
||||
$ sudo -u postgres psql
|
||||
```
|
||||
|
||||
列出所有数据库
|
||||
|
||||
```shell
|
||||
postgres=# \l
|
||||
```
|
||||
|
||||
连接到名为 postgres 的数据库
|
||||
|
||||
```shell
|
||||
postgres=# \c postgres
|
||||
```
|
||||
|
||||
断开
|
||||
|
||||
```shell
|
||||
postgres=# \q
|
||||
postgres=# \!
|
||||
```
|
||||
|
||||
### psql 命令
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
参数 | 示例 | 说明
|
||||
:- |- | -
|
||||
`[-d] <database>` | psql -d mydb | 连接到数据库
|
||||
`-U` | psql -U john mydb | 以特定用户身份连接
|
||||
`-h` `-p` | psql -h localhost -p 5432 mydb | 连接到主机/端口
|
||||
`-U` `-h` `-p` `-d` | psql -U admin -h 192.168.1.5 -p 2506 -d mydb | 连接远程 PostgreSQL
|
||||
`-W` | psql -W mydb | 强制密码
|
||||
`-c` | psql -c '\c postgres' -c '\dt' | 执行 SQL 查询或命令
|
||||
`-H` | psql -c "\l+" -H postgres > database.html | 生成 HTML 报告
|
||||
`-l` | psql -l | 列出所有数据库
|
||||
`-f` | psql mydb -f file.sql | 从文件执行命令
|
||||
`-V` | psql -V | 打印 psql 版本
|
||||
<!--rehype:className=show-header-->
|
||||
|
||||
### 获得帮助
|
||||
|
||||
:- | -
|
||||
:- | -
|
||||
`\h` | SQL 命令语法帮助
|
||||
`\h` DELETE | DELETE SQL 语句语法
|
||||
`\?` | PostgreSQL 命令列表
|
||||
|
||||
在 PostgreSQL 控制台中运行
|
||||
|
||||
PostgreSQL 工作
|
||||
-------
|
||||
|
||||
### Recon 观察
|
||||
|
||||
显示版本
|
||||
|
||||
```sql
|
||||
SHOW SERVER_VERSION;
|
||||
```
|
||||
|
||||
显示系统状态
|
||||
|
||||
```sql
|
||||
\conninfo
|
||||
```
|
||||
|
||||
显示环境变量
|
||||
|
||||
```sql
|
||||
SHOW ALL;
|
||||
```
|
||||
|
||||
列出用户
|
||||
|
||||
```sql
|
||||
SELECT rolname FROM pg_roles;
|
||||
```
|
||||
|
||||
显示当前用户
|
||||
|
||||
```sql
|
||||
SELECT current_user;
|
||||
```
|
||||
|
||||
显示当前用户的权限
|
||||
|
||||
```sql
|
||||
\du
|
||||
```
|
||||
|
||||
显示当前数据库
|
||||
|
||||
```sql
|
||||
SELECT current_database();
|
||||
```
|
||||
|
||||
显示数据库中的所有表
|
||||
|
||||
```sql
|
||||
\dt
|
||||
```
|
||||
|
||||
列出函数
|
||||
|
||||
```sql
|
||||
\df <schema>
|
||||
```
|
||||
|
||||
### Databases 数据库
|
||||
|
||||
列出数据库
|
||||
|
||||
```sql
|
||||
\l
|
||||
```
|
||||
|
||||
连接到数据库
|
||||
|
||||
```sql
|
||||
\c <database_name>
|
||||
```
|
||||
|
||||
显示当前数据库
|
||||
|
||||
```sql
|
||||
SELECT current_database();
|
||||
```
|
||||
|
||||
[创建数据库](http://www.postgresql.org/docs/current/static/sql-createdatabase.html)
|
||||
|
||||
```sql
|
||||
CREATE DATABASE <database_name> WITH OWNER <username>;
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
[删除数据库](http://www.postgresql.org/docs/current/static/sql-dropdatabase.html)
|
||||
|
||||
```sql
|
||||
DROP DATABASE IF EXISTS <database_name>;
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
[重命名数据库](http://www.postgresql.org/docs/current/static/sql-alterdatabase.html)
|
||||
|
||||
```sql
|
||||
ALTER DATABASE <old_name> RENAME TO <new_name>;
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### Tables 表
|
||||
|
||||
列出当前数据库中的表
|
||||
|
||||
```sql
|
||||
\dt
|
||||
SELECT table_schema,table_name FROM information_schema.tables ORDER BY table_schema,table_name;
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
全局列表
|
||||
|
||||
```sql
|
||||
\dt *.*.
|
||||
SELECT * FROM pg_catalog.pg_tables
|
||||
```
|
||||
|
||||
列表表架构
|
||||
|
||||
```sql
|
||||
\d <table_name>
|
||||
\d+ <table_name>
|
||||
SELECT column_name, data_type, character_maximum_length
|
||||
FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE table_name = '<table_name>';
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
[创建表](http://www.postgresql.org/docs/current/static/sql-createtable.html)
|
||||
|
||||
```sql
|
||||
CREATE TABLE <table_name>(
|
||||
<column_name> <column_type>,
|
||||
<column_name> <column_type>
|
||||
);
|
||||
```
|
||||
|
||||
创建表,主键自增
|
||||
|
||||
```sql
|
||||
CREATE TABLE <table_name> (
|
||||
<column_name> SERIAL PRIMARY KEY
|
||||
);
|
||||
```
|
||||
|
||||
[删除表](http://www.postgresql.org/docs/current/static/sql-droptable.html)
|
||||
|
||||
```sql
|
||||
DROP TABLE IF EXISTS <table_name> CASCADE;
|
||||
```
|
||||
|
||||
### Permissions 权限
|
||||
|
||||
成为 postgres 用户,如果您有权限错误
|
||||
|
||||
```shell
|
||||
sudo su - postgres
|
||||
psql
|
||||
```
|
||||
|
||||
[授予](http://www.postgresql.org/docs/current/static/sql-grant.html) 对数据库的所有权限
|
||||
|
||||
```sql
|
||||
GRANT ALL PRIVILEGES ON DATABASE <db_name> TO <user_name>;
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
授予数据库连接权限
|
||||
|
||||
```sql
|
||||
GRANT CONNECT ON DATABASE <db_name> TO <user_name>;
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
授予架构权限
|
||||
|
||||
```sql
|
||||
GRANT USAGE ON SCHEMA public TO <user_name>;
|
||||
```
|
||||
|
||||
授予函数权限
|
||||
|
||||
```sql
|
||||
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO <user_name>;
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
授予在所有表上选择、更新、插入、删除的权限
|
||||
|
||||
```sql
|
||||
GRANT SELECT, UPDATE, INSERT ON ALL TABLES IN SCHEMA public TO <user_name>;
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
在表上授予权限
|
||||
|
||||
```sql
|
||||
GRANT SELECT, UPDATE, INSERT ON <table_name> TO <user_name>;
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
授予对表的选择权限
|
||||
|
||||
```sql
|
||||
GRANT SELECT ON ALL TABLES IN SCHEMA public TO <user_name>;
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### Columns 列
|
||||
|
||||
[添加栏目](http://www.postgresql.org/docs/current/static/sql-altertable.html)
|
||||
|
||||
```sql
|
||||
ALTER TABLE <table_name> IF EXISTS
|
||||
ADD <column_name> <data_type> [<constraints>];
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
更新栏
|
||||
|
||||
```sql
|
||||
ALTER TABLE <table_name> IF EXISTS
|
||||
ALTER <column_name> TYPE <data_type> [<constraints>];
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
删除列
|
||||
|
||||
```sql
|
||||
ALTER TABLE <table_name> IF EXISTS
|
||||
DROP <column_name>;
|
||||
```
|
||||
|
||||
将列更新为自增主键
|
||||
|
||||
```sql
|
||||
ALTER TABLE <table_name>
|
||||
ADD COLUMN <column_name> SERIAL PRIMARY KEY;
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
使用自动递增的主键插入表中
|
||||
|
||||
```sql
|
||||
INSERT INTO <table_name>
|
||||
VALUES (DEFAULT, <value1>);
|
||||
INSERT INTO <table_name> (<column1_name>,<column2_name>)
|
||||
VALUES ( <value1>,<value2> );
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### Data 数据
|
||||
|
||||
[选择](http://www.postgresql.org/docs/current/static/sql-select.html) 所有数据
|
||||
|
||||
```sql
|
||||
SELECT * FROM <table_name>;
|
||||
```
|
||||
|
||||
读取一行数据
|
||||
|
||||
```sql
|
||||
SELECT * FROM <table_name> LIMIT 1;
|
||||
```
|
||||
|
||||
搜索数据
|
||||
|
||||
```sql
|
||||
SELECT * FROM <table_name> WHERE <column_name> = <value>;
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
[插入](http://www.postgresql.org/docs/current/static/sql-insert.html) 数据
|
||||
|
||||
```sql
|
||||
INSERT INTO <table_name> VALUES( <value_1>, <value_2> );
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
[更新](http://www.postgresql.org/docs/current/static/sql-update.html) 数据
|
||||
|
||||
```sql
|
||||
UPDATE <table_name>
|
||||
SET <column_1> = <value_1>, <column_2> = <value_2>
|
||||
WHERE <column_1> = <value>;
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
[删除](http://www.postgresql.org/docs/current/static/sql-delete.html) 所有数据
|
||||
|
||||
```sql
|
||||
DELETE FROM <table_name>;
|
||||
```
|
||||
|
||||
删除特定数据
|
||||
|
||||
```sql
|
||||
DELETE FROM <table_name>
|
||||
WHERE <column_name> = <value>;
|
||||
```
|
||||
|
||||
### Users 用户
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
列出角色
|
||||
|
||||
```sql
|
||||
SELECT rolname FROM pg_roles;
|
||||
```
|
||||
|
||||
[创建用户](http://www.postgresql.org/docs/current/static/sql-createuser.html)
|
||||
|
||||
```sql
|
||||
CREATE USER <user_name> WITH PASSWORD '<password>';
|
||||
```
|
||||
|
||||
[删除用户](http://www.postgresql.org/docs/current/static/sql-dropuser.html)
|
||||
|
||||
```sql
|
||||
DROP USER IF EXISTS <user_name>;
|
||||
```
|
||||
|
||||
[更改](http://www.postgresql.org/docs/current/static/sql-alterrole.html) 用户密码
|
||||
|
||||
```sql
|
||||
ALTER ROLE <user_name> WITH PASSWORD '<password>';
|
||||
```
|
||||
|
||||
### Schema
|
||||
|
||||
列出 Schemas
|
||||
|
||||
```sql
|
||||
\dn
|
||||
SELECT schema_name FROM information_schema.schemata;
|
||||
SELECT nspname FROM pg_catalog.pg_namespace;
|
||||
```
|
||||
|
||||
[创建架构](http://www.postgresql.org/docs/current/static/sql-createschema.html)
|
||||
|
||||
```sql
|
||||
CREATE SCHEMA IF NOT EXISTS <schema_name>;
|
||||
```
|
||||
|
||||
[删除模式](http://www.postgresql.org/docs/current/static/sql-dropschema.html)
|
||||
|
||||
```sql
|
||||
DROP SCHEMA IF EXISTS <schema_name> CASCADE;
|
||||
```
|
||||
|
||||
PostgreSQL 命令
|
||||
-----------
|
||||
|
||||
### 表
|
||||
|
||||
:- | -
|
||||
:- | -
|
||||
`\d <table>` | 描述表
|
||||
`\d+ <table>` | 详细描述表格
|
||||
`\dt` | 列出当前模式中的表
|
||||
`\dt *.*` | 列出所有模式中的表
|
||||
`\dt <schema>.*` | 列出架构的表
|
||||
`\dp` | 列出表访问权限
|
||||
`\det[+]` | 列出外部表
|
||||
|
||||
### 查询缓冲区
|
||||
|
||||
:- | -
|
||||
:- | -
|
||||
`\e [FILE]` | 编辑查询缓冲区(或文件)
|
||||
`\ef [FUNC]` | 编辑函数定义
|
||||
`\p` | 显示内容
|
||||
`\r` | 重置(清除)查询缓冲区
|
||||
`\s [FILE]` | 显示历史记录或保存到文件
|
||||
`\w FILE` | 将查询缓冲区写入文件
|
||||
|
||||
### 信息
|
||||
<!--rehype:wrap-class=row-span-4-->
|
||||
|
||||
:- | -
|
||||
:- | -
|
||||
`\l[+]` | 列出所有数据库
|
||||
`\dn[S+]` | 列出架构
|
||||
`\di[S+]` | 列出索引
|
||||
`\du[+]` | 列出角色
|
||||
`\ds[S+]` | 列出序列
|
||||
`\df[antw][S+]` | 列出函数
|
||||
`\deu[+]` | 列出用户映射
|
||||
`\dv[S+]` | 列表视图
|
||||
`\dl` | 列出大对象
|
||||
`\dT[S+]` | 列出数据类型
|
||||
`\da[S]` | 列出聚合
|
||||
`\db[+]` | 列出表空间
|
||||
`\dc[S+]` | 列出转化
|
||||
`\dC[+]` | 列出演员表
|
||||
`\ddp` | 列出默认权限
|
||||
`\dd[S]` | 显示对象描述
|
||||
`\dD[S+]` | 列出域
|
||||
`\des[+]` | 列出国外服务器
|
||||
`\dew[+]` | 列出外部数据包装器
|
||||
`\dF[+]` | 列出文本搜索配置
|
||||
`\dFd[+]` | 列出文本搜索词典
|
||||
`\dFp[+]` | 列出文本搜索解析器
|
||||
`\dFt[+]` | 列出文本搜索模板
|
||||
`\dL[S+]` | 列出程序语言
|
||||
`\do[S]` | 列出运算符
|
||||
`\dO[S+]` | 列出排序规则
|
||||
`\drds` | 列出每个数据库的角色设置
|
||||
`\dx[+]` | 列出扩展
|
||||
|
||||
`S`:显示系统对象,`+`:附加细节
|
||||
|
||||
### 连接
|
||||
|
||||
:- | -
|
||||
:- | -
|
||||
`\c [DBNAME]` | 连接到新数据库
|
||||
`\encoding [ENCODING]` | 显示或设置客户端编码
|
||||
`\password [USER]` | 更改密码
|
||||
`\conninfo` | 显示信息
|
||||
|
||||
### 格式化
|
||||
|
||||
:- | -
|
||||
:- | -
|
||||
`\a` | 在未对齐和对齐之间切换
|
||||
`\C [STRING]` | 设置表格标题,如果没有则取消设置
|
||||
`\f [STRING]` | 显示或设置未对齐的字段分隔符
|
||||
`\H` | 切换 HTML 输出模式
|
||||
`\t [on\|off]` | 仅显示行
|
||||
`\T [STRING]` | 设置或取消设置 HTML \<table\> 标签属性
|
||||
`\x [on\|off]` | 切换扩展输出
|
||||
|
||||
### 输入输出
|
||||
|
||||
:- | -
|
||||
:- | -
|
||||
`\copy ...` | 导入/导出表 _另见:_ [复制](#导入导出-csv)
|
||||
`\echo [STRING]` | 打印字符串
|
||||
`\i FILE` | 执行文件
|
||||
`\o [FILE]` | 将所有结果导出到文件
|
||||
`\qecho [STRING]` | 输出流的字符串
|
||||
|
||||
### 变量
|
||||
|
||||
:- | -
|
||||
:- | -
|
||||
`\prompt [TEXT] NAME` | 设置变量
|
||||
`\set [NAME [VALUE]]` | 设置变量 _(如果没有参数,则列出所有变量)_
|
||||
`\unset NAME` | 删除变量
|
||||
|
||||
### 杂项
|
||||
|
||||
:- | -
|
||||
:- | -
|
||||
`\cd [DIR]` | 更改目录
|
||||
`\timing [on\|off]` | 切换时间
|
||||
`\! [COMMAND]` | 在shell中执行
|
||||
`\! ls -l` | 在shell中列出所有
|
||||
|
||||
### 大对象
|
||||
|
||||
- `\lo_export LOBOID FILE`
|
||||
- `\lo_import FILE [COMMENT]`
|
||||
- `\lo_list`
|
||||
- `\lo_unlink LOBOID`
|
||||
|
||||
各种各样的
|
||||
-------------
|
||||
|
||||
### 备份
|
||||
|
||||
使用 pg_dumpall 备份所有数据库
|
||||
|
||||
```shell
|
||||
$ pg_dumpall -U postgres > all.sql
|
||||
```
|
||||
|
||||
使用 pg_dump 备份数据库
|
||||
|
||||
```shell
|
||||
$ pg_dump -d mydb -f mydb_backup.sql
|
||||
```
|
||||
|
||||
- `-a` 只转储数据,而不是模式(schema)
|
||||
- `-s` 只转储模式,不转储数据
|
||||
- `-c` 在重新创建之前删除数据库
|
||||
- `-C` 还原前创建数据库
|
||||
- `-t` 仅转储命名表
|
||||
- `-F` 格式(`c`:自定义,`d`:目录,`t`:tar)
|
||||
<!--rehype:className=style-none-->
|
||||
|
||||
使用 `pg_dump -?` 获取完整的选项列表
|
||||
|
||||
### 恢复
|
||||
|
||||
使用 psql 恢复数据库
|
||||
|
||||
```shell
|
||||
$ psql -U user mydb < mydb_backup.sql
|
||||
```
|
||||
|
||||
使用 pg_restore 恢复数据库
|
||||
|
||||
```shell
|
||||
$ pg_restore -d mydb mydb_backup.sql -c
|
||||
```
|
||||
|
||||
- `-U` 指定数据库用户
|
||||
- `-c` 在重新创建之前删除数据库
|
||||
- `-C` 还原前创建数据库
|
||||
- `-e` 如果遇到错误退出
|
||||
- `-F` 格式(`c`:自定义,`d`:目录,`t`:tar,`p`:纯文本sql(默认))
|
||||
<!--rehype:className=style-none-->
|
||||
|
||||
使用 `pg_restore -?` 获取完整的选项列表
|
||||
|
||||
### 远程访问
|
||||
|
||||
获取 postgresql.conf 的位置
|
||||
|
||||
```shell
|
||||
$ psql -U postgres -c 'SHOW config_file'
|
||||
```
|
||||
|
||||
附加到 postgresql.conf
|
||||
|
||||
```shell
|
||||
listen_addresses = '*'
|
||||
```
|
||||
|
||||
附加到 pg_hba.conf(与 postgresql.conf 相同的位置)
|
||||
|
||||
```shell
|
||||
host all all 0.0.0.0/0 md5
|
||||
host all all ::/0 md5
|
||||
```
|
||||
|
||||
重启 PostgreSQL 服务器
|
||||
|
||||
```shell
|
||||
$ sudo systemctl restart postgresql
|
||||
```
|
||||
|
||||
### 导入/导出 CSV
|
||||
|
||||
将表格导出为 CSV 文件
|
||||
|
||||
```sql
|
||||
\copy table TO '<path>' CSV
|
||||
\copy table(col1,col1) TO '<path>' CSV
|
||||
\copy (SELECT...) TO '<path>' CSV
|
||||
```
|
||||
|
||||
将 CSV 文件导入表格
|
||||
|
||||
```sql
|
||||
\copy table FROM '<path>' CSV
|
||||
\copy table(col1,col1) FROM '<path>' CSV
|
||||
```
|
||||
|
||||
另见:[复制](https://www.postgresql.org/docs/current/sql-copy.html)
|
||||
|
||||
另见
|
||||
----
|
||||
|
||||
- [Posgres-cheatsheet](https://gist.github.com/apolloclark/ea5466d5929e63043dcf#posgres-cheatsheet) _(gist.github.com)_
|
@@ -57,6 +57,7 @@ llo
|
||||
查看: [Strings](#python-字符串)
|
||||
|
||||
### Lists
|
||||
|
||||
```python
|
||||
mylist = []
|
||||
mylist.append(1)
|
||||
@@ -67,7 +68,6 @@ for item in mylist:
|
||||
|
||||
查看: [Lists](#python-lists)
|
||||
|
||||
|
||||
### If Else
|
||||
|
||||
```python
|
||||
@@ -77,6 +77,7 @@ if num > 0:
|
||||
else:
|
||||
print("num is not greater than 0")
|
||||
```
|
||||
|
||||
查看: [流程控制](#python-流程控制)
|
||||
|
||||
### 循环
|
||||
@@ -88,8 +89,8 @@ for item in range(6):
|
||||
else:
|
||||
print("Finally finished!")
|
||||
```
|
||||
查看: [Loops](#python-循环)
|
||||
|
||||
查看: [Loops](#python-循环)
|
||||
|
||||
### 函数
|
||||
|
||||
@@ -101,7 +102,7 @@ else:
|
||||
来自函数的你好
|
||||
```
|
||||
|
||||
查看: [Functions](#python-functions)
|
||||
查看: [Functions](#函数)
|
||||
|
||||
### 文件处理
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
@@ -151,7 +152,7 @@ message += "Part 2."
|
||||
'10 + 10 = 20'
|
||||
```
|
||||
|
||||
查看: [Python F-Strings](#python-f-strings-since-python)
|
||||
查看: [Python F-Strings](#f-字符串(Python 3.6+))
|
||||
|
||||
Python 数据类型
|
||||
---------------
|
||||
@@ -165,6 +166,7 @@ multi_string = """Multiline Strings
|
||||
Lorem ipsum dolor sit amet,
|
||||
consectetur adipiscing elit """
|
||||
```
|
||||
|
||||
查看: [Strings](#python-字符串)
|
||||
|
||||
### 数字
|
||||
@@ -194,8 +196,8 @@ list2 = [True, False, False]
|
||||
list3 = [1, 5, 7, 9, 3]
|
||||
list4 = list((1, 5, 7, 9, 3))
|
||||
```
|
||||
查看: [Lists](#python-lists)
|
||||
|
||||
查看: [Lists](#python-lists)
|
||||
|
||||
### 元组 Tuple
|
||||
|
||||
@@ -334,7 +336,7 @@ o
|
||||
'baco'
|
||||
```
|
||||
|
||||
#### 迈着大步
|
||||
#### 步长
|
||||
|
||||
```python
|
||||
>>> s = '12345' * 5
|
||||
@@ -361,6 +363,7 @@ o
|
||||
`len()` 函数返回字符串的长度
|
||||
|
||||
### 多份
|
||||
|
||||
```python
|
||||
>>> s = '===+'
|
||||
>>> n = 8
|
||||
@@ -396,7 +399,9 @@ True
|
||||
name = "John"
|
||||
print("Hello, %s!" % name)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```python
|
||||
name = "John"
|
||||
age = 23
|
||||
@@ -948,6 +953,7 @@ with open("myfile.txt") as file:
|
||||
for line in file:
|
||||
print(line)
|
||||
```
|
||||
|
||||
#### 带行号
|
||||
|
||||
```python
|
||||
@@ -956,7 +962,6 @@ for i, line in enumerate(file, start=1):
|
||||
print("Number %s: %s" % (i, line))
|
||||
```
|
||||
|
||||
|
||||
### 字符串
|
||||
|
||||
#### 写一个字符串
|
||||
@@ -1083,6 +1088,7 @@ class ChildClass(ParentClass):
|
||||
# 调用父级的 print_test()
|
||||
super().print_test()
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```python
|
||||
@@ -1172,7 +1178,8 @@ Yoki.sound() # => Woof!
|
||||
```python
|
||||
# 这是单行注释
|
||||
```
|
||||
----------
|
||||
|
||||
---
|
||||
|
||||
```python
|
||||
""" 可以写多行字符串
|
||||
@@ -1180,7 +1187,9 @@ Yoki.sound() # => Woof!
|
||||
作为文档。
|
||||
"""
|
||||
```
|
||||
----------
|
||||
|
||||
---
|
||||
|
||||
```python
|
||||
''' 可以写多行字符串
|
||||
使用三个',并且经常使用
|
||||
@@ -1215,7 +1224,7 @@ try:
|
||||
# 使用“raise”来引发错误
|
||||
raise IndexError("这是一个索引错误")
|
||||
except IndexError as e:
|
||||
pass # 通行证只是一个空操作。 通常你会在这里做恢复。
|
||||
pass # pass只是一个空操作。 通常你会在这里做恢复。
|
||||
except (TypeError, NameError):
|
||||
pass # 如果需要,可以一起处理多个异常。
|
||||
else: # try/except 块的可选子句。 必须遵循除块之外的所有内容
|
||||
@@ -1223,3 +1232,10 @@ else: # try/except 块的可选子句。 必须遵循除块
|
||||
finally: # 在所有情况下执行
|
||||
print("我们可以在这里清理资源")
|
||||
```
|
||||
|
||||
另见
|
||||
----
|
||||
|
||||
- [Python](https://www.python.org/) _(python.org)_
|
||||
- [Learn X in Y minutes](https://learnxinyminutes.com/docs/python/) _(learnxinyminutes.com)_
|
||||
- [Regex in python](./regex.md#python-中的正则表达式) _(quickref.me)_
|
||||
|
@@ -8,7 +8,7 @@ Quick Reference 备忘清单
|
||||
|
||||
### 本地编译预览
|
||||
|
||||
简单的将仓库克隆下来本地调试页面展示。
|
||||
将仓库克隆到本地调试页面。请参阅[贡献指南](https://github.com/jaywcjlove/reference/blob/main/CONTRIBUTING.md)了解如何开始
|
||||
|
||||
#### 克隆仓库
|
||||
|
||||
@@ -22,12 +22,101 @@ git clone git@github.com:jaywcjlove/reference.git
|
||||
```shell
|
||||
npm i # 安装依赖
|
||||
npm run build # 编译输出 HTML
|
||||
npm run start # 监听 md 文件编译输出 HTML
|
||||
```
|
||||
|
||||
HTML 存放在仓库根目录下的 `dist` 目录中,将 `dist/index.html` 静态页面在浏览器中打开预览。
|
||||
|
||||
```shell
|
||||
npm run start # 监听 md 文件编译输出 HTML
|
||||
```
|
||||
|
||||
### 目录结构
|
||||
|
||||
```bash
|
||||
.
|
||||
├── CONTRIBUTING.md # 贡献说明
|
||||
├── Dockerfile
|
||||
├── LICENSE
|
||||
├── README.md # Home(首页) 内容
|
||||
├── dist # 编译后的静态资源目录
|
||||
├── docs # Markdown 文档(速查表)
|
||||
│ ├── bash.md
|
||||
│ ├── ....
|
||||
│ └── yaml.md
|
||||
├── package.json
|
||||
└── scripts # MD 转 HTML 的编译脚本
|
||||
├── assets # LOGO 图标文件资源
|
||||
├── ....
|
||||
└── watch.mjs
|
||||
```
|
||||
|
||||
### 添加一个备忘清单
|
||||
|
||||
一个简单的备忘清单包含 `页面大标题<h1>`,放在大标题下面的 `介绍` 文本,`<h2>` 分类标题,`<h3>` 内容为 `卡片`
|
||||
|
||||
```markdown
|
||||
备忘清单 (页面大标题)
|
||||
===
|
||||
|
||||
这是您可以在当前清单上使用的样式参考!备忘清单介绍
|
||||
|
||||
入门 (分类标题)
|
||||
---
|
||||
|
||||
### 介绍 (卡片)
|
||||
|
||||
卡片内容
|
||||
```
|
||||
|
||||
上面 markdown 内容存放到 `docs` 目录中,命名为 `xxx.md`
|
||||
|
||||
### 首页导航
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
首页(`README.md`)存放在仓库的根目录,通过这个 `README.md` 自动生成首页导航,下面是导航实例:
|
||||
|
||||
```markdown
|
||||
## Linux 命令
|
||||
|
||||
[Cron](./docs/cron.md)<!--rehype:style=background: rgb(239 68 68/var(\-\-bg\-opacity));-->
|
||||
<!--rehype:class=home-card-->
|
||||
```
|
||||
|
||||
首页导航图标存放在 `scripts/assets` 目录中,如果你的备忘清单定义为 `docs/cron.md`,那么你的图标就定义为 `cron.svg` 存放到 `scripts/assets` 目录中,重新编译首页当行菜单就拥有了图标。
|
||||
|
||||
- 图标存放在 [`scripts/assets`](https://github.com/jaywcjlove/reference/blob/main/scripts/assets) 目录中
|
||||
- 图片名称与清单名称保持一致 `cron.md` -> `cron.svg` (注意大小写)
|
||||
- SVG 图标尺寸 `<svg height="1em" width="1em"`
|
||||
- SVG 图标颜色使用继承颜色值 `<svg fill="currentColor"`
|
||||
- 使用 `<!--rehype:class=home-card-->` 标识卡片样式
|
||||
|
||||
### 首页提示配置
|
||||
|
||||
```markdown
|
||||
[Django](./docs/djiango.md)<!--rehype:style=background: rgb(12 75 51/var(\-\-bg\-opacity));&class=contributing-->
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
添加 `contributing` 类名,会在卡片下方默认添加 `👆待完善需要您的参与`
|
||||
|
||||
```markdown
|
||||
class=tag&data-info=👆看看还缺点儿什么?
|
||||
```
|
||||
|
||||
上面示例将默认提示更改为: `👆看看还缺点儿什么?`
|
||||
|
||||
```markdown
|
||||
[Django](./docs/djiango.md)<!--rehype:style=background: rgb(12 75 51/var(\-\-bg\-opacity));&class=tag&data-lang=Python-->
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
添加 `class=tag&data-lang=Python` 类名和参数,会在卡片右上角标记 _`Python`_
|
||||
|
||||
Markdown 语法注释
|
||||
---
|
||||
|
||||
### 介绍
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
在备忘清单采用 `HTML 注释语法`,标识网站布局和一些样式,目的是为了在 `GitHub` 中也是正常毫无瑕疵的预览 [`Markdown`](./markdown.md)。
|
||||
|
||||
@@ -40,10 +129,10 @@ HTML 存放在仓库根目录下的 `dist` 目录中,将 `dist/index.html` 静
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
使用 `col-span-2` 类标识,卡片占 `2` 列位置
|
||||
上面基础示例,使用 `col-span-2` 类标识,卡片占 `2` 列位置,参考现有备忘清单的源代码是一个好习惯!
|
||||
|
||||
### 注释语法介绍
|
||||
<!--rehype:wrap-class=row-span-3&style=color:black;background-color: #d7a100;-->
|
||||
<!--rehype:wrap-class=row-span-4&style=color:black;background-color: #d7a100;-->
|
||||
|
||||
- 在某个 [`Markdown`](./markdown.md) 语法下方或者后面,添加 HTML注释
|
||||
- 以 `<!--rehype:` 开始,`-->` 结束,包裹参数内容
|
||||
@@ -57,7 +146,7 @@ HTML 存放在仓库根目录下的 `dist` 目录中,将 `dist/index.html` 静
|
||||
#### 示例
|
||||
|
||||
```markdown
|
||||
### H2 部分
|
||||
## H2 部分
|
||||
<!--rehype:body-class=cols-2-->
|
||||
|
||||
### H3 部分
|
||||
@@ -111,7 +200,6 @@ function () {}
|
||||
|
||||
如果代码块内容太长,使用强制换行类(`wrap-text`)解决
|
||||
|
||||
|
||||
### 展示表格表头
|
||||
|
||||
```markdown
|
||||
@@ -150,11 +238,11 @@ export const Student = (
|
||||
添加注释配置 `<!--rehype:tooltips-->` 添加一个 Tooltips 提示。
|
||||
|
||||
### H3 部分(卡片)背景颜色
|
||||
<!--rehype:wrap-style=background: #00c69357;-->
|
||||
<!--rehype:wrap-style=background: #8dffd42e;-->
|
||||
|
||||
```markdown
|
||||
### H3 部分(卡片)背景颜色
|
||||
<!--rehype:wrap-style=background: #00c69357;-->
|
||||
<!--rehype:wrap-style=background: #8dffd42e;-->
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
@@ -209,41 +297,12 @@ const school = <div>学校</div>;
|
||||
:- | -
|
||||
:- | -
|
||||
`<yel>` | <yel>黄色</yel>
|
||||
`<red>` | <yel>红色</yel>
|
||||
`<pur>` | <pur>紫色</pur>
|
||||
`<code>` 或 <code>\`\`</code> | <code>绿</code>`色`
|
||||
`<del>` 或 `~~删除~~` | <del>~~红色~~</del>
|
||||
<!--rehype:className=shortcuts-->
|
||||
|
||||
### 注释类配置
|
||||
<!--rehype:wrap-class=col-span-2 row-span-2-->
|
||||
|
||||
类 | 说明
|
||||
---- | ----
|
||||
`<!--rehype:className=wrap-text-->` | 强制换行
|
||||
`<!--rehype:className=show-header-->` | 展示表格表头
|
||||
`<!--rehype:className=shortcuts-->` | 快捷键样式
|
||||
`<!--rehype:className=auto-wrap-->` | 隐藏表头强制小尺寸自动换行
|
||||
`<!--rehype:className=style-list-arrow-->` | 列表箭头样式展示表格
|
||||
`<!--rehype:className=style-list-->` | 列表样式展示表格
|
||||
`<!--rehype:className=left-align-->` | 表格末尾列左对齐
|
||||
`<!--rehype:className=style-none-->` | \<li> 没有标记
|
||||
`<!--rehype:className=style-timeline-->` | 时间轴样式
|
||||
`<!--rehype:className=style-arrow-->` | 箭头标记
|
||||
|
||||
|
||||
### 隐藏卡片标题
|
||||
<!--rehype:style=display:none;&wrap-style=padding-top: 0;-->
|
||||
|
||||
```
|
||||
隐藏卡片标题,在 H3 标题下面添加注释样式
|
||||
```
|
||||
|
||||
```markdown {2}
|
||||
### 隐藏卡片标题
|
||||
<!--rehype:style=display:none;&wrap-style=padding-top: 0;-->
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### HTML 代码预览
|
||||
|
||||
```
|
||||
@@ -260,6 +319,35 @@ const school = <div>学校</div>;
|
||||
|
||||
上面的 [`markdown`](./markdown.md) 代码在 `meta` 位置添加 `preview` 标识,[HTML](./html.md) 代码将被执行预览
|
||||
|
||||
### 隐藏卡片标题
|
||||
<!--rehype:style=display:none;&wrap-style=padding-top: 0;-->
|
||||
|
||||
```
|
||||
隐藏卡片标题,在 H3 标题下面添加注释样式
|
||||
```
|
||||
|
||||
```markdown {2}
|
||||
### 隐藏卡片标题
|
||||
<!--rehype:style=display:none;&wrap-style=padding-top: 0;-->
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
### 注释类配置
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
类 | 说明
|
||||
---- | ----
|
||||
`<!--rehype:className=wrap-text-->` | 强制`换行`
|
||||
`<!--rehype:className=show-header-->` | 展示表格`表头`
|
||||
`<!--rehype:className=shortcuts-->` | `快捷键`样式
|
||||
`<!--rehype:className=auto-wrap-->` | 隐藏表头强制小尺寸`自动换行`
|
||||
`<!--rehype:className=style-list-arrow-->` | 列表`箭头`样式展示表格
|
||||
`<!--rehype:className=style-list-->` | `列表`样式展示表格
|
||||
`<!--rehype:className=left-align-->` | 表格末尾列`左对齐`
|
||||
`<!--rehype:className=style-none-->` | \<li> 没有标记样式
|
||||
`<!--rehype:className=style-timeline-->` | `时间轴`样式
|
||||
`<!--rehype:className=style-arrow-->` | `箭头`标记
|
||||
|
||||
### KaTeX 数学渲染
|
||||
|
||||
```KaTeX
|
||||
@@ -582,7 +670,6 @@ H2 部分
|
||||
|
||||
在 `Title 1` 标题添加 `col-span-2` 和 `row-span-2` 占位类,使用 `空格` 间隔。
|
||||
|
||||
|
||||
表格
|
||||
---
|
||||
|
||||
@@ -699,14 +786,19 @@ H2 部分
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
- **重命名为 new_name**
|
||||
|
||||
```bash
|
||||
$ git branch -m <new_name>
|
||||
```
|
||||
|
||||
- 推送和**重置**
|
||||
|
||||
```bash
|
||||
$ git push origin -u <new_name>
|
||||
```
|
||||
|
||||
- 删除远程分支
|
||||
|
||||
```bash
|
||||
$ git push origin --delete <old>
|
||||
```
|
||||
|
@@ -3,7 +3,6 @@ React 备忘清单
|
||||
|
||||
适合初学者的综合 React 备忘清单。
|
||||
|
||||
|
||||
入门
|
||||
----
|
||||
|
||||
@@ -59,7 +58,6 @@ import World, { Hello } from './hello.js';
|
||||
|
||||
使用 `import` 导入 `Hello` 组件,在示例中使用。
|
||||
|
||||
|
||||
### React 组件中的 CSS
|
||||
|
||||
```jsx {2,5}
|
||||
@@ -82,7 +80,6 @@ export const Student = (
|
||||
);
|
||||
```
|
||||
|
||||
|
||||
### 属性
|
||||
|
||||
```jsx
|
||||
@@ -112,7 +109,6 @@ class Student extends React.Component {
|
||||
|
||||
`class` 组件使用 `this.props` 访问传递给组件的属性。
|
||||
|
||||
|
||||
### Children
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
@@ -138,7 +134,7 @@ function AlertBox(props) {
|
||||
}
|
||||
```
|
||||
|
||||
----
|
||||
-----
|
||||
|
||||
```jsx
|
||||
{props.children}
|
||||
@@ -158,7 +154,7 @@ class AlertBox extends React.Component {
|
||||
}
|
||||
```
|
||||
|
||||
----
|
||||
-----
|
||||
|
||||
```jsx
|
||||
{this.props.children}
|
||||
@@ -297,7 +293,7 @@ function Student() {
|
||||
|
||||
### Portals
|
||||
|
||||
React 并*没有*创建一个新的 `div`。它只是把子元素渲染到 `domNode` 中。`domNode` 是一个可以在任何位置的有效 DOM 节点。
|
||||
React 并_没有_创建一个新的 `div`。它只是把子元素渲染到 `domNode` 中。`domNode` 是一个可以在任何位置的有效 DOM 节点。
|
||||
|
||||
```jsx
|
||||
render() {
|
||||
@@ -438,7 +434,7 @@ function CustomTextInput(props) {
|
||||
</div>
|
||||
```
|
||||
|
||||
----
|
||||
-----
|
||||
|
||||
- [识别不安全的生命周期](https://zh-hans.reactjs.org/docs/strict-mode.html#identifying-unsafe-lifecycles)
|
||||
- [关于使用过时字符串 ref API 的警告](https://zh-hans.reactjs.org/docs/strict-mode.html#warning-about-legacy-string-ref-api-usage)
|
||||
@@ -754,7 +750,7 @@ export default function Weather(props) {
|
||||
}
|
||||
```
|
||||
|
||||
----
|
||||
-----
|
||||
|
||||
```js
|
||||
{isShow && <div>内容</div>}
|
||||
@@ -860,7 +856,6 @@ class Welcome extends React.Component {
|
||||
`this.props` | 组件接受参数
|
||||
`this.state` | 组件内状态
|
||||
|
||||
|
||||
### Pure 组件
|
||||
|
||||
```jsx
|
||||
@@ -1003,7 +998,7 @@ Menu.Item = ({ children }) => (
|
||||
);
|
||||
```
|
||||
|
||||
----
|
||||
-----
|
||||
|
||||
```jsx
|
||||
<Menu>
|
||||
@@ -1330,7 +1325,7 @@ PropTypes 属性类型检查
|
||||
import PropTypes from 'prop-types'
|
||||
```
|
||||
|
||||
----
|
||||
-----
|
||||
|
||||
:- | -
|
||||
:- | -
|
||||
@@ -1354,7 +1349,6 @@ import PropTypes from 'prop-types'
|
||||
`oneOf(any)` | 枚举类型
|
||||
`oneOfType([type])` | 几种类型中的任意一个类型
|
||||
|
||||
|
||||
#### _数组 Array_
|
||||
|
||||
:- | -
|
||||
|
@@ -33,7 +33,6 @@ RegEX 备忘清单
|
||||
`[a-zA-Z]` | 范围内的字符:<br>`a-z` 或 `A-Z`
|
||||
`[a-zA-Z0-9]` | 范围内的字符:<br>`a-z`、`A-Z` 或 `0-9`
|
||||
|
||||
|
||||
### 量词
|
||||
|
||||
范例 | 说明
|
||||
@@ -115,7 +114,6 @@ RegEX 备忘清单
|
||||
`[\b]` | 退格字符
|
||||
`\` | 使任何字符文字
|
||||
|
||||
|
||||
### 锚点
|
||||
|
||||
范例 | 说明
|
||||
@@ -129,7 +127,6 @@ RegEX 备忘清单
|
||||
`\b` | 一个词的边界
|
||||
`\B` | 非单词边界
|
||||
|
||||
|
||||
### 替代
|
||||
|
||||
范例 | 说明
|
||||
@@ -285,7 +282,6 @@ RegEX 备忘清单
|
||||
|
||||
使用 `\` 搜索这些特殊字符:<br> `[ \ ^ $ . | ? * + ( ) { }`
|
||||
|
||||
|
||||
### 速记类
|
||||
|
||||
范例 | 说明
|
||||
@@ -355,7 +351,6 @@ RegEX 备忘清单
|
||||
`^[A-Z]` | 字符串必须以大写字母开头
|
||||
`[\.!?"')]$` | 字符串必须以终端标点结尾
|
||||
|
||||
|
||||
### 修饰
|
||||
|
||||
范例 | 说明
|
||||
@@ -421,7 +416,6 @@ RegEX 备忘清单
|
||||
`\b\w{3}(?<!pre)\w*?\b` | 不以“pre”开头的词
|
||||
`\b\w+(?<!ing)\b` | 匹配不以“ing”结尾的单词
|
||||
|
||||
|
||||
### If-then-else
|
||||
|
||||
匹配 `Mr.` 或 `Ms.` 如果单词 `her` 稍后在字符串中
|
||||
@@ -458,7 +452,7 @@ M(?(?=.*?\bher\b)s|r)\.
|
||||
|
||||
表达式 | 匹配示例
|
||||
:- | -
|
||||
`.ar` | The `car` `par`ked in the `gar`age.
|
||||
`.ar` | The `car` <pur>`par`</pur>ked in the `gar`age.
|
||||
`ar[.]` | A garage is a good place to park a c`ar`.
|
||||
<!--rehype:className=show-header-->
|
||||
|
||||
@@ -480,7 +474,7 @@ M(?(?=.*?\bher\b)s|r)\.
|
||||
|
||||
表达式 | 匹配示例
|
||||
:- | -
|
||||
`[a-z]*` | T`he` `car` `parked` `in` `the` `garage` #21.
|
||||
`[a-z]*` | T`he` <pur>`car`</pur> `parked` <pur>`in`</pur> `the` <pur>`garage`</pur> #21.
|
||||
`\s*cat\s*` | The fat `cat` sat on the con`cat`enation.
|
||||
|
||||
表达式 `[a-z]*` 匹配一个行中所有以小写字母开头的字符串。
|
||||
@@ -509,7 +503,7 @@ M(?(?=.*?\bher\b)s|r)\.
|
||||
`[0-9]{2,3}` | The number was 9.`999`7 but we rounded it off to `10`.0.
|
||||
`[0-9]{2,}` | The number was 9.`9997` but we rounded it off to `10`.0.
|
||||
`[0-9]{3}` | The number was 9.`999`7 but we rounded it off to 10.0.
|
||||
<!--rehype:className=show-header-->
|
||||
<!--rehype:className=style-list-arrow-->
|
||||
|
||||
### `(...)` 特征标群
|
||||
|
||||
@@ -622,7 +616,7 @@ M(?(?=.*?\bher\b)s|r)\.
|
||||
表达式 | 匹配示例
|
||||
:- | -
|
||||
`The` | The `fat` cat sat on the mat.
|
||||
`/The/gi` | The `fat` `cat` `sat` on the `mat`.
|
||||
`/The/gi` | `The` fat cat sat on `the` mat.
|
||||
<!--rehype:className=show-header-->
|
||||
|
||||
修饰语 `i` 用于忽略大小写,`g` 表示全局搜索。
|
||||
@@ -664,7 +658,6 @@ Python 中的正则表达式
|
||||
import re
|
||||
```
|
||||
|
||||
|
||||
### 实例
|
||||
<!--rehype:wrap-class=col-span-2 row-span-3-->
|
||||
|
||||
@@ -729,18 +722,15 @@ False
|
||||
函数 | 说明
|
||||
:-|-
|
||||
`re.findall` | 返回包含所有匹配项的列表
|
||||
`re.finditer` | 返回一个可迭代的匹配对象(每个匹配一个)
|
||||
`re.finditer` | 返回一个可迭代的匹配对象<br/> _(每个匹配一个)_
|
||||
`re.search` | 如果字符串中的任何位置存在匹配项,则返回 Match 对象
|
||||
`re.split` | 返回一个列表,其中字符串在每次匹配时被拆分
|
||||
`re.sub` | 用字符串替换一个或多个匹配项
|
||||
`re.compile` | 编译正则表达式模式供以后使用
|
||||
`re.escape` | 返回所有非字母数字反斜杠的字符串
|
||||
|
||||
|
||||
|
||||
### Flags 标志
|
||||
|
||||
|
||||
:- | - | -
|
||||
:- | - | -
|
||||
`re.I` | `re.IGNORECASE` | 忽略大小写
|
||||
@@ -750,8 +740,6 @@ False
|
||||
`re.U` | `re.UNICODE` | 使 `\w`、`\b`、`\d`、`\s` _unicode 依赖_
|
||||
`re.X` | `re.VERBOSE` | 可读风格
|
||||
|
||||
|
||||
|
||||
JavaScript 中的正则表达式
|
||||
---------------
|
||||
|
||||
@@ -894,14 +882,12 @@ text.replaceAll(regex, "mangoes");
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
|
||||
PHP中的正则表达式
|
||||
------------
|
||||
|
||||
### 函数
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
|
||||
:- | -
|
||||
:- | -
|
||||
`preg_match()` | 执行正则表达式匹配
|
||||
@@ -911,7 +897,6 @@ PHP中的正则表达式
|
||||
`preg_split()` | 按正则表达式模式拆分字符串
|
||||
`preg_grep()` | 返回与模式匹配的数组条目
|
||||
|
||||
|
||||
### preg_replace
|
||||
|
||||
```php
|
||||
@@ -923,7 +908,6 @@ echo preg_replace($regex, "QuickRef", $str);
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
|
||||
### preg_match
|
||||
|
||||
```php
|
||||
@@ -933,7 +917,6 @@ $regex = "#quickref#i";
|
||||
echo preg_match($regex, $str);
|
||||
```
|
||||
|
||||
|
||||
### preg_matchall
|
||||
<!--rehype:wrap-class=col-span-2 row-span-2-->
|
||||
|
||||
@@ -952,7 +935,6 @@ if (preg_match_all($regex, $input_str, $matches_out)) {
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### preg_grep
|
||||
|
||||
```php
|
||||
@@ -962,7 +944,6 @@ $regex = "/Jane/";
|
||||
echo preg_grep($regex, $arr);
|
||||
```
|
||||
|
||||
|
||||
### preg_split
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
@@ -973,7 +954,6 @@ $regex = "@\s@";
|
||||
print_r(preg_split($regex, $str));
|
||||
```
|
||||
|
||||
|
||||
Java 中的正则表达式
|
||||
-------------
|
||||
|
||||
@@ -1003,10 +983,8 @@ boolean s3 = Pattern.matches(".s", "XXXX");
|
||||
System.out.println(s3); // Outputs: false
|
||||
```
|
||||
|
||||
|
||||
### 模式字段
|
||||
|
||||
|
||||
:- | -
|
||||
:- | -
|
||||
`CANON_EQ` | 规范等价
|
||||
@@ -1017,7 +995,6 @@ System.out.println(s3); // Outputs: false
|
||||
`UNICODE_CASE` | Unicode 感知大小写折叠
|
||||
`UNIX_LINES` | Unix 行模式
|
||||
|
||||
|
||||
### 方法
|
||||
|
||||
#### Pattern
|
||||
@@ -1043,7 +1020,6 @@ System.out.println(s3); // Outputs: false
|
||||
|
||||
还有更多方法...
|
||||
|
||||
|
||||
### 例子
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
@@ -1073,7 +1049,6 @@ while (m.find()) {
|
||||
System.out.println(matches);
|
||||
```
|
||||
|
||||
|
||||
MySQL中的正则表达式
|
||||
-------------
|
||||
<!--rehype:body-class=cols-2-->
|
||||
@@ -1088,9 +1063,8 @@ MySQL中的正则表达式
|
||||
`REGEXP_REPLACE()` | 替换匹配正则表达式的子字符串 <br>_(注意:仅限 MySQL 8.0+)_
|
||||
`REGEXP_SUBSTR()` | 返回匹配正则表达式的子字符串 <br>_(注意:仅 MySQL 8.0+)_
|
||||
|
||||
|
||||
|
||||
### REGEXP
|
||||
|
||||
```sql
|
||||
expr REGEXP pat
|
||||
```
|
||||
@@ -1107,7 +1081,6 @@ mysql> SELECT 'a' REGEXP 'A', 'a' REGEXP BINARY 'A';
|
||||
1 0
|
||||
```
|
||||
|
||||
|
||||
### REGEXP_REPLACE
|
||||
|
||||
```
|
||||
@@ -1123,7 +1096,6 @@ mysql> SELECT REGEXP_REPLACE('abc ghi', '[a-z]+', 'X', 1, 2);
|
||||
abc X
|
||||
```
|
||||
|
||||
|
||||
### REGEXP_SUBSTR
|
||||
|
||||
```
|
||||
@@ -1139,7 +1111,6 @@ mysql> SELECT REGEXP_SUBSTR('abc def ghi', '[a-z]+', 1, 3);
|
||||
ghi
|
||||
```
|
||||
|
||||
|
||||
### REGEXP_LIKE
|
||||
|
||||
```
|
||||
@@ -1161,7 +1132,6 @@ mysql> SELECT regexp_like('a\nb\nc', '^b$', 'm');
|
||||
1
|
||||
```
|
||||
|
||||
|
||||
### REGEXP_INSTR
|
||||
|
||||
```
|
||||
|
@@ -133,7 +133,6 @@ Resolutions 备忘清单
|
||||
| Xiaomi Redmi Note 8 Pro (2019) | 6.53 <sub>inch</sub> | 1080 x 2340 <sub>px</sub> | 393 x 851 <sub>px</sub> | 395 <sub>ppi</sub> | 144 <sub>ppi</sub> | 2.75 <sub>xxhdpi</sub> | Android 9.0 |
|
||||
<!--rehype:className=show-header-->
|
||||
|
||||
|
||||
### 平板
|
||||
<!--rehype:wrap-class=col-span-3-->
|
||||
|
||||
@@ -159,7 +158,6 @@ Resolutions 备忘清单
|
||||
| Google Pixel C (2015) | 10.2 <sub>inch</sub> | 2560x1800 <sub>px</sub> | 1280 x 900 <sub>px</sub> | 308 <sub>ppi</sub> | 154 <sub>ppi</sub> | 2 <sub>xhdpi</sub> | Android 6.0.1 |
|
||||
<!--rehype:className=show-header-->
|
||||
|
||||
|
||||
### 笔记本电脑
|
||||
<!--rehype:wrap-class=col-span-3-->
|
||||
|
||||
|
2452
docs/ruby.md
Normal file
2452
docs/ruby.md
Normal file
File diff suppressed because it is too large
Load Diff
880
docs/rust.md
880
docs/rust.md
File diff suppressed because it is too large
Load Diff
@@ -156,7 +156,6 @@ h1 {
|
||||
Sass 混合(Mixins)
|
||||
------
|
||||
|
||||
|
||||
### 参数
|
||||
|
||||
```scss
|
||||
@@ -264,7 +263,7 @@ green($color)
|
||||
blue($color)
|
||||
```
|
||||
|
||||
---
|
||||
----
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
|
@@ -30,7 +30,6 @@ $ screen -ls
|
||||
$ screen -r <name/pid>
|
||||
```
|
||||
|
||||
|
||||
### 选项
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
@@ -45,7 +44,6 @@ $ screen -r <name/pid>
|
||||
`-X` | screen -X -S debug kill | 终止正在运行的会话
|
||||
<!--rehype:className=show-header-->
|
||||
|
||||
|
||||
### 进入
|
||||
|
||||
Command | Description
|
||||
@@ -108,7 +106,6 @@ Command | Description
|
||||
`Ctrl-A` `H` | 在屏幕会话中启用日志记录
|
||||
<!--rehype:className=shortcuts-->
|
||||
|
||||
|
||||
### 分屏
|
||||
|
||||
Command | Description
|
||||
@@ -121,7 +118,6 @@ Command | Description
|
||||
`Ctrl-A` `Q` | 删除除当前区域之外的所有区域
|
||||
<!--rehype:className=shortcuts-->
|
||||
|
||||
|
||||
### 滚动
|
||||
|
||||
Command | Description
|
||||
|
@@ -109,7 +109,6 @@ $ sed 's/old/new/[flags]' [input-file]
|
||||
| `I` | 搜索时忽略大小写 |
|
||||
| `e` | 在命令行中替换并执行 |
|
||||
|
||||
|
||||
### 循环命令
|
||||
|
||||
| Command | Description |
|
||||
|
@@ -142,7 +142,6 @@ Semver 备忘清单
|
||||
1.1.2-prerelease+meta
|
||||
```
|
||||
|
||||
|
||||
另见
|
||||
----
|
||||
|
||||
|
@@ -22,7 +22,6 @@ Sketch 备忘清单
|
||||
| `t` | (Text) 文本 |
|
||||
<!--rehype:className=shortcuts-->
|
||||
|
||||
|
||||
### 类型
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
@@ -131,7 +130,6 @@ Sketch 备忘清单
|
||||
| `Fn + ↓` | 选择下面的页面 |
|
||||
<!--rehype:className=shortcuts-->
|
||||
|
||||
|
||||
另见
|
||||
----
|
||||
|
||||
|
@@ -99,7 +99,6 @@ $ scp user@server:/dir/* .
|
||||
`~/.ssh/known_hosts` | 登录主机
|
||||
`~/.ssh/authorized_keys` | 授权登录密钥
|
||||
|
||||
|
||||
### SCP 选项
|
||||
|
||||
选项 | 说明
|
||||
@@ -111,7 +110,6 @@ scp `-P` 8080 | 使用特定端口
|
||||
scp `-B` | 批处理模式_(防止密码)_
|
||||
scp `-p` | 保留时间和模式
|
||||
|
||||
|
||||
### 配置示例
|
||||
|
||||
```toml
|
||||
@@ -148,7 +146,6 @@ $ ssh -J user@proxy_host1:port1,user@proxy_host2:port2 user@remote_host3
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
|
||||
### ssh-copy-id
|
||||
|
||||
```shell
|
||||
@@ -229,7 +226,6 @@ $ ssh-keygen -p -f ~/.ssh/id_rsa
|
||||
- dsa
|
||||
- ecdsa
|
||||
|
||||
|
||||
### known_hosts
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
|
@@ -3,7 +3,6 @@ styled-components 备忘清单
|
||||
|
||||
此快速参考备忘单提供了使用 CSS in JS 工具的各种方法。
|
||||
|
||||
|
||||
入门
|
||||
----
|
||||
|
||||
@@ -29,6 +28,7 @@ import styled from 'styled-components';
|
||||
```
|
||||
|
||||
创建一个 Title 组件
|
||||
|
||||
```jsx
|
||||
// 该组件将呈现具有样式的 <h1> 标签
|
||||
const Title = styled.h1`
|
||||
@@ -236,7 +236,6 @@ const Demo = () => (
|
||||
);
|
||||
```
|
||||
|
||||
|
||||
### 样式对象
|
||||
|
||||
```jsx {2,5}
|
||||
|
@@ -84,6 +84,7 @@ h5 {
|
||||
}
|
||||
```
|
||||
|
||||
<!-- markdownlint-disable MD051 -->
|
||||
另见:下面[Mixins](#混合-Mixins)
|
||||
|
||||
### 变量 Variables
|
||||
@@ -388,6 +389,7 @@ for i in 1..3
|
||||
.text-{i}
|
||||
font-size: lookup('font-size-' + i)
|
||||
```
|
||||
|
||||
### 定义检查
|
||||
|
||||
```stylus {1}
|
||||
|
@@ -444,7 +444,7 @@ switch num {
|
||||
// 打印: 7 奇数
|
||||
```
|
||||
|
||||
### 逻辑运算符!
|
||||
### 逻辑运算符
|
||||
|
||||
```swift
|
||||
!true // false
|
||||
@@ -480,6 +480,7 @@ false || false // false
|
||||
```swift
|
||||
false || true && false // false
|
||||
```
|
||||
|
||||
`true && false` 首先计算返回 `false` 然后,表达式,`false` || `false` 评估并返回最终结果 `false`
|
||||
|
||||
### 控制执行顺序
|
||||
|
@@ -53,7 +53,7 @@ struct AlbumDetail: View {
|
||||
- [Picker](#picker-选择控件) _(UISegmentedControl)_
|
||||
- [Stepper](#stepper-执行语义递增和递减操作的控件) _(UIStepper)_
|
||||
- [DatePicker](#datepicker-日期控件) _(UIDatePicker)_
|
||||
- [Text](#text-文本) _(NSAttributedString)无等效项)_
|
||||
- [Text](#text) _(NSAttributedString)无等效项)_
|
||||
- [Map](#map-地图界面的视图) _(MapKit)_
|
||||
- [ProgressView](#progressview-进度视图) _(UIProgressView)_
|
||||
- [Shape](#shape) / [Rectangle](#shape) / [Circle](#shape)
|
||||
@@ -230,7 +230,6 @@ Map(coordinateRegion: $region,
|
||||
|
||||
文档 - [Map](https://developer.apple.com/documentation/mapkit/map)
|
||||
|
||||
|
||||
Layout(布局)
|
||||
----
|
||||
|
||||
@@ -620,7 +619,6 @@ DatePicker("Maximum Date", selection: $selectedDate,
|
||||
|
||||
文档 - [DatePicker](https://developer.apple.com/documentation/swiftui/datepicker)
|
||||
|
||||
|
||||
### Slider 滑动输入条
|
||||
|
||||
用于从值的有界线性范围中选择一个值的控件。
|
||||
@@ -673,6 +671,7 @@ NavigationView {
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
您可以使用 `.pickerStyle(WheelPickerStyle())` 覆盖样式。
|
||||
|
||||
```swift
|
||||
@@ -1200,7 +1199,6 @@ struct SheetDetail: Identifiable {
|
||||
|
||||
文档 - [ActionSheet](https://developer.apple.com/documentation/swiftui/actionsheet)
|
||||
|
||||
|
||||
另见
|
||||
---
|
||||
|
||||
|
110
docs/systemd.md
Normal file
110
docs/systemd.md
Normal file
@@ -0,0 +1,110 @@
|
||||
Systemd
|
||||
===
|
||||
|
||||
最常用的 [Systemd](https://systemd.io/) 命令备忘单快速参考
|
||||
|
||||
命令
|
||||
----
|
||||
|
||||
### 查看系统信息
|
||||
|
||||
:- | -
|
||||
:- | -
|
||||
`systemctl list-dependencies` | 显示单元的依赖关系
|
||||
`systemctl list-sockets` | 列出套接字和激活的内容
|
||||
`systemctl list-jobs` | 查看活动的 systemd 作业
|
||||
`systemctl list-unit-files` | 查看单元文件及其状态
|
||||
`systemctl list-units` | 显示单位是否已加载/活动
|
||||
`systemctl get-default` | 列出默认目标(如运行级别)
|
||||
<!--rehype:className=style-list-->
|
||||
|
||||
### 改变系统状态
|
||||
|
||||
:- | -
|
||||
:- | -
|
||||
`systemctl reboot` | 重启系统(reboot.target)
|
||||
`systemctl poweroff` | 关闭系统(poweroff.target)
|
||||
`systemctl emergency` | 进入紧急模式(emergency.target)
|
||||
`systemctl default` | 返回默认目标(multi-user.target)
|
||||
<!--rehype:className=style-list-->
|
||||
|
||||
### 使用服务
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
:- | -
|
||||
:- | -
|
||||
`systemctl stop service` | <red>停止</red>正在运行的服务
|
||||
`systemctl start service` | 启动服务
|
||||
`systemctl restart service` | 重新启动正在运行的服务
|
||||
`systemctl reload service` | 重新加载服务中的所有配置文件
|
||||
`systemctl daemon-reload` | 必须运行以重新加载更改的单元文件
|
||||
`systemctl status` | service 查看服务是否正在运行/启用
|
||||
`systemctl --failed` | 显示未能运行的服务
|
||||
`systemctl reset-failed` | 将任何单位从失败状态重置
|
||||
`systemctl enable service` | 使服务在启动时启动
|
||||
`systemctl disable service` | 禁用服务 - 不会在启动时启动
|
||||
`systemctl show service` | 显示服务(或其他单元)的属性
|
||||
`systemctl edit service` | 创建片段以放入单元文件
|
||||
`systemctl edit --full service` | 编辑整个单元文件以进行服务
|
||||
`systemctl -H host status network` | 远程运行任何 systemctl 命令
|
||||
<!--rehype:className=style-list-->
|
||||
|
||||
### 查看日志消息
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
:- | -
|
||||
:- | -
|
||||
`journalctl` | 显示所有收集的日志消息
|
||||
`journalctl -u network.service` | 查看网络服务消息
|
||||
`journalctl -f` | 关注出现的消息
|
||||
`journalctl -k` | 仅显示内核消息
|
||||
|
||||
### SysVinit 到 Systemd
|
||||
<!--rehype:wrap-class=col-span-3-->
|
||||
|
||||
SysVinit | Systemd | 说明
|
||||
:- | - | -
|
||||
`service SERVICE_NAME start` | `systemctl start SERVICE_NAME` | 用于启动服务(不重启持久)
|
||||
`service SERVICE_NAME stop` | `systemctl stop SERVICE_NAME` | 用于停止服务(不永久重启)
|
||||
`service SERVICE_NAME restart` | `systemctl restart SERVICE_NAME` | 用于停止然后启动服务
|
||||
`service SERVICE_NAME reload` | `systemctl reload SERVICE_NAME` | 重新加载配置文件而不中断挂起的操作
|
||||
`service SERVICE_NAME condrestart` | `systemctl condrestart SERVICE_NAME` | 如果服务已在运行,则重新启动
|
||||
`service SERVICE_NAME status` | `systemctl status SERVICE_NAME` | 判断服务当前是否正在运行
|
||||
`chkconfig SERVICE_NAME on` | `systemctl enable SERVICE_NAME` | 打开服务,以便在下次启动时启动,或其他触发器
|
||||
`chkconfig SERVICE_NAME off` | `systemctl disable SERVICE_NAME` | 为下次重新启动或任何其他触发器关闭服务
|
||||
`chkconfig SERVICE_NAME` | `systemctl is-enabled SERVICE_NAME` | 用于检查服务是否配置为在当前环境中启动
|
||||
`chkconfig –list` | `systemctl list-unit-files –type=service` (or) <br/>`ls /etc/systemd/system/*.wants/` | 打印一个服务表,列出每个配置的运行级别打开或关闭
|
||||
`chkconfig –list \| grep 5:on` | `systemctl list-dependencies graphical.target` | 打印启动到图形模式时将启动的服务表
|
||||
`chkconfig SERVICE_NAME –list` | `ls /etc/systemd/system/*.wants/SERVICE_NAME.service` | 用于列出此服务配置为打开或关闭的级别
|
||||
`chkconfig SERVICE_NAME –add` | `systemctl daemon-reload` | 在创建新服务文件或修改任何配置时使用
|
||||
<!--rehype:className=show-header-->
|
||||
|
||||
### 目标运行级别
|
||||
<!--rehype:wrap-class=col-span-3-->
|
||||
|
||||
SysVinit | Systemd | 说明
|
||||
:- | - | -
|
||||
`0` | `runlevel0.target`, `poweroff.target` | 停止系统
|
||||
`1`, `s`, `single` | `runlevel1.target`, `rescue.target` | 单用户模式
|
||||
`2`, `4` | `runlevel2.target`, `runlevel4.target`, `multi-user.target` | 用户定义/站点特定的运行级别。 默认情况下,与 3 相同
|
||||
`3` | `runlevel3.target`, `multi-user.target` | 多用户,非图形。 用户通常可以通过多个控制台或通过网络登录
|
||||
`5` | `runlevel5.target`, `graphical.target` | 多用户,图形。 通常具有运行级别 3 的所有服务以及图形登录
|
||||
`6` | `runlevel6.target`, `reboot.target` | 重启
|
||||
`emergency` | `emergency.target` | 应急外壳
|
||||
<!--rehype:className=show-header-->
|
||||
|
||||
### 更改运行级别
|
||||
<!--rehype:wrap-class=col-span-3-->
|
||||
|
||||
SysVinit | Systemd | 说明
|
||||
:- | - | -
|
||||
`telinit 3` | `systemctl isolate multi-user.target` <br/>OR `systemctl isolate runlevel3.target`<br/>OR `telinit 3` | 更改为多用户运行级别
|
||||
`sed s/^id:.*:initdefault:/id:3:initdefault:/` | `ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target` | 设置为在下次重新启动时使用多用户运行级别
|
||||
<!--rehype:className=show-header-->
|
||||
|
||||
另见
|
||||
---
|
||||
|
||||
- [Systemd 官网](https://systemd.io/) _(systemd.io)_
|
||||
- [Systemd Cheat Sheet](https://access.redhat.com/sites/default/files/attachments/12052018_systemd_6.pdf) _(access.redhat.com)_
|
||||
- [Systemd Cheat Sheet](https://www.linuxtrainingacademy.com/systemd-cheat-sheet/) _(linuxtrainingacademy.com)_
|
243
docs/tmux.md
Normal file
243
docs/tmux.md
Normal file
@@ -0,0 +1,243 @@
|
||||
Tmux 备忘清单
|
||||
===
|
||||
|
||||
最常用的快捷键和命令的 tmux 备忘单快速参考
|
||||
|
||||
Tmux CLI
|
||||
-------
|
||||
|
||||
### 新会话
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
开始一个新的会话
|
||||
|
||||
```bash
|
||||
$ tmux
|
||||
$ tmux new
|
||||
$ tmux new-session
|
||||
|
||||
:new
|
||||
```
|
||||
|
||||
开始一个名为 myname 的新会话
|
||||
|
||||
```bash
|
||||
$ tmux new -s myname
|
||||
|
||||
:new -s myname
|
||||
```
|
||||
|
||||
显示所有会话,或者 <kbd>Ctrl</kbd> + <kbd>b</kbd> + <kbd>s</kbd> 快捷键
|
||||
|
||||
```bash
|
||||
$ tmux ls
|
||||
$ tmux list-sessions
|
||||
```
|
||||
|
||||
### 附加会话
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
附加到上一个会话
|
||||
|
||||
```bash
|
||||
$ tmux a
|
||||
$ tmux at
|
||||
$ tmux attach
|
||||
$ tmux attach-session
|
||||
```
|
||||
|
||||
附加到命名
|
||||
|
||||
```bash
|
||||
$ tmux a -t myname
|
||||
```
|
||||
|
||||
附加到名为 myname 的会话
|
||||
|
||||
```bash
|
||||
$ tmux a -t myname
|
||||
$ tmux at -t myname
|
||||
$ tmux attach -t myname
|
||||
$ tmux attach-session -t myname
|
||||
```
|
||||
|
||||
### 终止会话
|
||||
|
||||
按名称终止会话
|
||||
|
||||
```bash
|
||||
$ tmux kill-ses -t myname # 杀死/删除会话
|
||||
$ tmux kill-session -t myname
|
||||
```
|
||||
|
||||
杀死/删除除当前会话之外的所有会话
|
||||
|
||||
```bash
|
||||
$ tmux kill-ses -a
|
||||
```
|
||||
|
||||
杀死/删除除 myname 之外的所有会话
|
||||
|
||||
```bash
|
||||
$ tmux kill-ses -a -t myname
|
||||
```
|
||||
|
||||
### Tmux 帮助
|
||||
|
||||
```bash
|
||||
$ tmux info
|
||||
```
|
||||
|
||||
### 配置
|
||||
|
||||
重新加载配置
|
||||
|
||||
```bash
|
||||
$ tmux source-file ~/.tmux.conf
|
||||
```
|
||||
|
||||
显示配置
|
||||
|
||||
```bash
|
||||
$ tmux show-options -g
|
||||
```
|
||||
|
||||
### 复制模式
|
||||
|
||||
命令 | 描述
|
||||
:- | -
|
||||
`Ctrl+b` `[` | 进入复制模式
|
||||
`<Space>` | 开始选择
|
||||
`Enter` | 复制选择
|
||||
`q` | 退出复制模式
|
||||
`Ctrl+b` `]` | 粘贴 buffer_0 的内容
|
||||
<!--rehype:className=shortcuts-->
|
||||
|
||||
主要作用类似于在 [Vim](./vim.md#动作) 中选择文本
|
||||
|
||||
Tmux 快捷键
|
||||
----------
|
||||
|
||||
### 入门
|
||||
<!--rehype:style=background:rgb(245 158 11/1);-->
|
||||
|
||||
快捷键/命令 | 描述
|
||||
:- | -
|
||||
| `Ctrl+b` `?` | List all shortcuts |
|
||||
<!--rehype:className=shortcuts show-header-->
|
||||
|
||||
----
|
||||
|
||||
显示每个会话、窗口、窗格等
|
||||
|
||||
```bash
|
||||
$ tmux info
|
||||
```
|
||||
|
||||
### 窗格(拆分)
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
快捷键/命令 | 描述
|
||||
:- | -
|
||||
`Ctrl+b` `"` _/_ `%` | 水平分割/垂直
|
||||
`Ctrl+b` `!` | 窗格 -> 窗口
|
||||
`Ctrl+b` `x` | 杀死窗格
|
||||
`Ctrl+b` \<Arrow> | 导航窗格
|
||||
`Ctrl+b` \<Space> | 切换布局
|
||||
`Ctrl+b` `{` _/_ `}` | 向左/向右移动
|
||||
`Ctrl+b` `o` | 转到下一个窗格
|
||||
`Ctrl+b` `z` | 切换全屏
|
||||
`Ctrl+b` `;` | 切换最后一个窗格
|
||||
`Ctrl+b` `q` | 显示号码
|
||||
`Ctrl+b` `q` `0`...`9` | 转到 # 窗格
|
||||
<!--rehype:className=shortcuts-->
|
||||
|
||||
### Window (Tabs)
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
快捷键/命令 | 描述
|
||||
:- | -
|
||||
`Ctrl+b` `c` | 创建窗口
|
||||
`Ctrl+b` `p` _/_ `n` | 上一个/下一个窗口
|
||||
`Ctrl+b` `"` _/_ `%` | 水平分割/垂直
|
||||
`Ctrl+b` `w` | 列表窗口
|
||||
`Ctrl+b` `,` | 重命名窗口
|
||||
`Ctrl+b` `f` | 查找窗口
|
||||
`Ctrl+b` `l` | 最后一个窗口
|
||||
`Ctrl+b` `.` | 移动窗口
|
||||
`Ctrl+b` `&` | 关闭窗口
|
||||
`Ctrl+b` `0`...`9` | 转到#窗口
|
||||
<!--rehype:className=shortcuts-->
|
||||
|
||||
### 会话(Windows 组)
|
||||
|
||||
快捷键/命令 | 描述
|
||||
:- | -
|
||||
`Ctrl+b` `d` | <red>从会话中分离</red>
|
||||
`Ctrl+b` `s` | 显示所有会话
|
||||
`Ctrl+b` `$` | 重命名会话
|
||||
`Ctrl+b` `(` _/_ `)` | 上一届/下一届
|
||||
<!--rehype:className=shortcuts-->
|
||||
|
||||
Tmux 命令模式
|
||||
-----------
|
||||
|
||||
### 用法
|
||||
<!--rehype:style=background:rgb(245 158 11/1);-->
|
||||
|
||||
快捷键/命令 | 描述
|
||||
:- | -
|
||||
`Ctrl+b` `:` | 进入命令模式
|
||||
<!--rehype:className=shortcuts-->
|
||||
|
||||
### 调整大小
|
||||
|
||||
快捷键/命令 | 描述
|
||||
:- | -
|
||||
`resize-pane -D 20` | 缩小尺寸
|
||||
`resize-pane -U 20` | 调整大小
|
||||
`resize-pane -L 20` | 向左调整大小
|
||||
`resize-pane -R 20` | 向右调整大小
|
||||
|
||||
### 清单
|
||||
|
||||
快捷键/命令 | 描述
|
||||
:- | -
|
||||
`list-keys` | 所有命令
|
||||
`list-panes` | 所有窗格
|
||||
`list-windows` | 所有窗口
|
||||
|
||||
### 复印
|
||||
|
||||
快捷键/命令 | 描述
|
||||
:- | -
|
||||
`list-buffers` | 列出所有缓冲区
|
||||
`show-buffer` | 显示 #0 内容
|
||||
`capture-pane` | 窗格的副本
|
||||
`choose-buffer` | 显示和粘贴
|
||||
`save-buffer a.txt` | 保存到文件
|
||||
`delete-buffer -b 1` | 删除缓冲区 1
|
||||
|
||||
### 环境
|
||||
|
||||
快捷键/命令 | 描述
|
||||
:- | -
|
||||
`set -g OPTION` | 为所有会话设置
|
||||
`setw -g OPTION` | 为所有窗口设置
|
||||
`setw -g mode-keys vi` | 启用 vi 模式
|
||||
`set -g prefix C-a` | 设置前缀
|
||||
|
||||
### 杂项
|
||||
|
||||
快捷键/命令 | 描述
|
||||
:- | -
|
||||
`swap-pane -s 3 -t 1` | 交换窗格
|
||||
`swap-window -t -1` | 向左移动
|
||||
`setw synchronize-panes` | 同步窗格
|
||||
`join-pane -t :#` | 加入窗格
|
||||
|
||||
另见
|
||||
---
|
||||
|
||||
- [Tmux 开源仓库](https://github.com/tmux/tmux) _(github.com)_
|
||||
- [Tmux Cheat Sheet & Quick Reference](https://tmuxcheatsheet.com/) _(tmuxcheatsheet.com)_
|
@@ -44,7 +44,6 @@ int3 = -21
|
||||
integerRange = 64
|
||||
```
|
||||
|
||||
|
||||
### 浮点数
|
||||
|
||||
```toml
|
||||
@@ -80,7 +79,7 @@ str2 = "You can \"quote\" me."
|
||||
str3 = "Name\tJos\u00E9\nLoc\tSF."
|
||||
```
|
||||
|
||||
See: [Strings](#toml-strings)
|
||||
See: [Strings](#字符串)
|
||||
|
||||
### Table
|
||||
|
||||
@@ -224,6 +223,7 @@ type = "pug"
|
||||
[foo.bar.baz]
|
||||
bat = "hi"
|
||||
```
|
||||
|
||||
#### ↓ 等效的 JSON
|
||||
|
||||
```json
|
||||
@@ -247,7 +247,7 @@ bat = "hi"
|
||||
[ j . "ʞ" .'l' ] # same as [j."ʞ".'l']
|
||||
```
|
||||
|
||||
### Inline Table
|
||||
### 内联表
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
```toml
|
||||
@@ -263,6 +263,5 @@ animal = { type.name = "pug" }
|
||||
- [Learn X in Y minutes](https://learnxinyminutes.com/docs/toml/) _(learnxinyminutes.com)_
|
||||
- [Better TOML VSCode 插件](https://marketplace.visualstudio.com/items?itemName=bungcip.better-toml) _(visualstudio.com)_
|
||||
|
||||
|
||||
- [INI 格式配置文件备忘清单](./ini.md) _(jaywcjlove.github.io)_
|
||||
- [YAML 格式配置文件备忘清单](./yaml.md) _(jaywcjlove.github.io)_
|
@@ -10,8 +10,8 @@ TypeScript 备忘清单
|
||||
|
||||
TypeScript 是具有类型语法的 JavaScript。Interface 是为了匹配它们的运行时行为而构建的。
|
||||
|
||||
- [JavaScript 备忘清单](./javascript.md)
|
||||
- [TypeScript 官网](https://www.typescriptlang.org/)
|
||||
- [JavaScript 备忘清单](./javascript.md) _(jaywcjlove.github.io)_
|
||||
- [TypeScript 官网](https://www.typescriptlang.org/) _(typescriptlang.org)_
|
||||
|
||||
### 内置类型基元
|
||||
|
||||
@@ -240,7 +240,6 @@ type Data = typeof data
|
||||
|
||||
通过 typeof 运算符重用来自现有 JavaScript 运行时值的类型。
|
||||
|
||||
|
||||
### 从函数返回类型
|
||||
|
||||
```ts
|
||||
@@ -1077,11 +1076,9 @@ console.log(fiveToHex());
|
||||
|
||||
从 Type 中移除 this 参数。 如果 Type 没有显式声明此参数,则结果只是 Type。 否则,从 Type 创建一个不带此参数的新函数类型。 泛型被删除,只有最后一个重载签名被传播到新的函数类型中。
|
||||
|
||||
|
||||
JSX
|
||||
----
|
||||
|
||||
|
||||
### JSX 介绍
|
||||
|
||||
JSX 规范是对 ECMAScript 的类似 XML 的语法扩展。
|
||||
@@ -1233,7 +1230,6 @@ function NotAValidFactoryFunction() {
|
||||
|
||||
默认情况下,`JSX.ElementClass` 是 {},但可以对其进行扩展,以将 `JSX` 的使用限制为仅限于符合适当接口的类型。
|
||||
|
||||
|
||||
### 类组件
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
@@ -1268,3 +1264,302 @@ class Select<T> extends React.Component<SelectProps<T>, any> {}
|
||||
// 使用
|
||||
const Form = () => <Select<string> items={['a', 'b']} />;
|
||||
```
|
||||
|
||||
各种各样的技巧
|
||||
---
|
||||
|
||||
### 类型推导(infer)
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
```ts
|
||||
type Capitalize<T extends string> = T extends `${infer U}${infer V}`
|
||||
? `${Uppercase<U>}${V}`
|
||||
: T
|
||||
type capitalized = Capitalize<"hello world"> // Hello World
|
||||
```
|
||||
|
||||
- 也可以在 infer 中使用条件约束(`extends`)
|
||||
|
||||
```ts
|
||||
type SomeBigInt = "100" extends `${infer U extends bigint}` ? U : never;
|
||||
// 100n
|
||||
```
|
||||
|
||||
### keyof 取 interface 的键
|
||||
|
||||
```ts
|
||||
interface Point {
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
||||
// type keys = "x" | "y"
|
||||
type keys = keyof Point;
|
||||
```
|
||||
|
||||
### 索引签名
|
||||
|
||||
```ts
|
||||
interface NumberOrString {
|
||||
[index: string]: string | number;
|
||||
length: number;
|
||||
name: string;
|
||||
}
|
||||
```
|
||||
|
||||
### 从数组中提取类型
|
||||
|
||||
```ts
|
||||
type Point = { x: number; y: number; }
|
||||
type Data = Point[];
|
||||
// Data 是个数组,提取里面的元素类型
|
||||
type PointDetail = Data[number];
|
||||
// type PointDetail = { x: number; y: number; }
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 只读元组类型
|
||||
|
||||
```ts
|
||||
const point = [3, 4] as const
|
||||
// type 'readonly [3, 4]'
|
||||
```
|
||||
|
||||
TSConfig Ref
|
||||
---
|
||||
|
||||
### 顶层配置
|
||||
|
||||
:- | --
|
||||
:- | --
|
||||
`files` [#](https://www.typescriptlang.org/zh/tsconfig#files) | 指定要`包含`在程序中的文件的允许列表
|
||||
`extends` [#](https://www.typescriptlang.org/zh/tsconfig#extends) | 包含要`继承`的另一个配置文件的路径
|
||||
`include` [#](https://www.typescriptlang.org/zh/tsconfig#include) | 指定要`包含`在程序中的文件名或模式数组
|
||||
`exclude` [#](https://www.typescriptlang.org/zh/tsconfig#exclude) | 指定解析包含时应`跳过`的文件名或模式数组
|
||||
`references` [#](https://www.typescriptlang.org/zh/tsconfig#references) | 项目引用是一种将 TypeScript 程序构造成更小部分的方法
|
||||
<!--rehype:className=style-list-arrow-->
|
||||
|
||||
---
|
||||
|
||||
```js
|
||||
{
|
||||
"extends": "./tsconfig",
|
||||
"compilerOptions": {
|
||||
"strictNullChecks": false
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 类型检查(compilerOptions)
|
||||
<!--rehype:wrap-class=row-span-3-->
|
||||
|
||||
:- | --
|
||||
:- | --
|
||||
`allowUnreachableCode` [#](https://www.typescriptlang.org/zh/tsconfig#allowUnreachableCode) | 允许无法访问的代码
|
||||
`allowUnusedLabels` [#](https://www.typescriptlang.org/zh/tsconfig#allowUnusedLabels) | 允许未使用的标签
|
||||
`alwaysStrict` [#](https://www.typescriptlang.org/zh/tsconfig#alwaysStrict) | 始终严格
|
||||
`exactOptionalPropertyTypes` [#](https://www.typescriptlang.org/zh/tsconfig#exactOptionalPropertyTypes) | 启用后,TypeScript 应用更严格的规则来处理它如何处理类型或具有 ? 字首
|
||||
`noFallthroughCasesInSwitch` [#](https://www.typescriptlang.org/zh/tsconfig#noFallthroughCasesInSwitch) | 在 switch 语句中报告失败案例的错误
|
||||
`noImplicitAny` [#](https://www.typescriptlang.org/zh/tsconfig#noImplicitAny) | 在某些不存在类型注释的情况下,TypeScript 将在无法推断类型时回退到变量的任何类型
|
||||
`noImplicitOverride` [#](https://www.typescriptlang.org/zh/tsconfig#noImplicitOverride) | 当处理使用继承的类时,子类可能与在基类中重命名时重载的函数“不同步”
|
||||
`noImplicitReturns` [#](https://www.typescriptlang.org/zh/tsconfig#noImplicitReturns) | 没有隐式返回
|
||||
`noImplicitThis` [#](https://www.typescriptlang.org/zh/tsconfig#noImplicitThis) | 使用隐含的“any”类型在“this”表达式上引发错误
|
||||
`noPropertyAccessFromIndexSignature` [#](https://www.typescriptlang.org/zh/tsconfig#noPropertyAccessFromIndexSignature) | 此设置确保通过“点”(obj.key)语法访问字段和“索引”(obj[“key”])以及在类型中声明属性的方式之间的一致性
|
||||
`noUncheckedIndexedAccess` [#](https://www.typescriptlang.org/zh/tsconfig#noUncheckedIndexedAccess) | TypeScript 有一种方法可以通过索引签名来描述对象上具有未知键但已知值的对象
|
||||
`noUnusedLocals` [#](https://www.typescriptlang.org/zh/tsconfig#noUnusedLocals) | 报告未使用的局部变量的错误
|
||||
`noUnusedParameters` [#](https://www.typescriptlang.org/zh/tsconfig#noUnusedParameters) | 报告函数中未使用参数的错误
|
||||
`strict` [#](https://www.typescriptlang.org/zh/tsconfig#strict) | 严格标志启用了范围广泛的类型检查行为,从而更有效地保证了程序的正确性
|
||||
`strictBindCallApply` [#](https://www.typescriptlang.org/zh/tsconfig#strictBindCallApply) | TypeScript 将检查函数调用、绑定和应用的内置方法是否使用底层函数的正确参数调用
|
||||
`strictFunctionTypes` [#](https://www.typescriptlang.org/zh/tsconfig#strictFunctionTypes) | 此标志会导致更正确地检查函数参数
|
||||
`strictNullChecks` [#](https://www.typescriptlang.org/zh/tsconfig#strictNullChecks) | 严格的空检查
|
||||
`strictPropertyInitialization` [#](https://www.typescriptlang.org/zh/tsconfig#strictPropertyInitialization) | 严格的属性初始化
|
||||
`useUnknownInCatchVariables` [#](https://www.typescriptlang.org/zh/tsconfig#useUnknownInCatchVariables) | 在 TypeScript 4.0 中,添加了支持以允许将 catch 子句中的变量类型从 any 更改为 unknown
|
||||
<!--rehype:className=style-list-arrow-->
|
||||
|
||||
### 模块(compilerOptions)
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
:- | --
|
||||
:- | --
|
||||
`allowUmdGlobalAccess` [#](https://www.typescriptlang.org/zh/tsconfig#allowUmdGlobalAccess) | 为 true 时,将允许你在模块文件中以全局变量的形式访问 UMD 的导出
|
||||
`baseUrl` [#](https://www.typescriptlang.org/zh/tsconfig#baseUrl) | 可以让您设置解析非绝对路径模块名时的基准目录
|
||||
`module` [#](https://www.typescriptlang.org/zh/tsconfig#module) | 设置程序的模块系统
|
||||
`moduleResolution` [#](https://www.typescriptlang.org/zh/tsconfig#moduleResolution) | 指定模块解析策略:'node'(Node.js)或 'classic'
|
||||
`moduleSuffixes` [#](https://www.typescriptlang.org/zh/tsconfig#moduleSuffixes) | 提供一种在解析模块时覆盖要搜索的默认文件名后缀列表的方法
|
||||
`noResolve` [#](https://www.typescriptlang.org/zh/tsconfig#noResolve) | 默认情况下,TypeScript 将检查导入和 `<reference` 指令的初始文件集,并将这些解析的文件添加到您的程序中
|
||||
`paths` [#](https://www.typescriptlang.org/zh/tsconfig#paths) | 一些将模块导入重新映射到相对于 baseUrl 路径的配置
|
||||
`resolveJsonModule` [#](https://www.typescriptlang.org/zh/tsconfig#resolveJsonModule) | 允许导入带有“.json”扩展名的模块,这是 node 项目中的常见做法
|
||||
`rootDir` [#](https://www.typescriptlang.org/zh/tsconfig#rootDir) | 默认: 所有输入的非声明文件中的最长公共路径
|
||||
`rootDirs` [#](https://www.typescriptlang.org/zh/tsconfig#rootDirs) | 通过 rootDirs,你可以告诉编译器有许多“虚拟”的目录作为一个根目录
|
||||
`typeRoots` [#](https://www.typescriptlang.org/zh/tsconfig#typeRoots) | 默认情况下,所有 可见 的 ”@types” 包都将包含在你的编译过程中
|
||||
`types` [#](https://www.typescriptlang.org/zh/tsconfig#types) | 默认情况下,所有 可见 的 ”@types” 包都将包含在你的编译过程中
|
||||
<!--rehype:className=style-list-arrow-->
|
||||
|
||||
### Emit(compilerOptions)
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
:- | --
|
||||
:- | --
|
||||
`declaration` [#](https://www.typescriptlang.org/zh/tsconfig#declaration) |
|
||||
`declarationDir` [#](https://www.typescriptlang.org/zh/tsconfig#declarationDir) |
|
||||
`declarationMap` [#](https://www.typescriptlang.org/zh/tsconfig#declarationMap) |
|
||||
`downlevelIteration` [#](https://www.typescriptlang.org/zh/tsconfig#downlevelIteration) |
|
||||
`emitBOM` [#](https://www.typescriptlang.org/zh/tsconfig#emitBOM) |
|
||||
`emitDeclarationOnly` [#](https://www.typescriptlang.org/zh/tsconfig#emitDeclarationOnly) |
|
||||
`importHelpers` [#](https://www.typescriptlang.org/zh/tsconfig#importHelpers) |
|
||||
`importsNotUsedAsValues` [#](https://www.typescriptlang.org/zh/tsconfig#importsNotUsedAsValues) |
|
||||
`inlineSourceMap` [#](https://www.typescriptlang.org/zh/tsconfig#inlineSourceMap) |
|
||||
`inlineSources` [#](https://www.typescriptlang.org/zh/tsconfig#inlineSources) |
|
||||
`mapRoot` [#](https://www.typescriptlang.org/zh/tsconfig#mapRoot) |
|
||||
`newLine` [#](https://www.typescriptlang.org/zh/tsconfig#newLine) |
|
||||
`noEmit` [#](https://www.typescriptlang.org/zh/tsconfig#noEmit) |
|
||||
`noEmitHelpers` [#](https://www.typescriptlang.org/zh/tsconfig#noEmitHelpers) |
|
||||
`noEmitOnError` [#](https://www.typescriptlang.org/zh/tsconfig#noEmitOnError) |
|
||||
`outDir` [#](https://www.typescriptlang.org/zh/tsconfig#outDir) |
|
||||
`outFile` [#](https://www.typescriptlang.org/zh/tsconfig#outFile) |
|
||||
`preserveConstEnums` [#](https://www.typescriptlang.org/zh/tsconfig#preserveConstEnums) |
|
||||
`preserveValueImports` [#](https://www.typescriptlang.org/zh/tsconfig#preserveValueImports) |
|
||||
`removeComments` [#](https://www.typescriptlang.org/zh/tsconfig#removeComments) |
|
||||
`sourceMap` [#](https://www.typescriptlang.org/zh/tsconfig#sourceMap) |
|
||||
`sourceRoot` [#](https://www.typescriptlang.org/zh/tsconfig#sourceRoot) |
|
||||
`stripInternal` [#](https://www.typescriptlang.org/zh/tsconfig#stripInternal) |
|
||||
|
||||
### JavaScript 支持(compilerOptions)
|
||||
|
||||
:- | --
|
||||
:- | --
|
||||
`allowJs` [#](https://www.typescriptlang.org/zh/tsconfig#allowJs) | 允许 JavaScript 文件在你的工程中被引入,而不是仅仅允许 .ts 和 .tsx 文件
|
||||
`checkJs` [#](https://www.typescriptlang.org/zh/tsconfig#checkJs) | 与 allowJs 配合使用,当 checkJs 被启用时,JavaScript 文件中会报告错误
|
||||
`maxNodeModuleJsDepth` [#](https://www.typescriptlang.org/zh/tsconfig#maxNodeModuleJsDepth) | 在 node_modules 下搜索和加载 JavaScript 文件的最大依赖深度
|
||||
<!--rehype:className=style-list-arrow-->
|
||||
|
||||
### 编辑器支持(compilerOptions)
|
||||
|
||||
:- | --
|
||||
:- | --
|
||||
`disableSizeLimit` [#](https://www.typescriptlang.org/zh/tsconfig#disableSizeLimit) | 分配的内存量有一个上限。打开此标志将删除限制
|
||||
`plugins` [#](https://www.typescriptlang.org/zh/tsconfig#plugins) | 可在编辑器内运行的语言服务插件列表
|
||||
<!--rehype:className=style-list-arrow-->
|
||||
|
||||
### 互操作约束(compilerOptions)
|
||||
|
||||
:- | --
|
||||
:- | --
|
||||
`allowSyntheticDefaultImports` [#](https://www.typescriptlang.org/zh/tsconfig#allowSyntheticDefaultImports) |
|
||||
`esModuleInterop` [#](https://www.typescriptlang.org/zh/tsconfig#esModuleInterop) |
|
||||
`forceConsistentCasingInFileNames` [#](https://www.typescriptlang.org/zh/tsconfig#forceConsistentCasingInFileNames) |
|
||||
`isolatedModules` [#](https://www.typescriptlang.org/zh/tsconfig#isolatedModules) |
|
||||
`preserveSymlinks` [#](https://www.typescriptlang.org/zh/tsconfig#preserveSymlinks) |
|
||||
|
||||
### 向后兼容性(compilerOptions)
|
||||
|
||||
:- | --
|
||||
:- | --
|
||||
`charset` [#](https://www.typescriptlang.org/zh/tsconfig#charset) |
|
||||
`keyofStringsOnly` [#](https://www.typescriptlang.org/zh/tsconfig#keyofStringsOnly) |
|
||||
`noImplicitUseStrict` [#](https://www.typescriptlang.org/zh/tsconfig#noImplicitUseStrict) |
|
||||
`noStrictGenericChecks` [#](https://www.typescriptlang.org/zh/tsconfig#noStrictGenericChecks) |
|
||||
`out` [#](https://www.typescriptlang.org/zh/tsconfig#out) |
|
||||
`suppressExcessPropertyErrors` [#](https://www.typescriptlang.org/zh/tsconfig#suppressExcessPropertyErrors) |
|
||||
`suppressImplicitAnyIndexErrors` [#](https://www.typescriptlang.org/zh/tsconfig#suppressImplicitAnyIndexErrors) |
|
||||
|
||||
### 语言与环境(compilerOptions)
|
||||
|
||||
:- | --
|
||||
:- | --
|
||||
`emitDecoratorMetadata` [#](https://www.typescriptlang.org/zh/tsconfig#emitDecoratorMetadata) |
|
||||
`experimentalDecorators` [#](https://www.typescriptlang.org/zh/tsconfig#experimentalDecorators) |
|
||||
`jsx` [#](https://www.typescriptlang.org/zh/tsconfig#jsx) |
|
||||
`jsxFactory` [#](https://www.typescriptlang.org/zh/tsconfig#jsxFactory) |
|
||||
`jsxFragmentFactory` [#](https://www.typescriptlang.org/zh/tsconfig#jsxFragmentFactory) |
|
||||
`jsxImportSource` [#](https://www.typescriptlang.org/zh/tsconfig#jsxImportSource) |
|
||||
`lib` [#](https://www.typescriptlang.org/zh/tsconfig#lib) |
|
||||
`moduleDetection` [#](https://www.typescriptlang.org/zh/tsconfig#moduleDetection) |
|
||||
`noLib` [#](https://www.typescriptlang.org/zh/tsconfig#noLib) |
|
||||
`reactNamespace` [#](https://www.typescriptlang.org/zh/tsconfig#reactNamespace) |
|
||||
`target` [#](https://www.typescriptlang.org/zh/tsconfig#target) |
|
||||
`useDefineForClassFields` [#](https://www.typescriptlang.org/zh/tsconfig#useDefineForClassFields) |
|
||||
|
||||
### 编译器诊断(compilerOptions)
|
||||
|
||||
:- | --
|
||||
:- | --
|
||||
`diagnostics` [#](https://www.typescriptlang.org/zh/tsconfig#diagnostics) |
|
||||
`explainFiles` [#](https://www.typescriptlang.org/zh/tsconfig#explainFiles) |
|
||||
`extendedDiagnostics` [#](https://www.typescriptlang.org/zh/tsconfig#extendedDiagnostics) |
|
||||
`generateCpuProfile` [#](https://www.typescriptlang.org/zh/tsconfig#generateCpuProfile) |
|
||||
`listEmittedFiles` [#](https://www.typescriptlang.org/zh/tsconfig#listEmittedFiles) |
|
||||
`listFiles` [#](https://www.typescriptlang.org/zh/tsconfig#listFiles) |
|
||||
`traceResolution` [#](https://www.typescriptlang.org/zh/tsconfig#traceResolution) |
|
||||
|
||||
### 项目(compilerOptions)
|
||||
|
||||
:- | --
|
||||
:- | --
|
||||
`composite` [#](https://www.typescriptlang.org/zh/tsconfig#composite) |
|
||||
`disableReferencedProjectLoad` [#](https://www.typescriptlang.org/zh/tsconfig#disableReferencedProjectLoad) |
|
||||
`disableSolutionSearching` [#](https://www.typescriptlang.org/zh/tsconfig#disableSolutionSearching) |
|
||||
`disableSourceOfProjectReferenceRedirect` [#](https://www.typescriptlang.org/zh/tsconfig#disableSourceOfProjectReferenceRedirect) |
|
||||
`incremental` [#](https://www.typescriptlang.org/zh/tsconfig#incremental) |
|
||||
`tsBuildInfoFile` [#](https://www.typescriptlang.org/zh/tsconfig#tsBuildInfoFile) |
|
||||
|
||||
### 输出格式(compilerOptions)
|
||||
|
||||
:- | --
|
||||
:- | --
|
||||
`noErrorTruncation` [#](https://www.typescriptlang.org/zh/tsconfig#noErrorTruncation) |
|
||||
`preserveWatchOutput` [#](https://www.typescriptlang.org/zh/tsconfig#preserveWatchOutput) |
|
||||
`pretty` [#](https://www.typescriptlang.org/zh/tsconfig#pretty) |
|
||||
|
||||
### 完整性(compilerOptions)
|
||||
|
||||
:- | --
|
||||
:- | --
|
||||
`skipDefaultLibCheck` [#](https://www.typescriptlang.org/zh/tsconfig#skipDefaultLibCheck) |
|
||||
`skipLibCheck` [#](https://www.typescriptlang.org/zh/tsconfig#skipLibCheck) |
|
||||
|
||||
### 监听选项(watchOptions)
|
||||
|
||||
:- | --
|
||||
:- | --
|
||||
`watchFile` [#](https://www.typescriptlang.org/zh/tsconfig#watch-watchFile) |
|
||||
`watchDirectory` [#](https://www.typescriptlang.org/zh/tsconfig#watch-watchDirectory) |
|
||||
`fallbackPolling` [#](https://www.typescriptlang.org/zh/tsconfig#watch-fallbackPolling) |
|
||||
`synchronousWatchDirectory` [#](https://www.typescriptlang.org/zh/tsconfig#watch-synchronousWatchDirectory) |
|
||||
`excludeDirectories` [#](https://www.typescriptlang.org/zh/tsconfig#watch-excludeDirectories) |
|
||||
`excludeFiles` [#](https://www.typescriptlang.org/zh/tsconfig#watch-excludeFiles) |
|
||||
|
||||
---
|
||||
|
||||
```js
|
||||
{
|
||||
"watchOptions": {
|
||||
"synchronousWatchDirectory": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 类型采集(typeAcquisition)
|
||||
|
||||
:- | --
|
||||
:- | --
|
||||
`enable` [#](https://www.typescriptlang.org/zh/tsconfig#type-enable) |
|
||||
`include` [#](https://www.typescriptlang.org/zh/tsconfig#type-include) |
|
||||
`exclude` [#](https://www.typescriptlang.org/zh/tsconfig#type-exclude) |
|
||||
`disableFilenameBasedTypeAcquisition` [#](https://www.typescriptlang.org/zh/tsconfig#type-disableFilenameBasedTypeAcquisition) |
|
||||
|
||||
---
|
||||
|
||||
```js
|
||||
{
|
||||
"typeAcquisition": {
|
||||
"enable": false
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
另见
|
||||
----
|
||||
|
||||
- [JavaScript 备忘清单](./javascript.md)
|
||||
- [TypeScript 官网](https://www.typescriptlang.org/) _(typescriptlang.org)_
|
||||
|
@@ -276,7 +276,6 @@ Vim 文本对象
|
||||
### 用法
|
||||
<!--rehype:style=background:#d7a100;-->
|
||||
|
||||
|
||||
快捷方式 | 说明
|
||||
:- | -
|
||||
`v` | <pur>i</pur> _/_ <pur>a</pur> | <yel>p</yel>
|
||||
@@ -409,7 +408,7 @@ Vim 搜索和替换
|
||||
`?foo` | 向后搜索
|
||||
`/\v\d+` | 使用 [regex](./regex.md) 搜索
|
||||
`n` | 下一个匹配的搜索模式
|
||||
`N` | 上一场比赛
|
||||
`N` | 上一个匹配的搜索
|
||||
`*` | 向前搜索当前单词
|
||||
`#` | 向后搜索当前单词
|
||||
|
||||
@@ -435,6 +434,7 @@ Vim 搜索和替换
|
||||
```vim
|
||||
:%s/{pattern}/{str}/[flags]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
:- | -
|
||||
@@ -516,7 +516,6 @@ Vim 搜索和替换
|
||||
### 例子
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
|
||||
```shell
|
||||
:s/a\|b/xxx\0xxx/g # 将 "a b" 修改为 "xxxaxxx xxxbxxx"
|
||||
:s/test/\U& file/ # 将 "test" 修改为 "TEST FILE"
|
||||
|
@@ -65,7 +65,6 @@ VSCode 备忘清单
|
||||
| `Ctrl` `M` | 切换 Tab 移动焦点 |
|
||||
<!--rehype:className=shortcuts-->
|
||||
|
||||
|
||||
### 搜索和替换
|
||||
|
||||
| - | - |
|
||||
@@ -115,7 +114,6 @@ VSCode 备忘清单
|
||||
| `Ctrl` `K` `M` | 更改文件语言 |
|
||||
<!--rehype:className=shortcuts-->
|
||||
|
||||
|
||||
### 编辑管理
|
||||
|
||||
| - | - |
|
||||
@@ -170,7 +168,6 @@ VSCode 备忘清单
|
||||
| `Ctrl` `K` `Z` | Zen 模式(Esc Esc 退出) |
|
||||
<!--rehype:className=shortcuts-->
|
||||
|
||||
|
||||
### 调试
|
||||
|
||||
| - | - |
|
||||
|
387
docs/vue.md
387
docs/vue.md
@@ -3,7 +3,6 @@ Vue 3 备忘清单
|
||||
|
||||
渐进式 JavaScript 框架 [Vue 3](https://cn.vuejs.org/) 备忘清单的快速参考列表,包含常用 API 和示例。
|
||||
|
||||
|
||||
入门
|
||||
---
|
||||
|
||||
@@ -209,7 +208,6 @@ data() {
|
||||
</span>
|
||||
```
|
||||
|
||||
|
||||
### 指令 Directives
|
||||
|
||||
```html
|
||||
@@ -277,66 +275,149 @@ v-on:submit.prevent="onSubmit"
|
||||
### 声明状态
|
||||
|
||||
```html
|
||||
<div>{{ count }}</div>
|
||||
<div>{{ state.count }}</div>
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```js {2,4}
|
||||
export default {
|
||||
data() {
|
||||
```js {6,7,11}
|
||||
import { defineComponent, reactive } from 'vue';
|
||||
|
||||
// `defineComponent`用于IDE推导类型
|
||||
export default defineComponent({
|
||||
// `setup` 是一个专门用于组合式 API 的特殊钩子函数
|
||||
setup() {
|
||||
const state = reactive({ count: 0 });
|
||||
|
||||
// 暴露 state 到模板
|
||||
return {
|
||||
count: 0
|
||||
}
|
||||
state
|
||||
};
|
||||
},
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### 声明方法
|
||||
|
||||
```html
|
||||
<button @click="increment">
|
||||
{{ count }}
|
||||
{{ state.count }}
|
||||
</button>
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```js {8-10}
|
||||
export default {
|
||||
data() {
|
||||
```js {7-9,14}
|
||||
import { defineComponent, reactive } from 'vue';
|
||||
|
||||
export default defineComponent({
|
||||
setup() {
|
||||
const state = reactive({ count: 0 });
|
||||
|
||||
function increment() {
|
||||
state.count++;
|
||||
}
|
||||
|
||||
// 不要忘记同时暴露 increment 函数
|
||||
return {
|
||||
count: 0
|
||||
}
|
||||
state,
|
||||
increment
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
increment() {
|
||||
this.count++
|
||||
}
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### `<script setup>` setup语法糖
|
||||
|
||||
```html {1}
|
||||
<script setup>
|
||||
// setup语法糖用于简化代码,尤其是当需要暴露的状态和方法越来越多时
|
||||
import { reactive } from 'vue';
|
||||
|
||||
const state = reactive({ count: 0 })
|
||||
|
||||
function increment() {
|
||||
state.count++
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<button @click="increment">
|
||||
{{ state.count }}
|
||||
</button>
|
||||
</template>
|
||||
```
|
||||
|
||||
### 用 `ref()` 定义响应式变量
|
||||
|
||||
```js
|
||||
// `reactive`只能用于对象、数组和 Map、Set 这样的集合类型,对 string、number 和 boolean 这样的原始类型则需要使用`ref`
|
||||
import { ref } from 'vue';
|
||||
|
||||
const count = ref(0);
|
||||
|
||||
console.log(count); // { value: 0 }
|
||||
console.log(count.value); // 0
|
||||
|
||||
count.value++;
|
||||
console.log(count.value); // 1
|
||||
|
||||
const objectRef = ref({ count: 0 });
|
||||
|
||||
// 这是响应式的替换
|
||||
objectRef.value = { count: 1 };
|
||||
|
||||
const obj = {
|
||||
foo: ref(1),
|
||||
bar: ref(2)
|
||||
};
|
||||
|
||||
// 该函数接收一个 ref
|
||||
// 需要通过 .value 取值
|
||||
// 但它会保持响应性
|
||||
callSomeFunction(obj.foo);
|
||||
|
||||
// 仍然是响应式的
|
||||
const { foo, bar } = obj;
|
||||
```
|
||||
|
||||
```html
|
||||
<!-- PS: 在html模板中不需要带.value就可以使用 -->
|
||||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
|
||||
const count = ref(0);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
{{ count }}
|
||||
</div>
|
||||
</template>
|
||||
```
|
||||
|
||||
### 有状态方法
|
||||
|
||||
```js
|
||||
import { debounce } from 'lodash-es'
|
||||
export default {
|
||||
created() {
|
||||
import { reactive, defineComponent, onUnmounted } from 'vue';
|
||||
import { debounce } from 'lodash-es';
|
||||
|
||||
export default defineComponent({
|
||||
setup() {
|
||||
// 每个实例都有了自己的预置防抖的处理函数
|
||||
this.debouncedClick = debounce(this.click, 500)
|
||||
},
|
||||
unmounted() {
|
||||
// 最好是在组件卸载时
|
||||
// 清除掉防抖计时器
|
||||
this.debouncedClick.cancel()
|
||||
},
|
||||
methods: {
|
||||
click() {
|
||||
const debouncedClick = debounce(click, 500);
|
||||
|
||||
function click() {
|
||||
// ... 对点击的响应 ...
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 最好是在组件卸载时
|
||||
// 清除掉防抖计时器
|
||||
onUnmounted(() => {
|
||||
debouncedClick.cancel();
|
||||
});
|
||||
},
|
||||
});
|
||||
```
|
||||
<!--rehype:className=wrap-text -->
|
||||
|
||||
@@ -348,32 +429,32 @@ API 参考
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`createApp()` | [#](https://cn.vuejs.org/api/application.html#create-app)
|
||||
`createSSRApp()` | [#](https://cn.vuejs.org/api/application.html#create-ssr-app)
|
||||
`app.mount()` | [#](https://cn.vuejs.org/api/application.html#app-mount)
|
||||
`app.unmount()` | [#](https://cn.vuejs.org/api/application.html#app-unmount)
|
||||
`app.provide()` | [#](https://cn.vuejs.org/api/application.html#app-provide)
|
||||
`app.component()` | [#](https://cn.vuejs.org/api/application.html#app-component)
|
||||
`app.directive()` | [#](https://cn.vuejs.org/api/application.html#app-directive)
|
||||
`app.use()` | [#](https://cn.vuejs.org/api/application.html#app-use)
|
||||
`app.mixin()` | [#](https://cn.vuejs.org/api/application.html#app-mixin)
|
||||
`app.version` | [#](https://cn.vuejs.org/api/application.html#app-version)
|
||||
`app.config` | [#](https://cn.vuejs.org/api/application.html#app-config)
|
||||
`app.config.errorHandler` | [#](https://cn.vuejs.org/api/application.html#app-config-errorhandler)
|
||||
`app.config.warnHandler` | [#](https://cn.vuejs.org/api/application.html#app-config-warnhandler)
|
||||
`app.config.performance` | [#](https://cn.vuejs.org/api/application.html#app-config-performance)
|
||||
`app.config.compilerOptions` | [#](https://cn.vuejs.org/api/application.html#app-config-compileroptions)
|
||||
`app.config.globalProperties` | [#](https://cn.vuejs.org/api/application.html#app-config-globalproperties)
|
||||
`app.config.optionMergeStrategies` | [#](https://cn.vuejs.org/api/application.html#app-config-optionmergestrategies)
|
||||
`createApp()` | 创建一个应用实例 [#](https://cn.vuejs.org/api/application.html#create-app)
|
||||
`createSSRApp()` | 以 [SSR 激活](https://cn.vuejs.org/guide/scaling-up/ssr.html#client-hydration)模式创建一个应用实例 [#](https://cn.vuejs.org/api/application.html#create-ssr-app)
|
||||
`app.mount()` | 将应用实例挂载在一个容器元素中 [#](https://cn.vuejs.org/api/application.html#app-mount)
|
||||
`app.unmount()` | 卸载一个已挂载的应用实例 [#](https://cn.vuejs.org/api/application.html#app-unmount)
|
||||
`app.provide()` | 提供一个可以在应用中的所有后代组件中注入使用的值 [#](https://cn.vuejs.org/api/application.html#app-provide)
|
||||
`app.component()` | 注册或获取全局组件 [#](https://cn.vuejs.org/api/application.html#app-component)
|
||||
`app.directive()` | 注册或获取全局指令 [#](https://cn.vuejs.org/api/application.html#app-directive)
|
||||
`app.use()` | 安装一个插件 [#](https://cn.vuejs.org/api/application.html#app-use)
|
||||
`app.mixin()` | 全局注册一个混入 [#](https://cn.vuejs.org/api/application.html#app-mixin)
|
||||
`app.version` | 当前应用所使用的 Vue 版本号 [#](https://cn.vuejs.org/api/application.html#app-version)
|
||||
`app.config` | 获得应用实例的配置设定 [#](https://cn.vuejs.org/api/application.html#app-config)
|
||||
`app.config.errorHandler` | 为应用内抛出的未捕获错误指定一个全局处理函数 [#](https://cn.vuejs.org/api/application.html#app-config-errorhandler)
|
||||
`app.config.warnHandler` | 为 Vue 的运行时警告指定一个自定义处理函数 [#](https://cn.vuejs.org/api/application.html#app-config-warnhandler)
|
||||
`app.config.performance` | 在浏览器开发工具中追踪性能表现 [#](https://cn.vuejs.org/api/application.html#app-config-performance)
|
||||
`app.config.compilerOptions` | 配置运行时编译器的选项 [#](https://cn.vuejs.org/api/application.html#app-config-compileroptions)
|
||||
`app.config.globalProperties` | 注册全局属性对象 [#](https://cn.vuejs.org/api/application.html#app-config-globalproperties)
|
||||
`app.config.optionMergeStrategies` | 定义自定义组件选项的合并策略的对象 [#](https://cn.vuejs.org/api/application.html#app-config-optionmergestrategies)
|
||||
|
||||
### 全局 API - 通用
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`version` | [#](https://cn.vuejs.org/api/general.html#version)
|
||||
`nextTick()` | [#](https://cn.vuejs.org/api/general.html#nexttick)
|
||||
`defineComponent()` | [#](https://cn.vuejs.org/api/general.html#definecomponent)
|
||||
`defineAsyncComponent()` | [#](https://cn.vuejs.org/api/general.html#defineasynccomponent)
|
||||
`version` | Vue 版本号 [#](https://cn.vuejs.org/api/general.html#version)
|
||||
`nextTick()` | 等待下一次 DOM 更新后执行回调 [#](https://cn.vuejs.org/api/general.html#nexttick)
|
||||
`defineComponent()` | 在定义 Vue 组件时提供类型推导的辅助函数 [#](https://cn.vuejs.org/api/general.html#definecomponent)
|
||||
`defineAsyncComponent()` | 定义一个异步组件 [#](https://cn.vuejs.org/api/general.html#defineasynccomponent)
|
||||
`defineCustomElement()` | [#](https://cn.vuejs.org/api/general.html#definecustomelement)
|
||||
|
||||
### 组合式 API - setup()
|
||||
@@ -389,13 +470,13 @@ API 参考
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`isRef()` | [#](https://cn.vuejs.org/api/reactivity-utilities.html#isref)
|
||||
`unref()` | [#](https://cn.vuejs.org/api/reactivity-utilities.html#unref)
|
||||
`toRef()` | [#](https://cn.vuejs.org/api/reactivity-utilities.html#toref)
|
||||
`toRefs()` | [#](https://cn.vuejs.org/api/reactivity-utilities.html#torefs)
|
||||
`isProxy()` | [#](https://cn.vuejs.org/api/reactivity-utilities.html#isproxy)
|
||||
`isReactive()` | [#](https://cn.vuejs.org/api/reactivity-utilities.html#isreactive)
|
||||
`isReadonly()` | [#](https://cn.vuejs.org/api/reactivity-utilities.html#isreadonly)
|
||||
`isRef()` | 判断是否为 ref [#](https://cn.vuejs.org/api/reactivity-utilities.html#isref)
|
||||
`unref()` | 是 ref,返回内部值,否则返回参数本身 [#](https://cn.vuejs.org/api/reactivity-utilities.html#unref)
|
||||
`toRef()` | 创建一个属性对应的 ref [#](https://cn.vuejs.org/api/reactivity-utilities.html#toref)
|
||||
`toRefs()` | 将对象上的每一个可枚举属性转换为 ref [#](https://cn.vuejs.org/api/reactivity-utilities.html#torefs)
|
||||
`isProxy()` | 检查一个对象是否是由 `reactive()`、`readonly()`、`shallowReactive()` 或 `shallowReadonly()` 创建的代理 [#](https://cn.vuejs.org/api/reactivity-utilities.html#isproxy)
|
||||
`isReactive()` | 检查一个对象是否是由 `reactive()` 或 `shallowReactive()` 创建的代理。 [#](https://cn.vuejs.org/api/reactivity-utilities.html#isreactive)
|
||||
`isReadonly()` | 检查传入的值是否为只读对象 [#](https://cn.vuejs.org/api/reactivity-utilities.html#isreadonly)
|
||||
|
||||
### 组合式 API - 生命周期钩子
|
||||
<!--rehype:wrap-class=row-span-3-->
|
||||
@@ -420,144 +501,144 @@ API 参考
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`provide()` | [#](https://cn.vuejs.org/api/composition-api-dependency-injection.html#provide)
|
||||
`inject()` | [#](https://cn.vuejs.org/api/composition-api-dependency-injection.html#inject)
|
||||
`provide()` | 提供一个可以被后代组件中注入使用的值 [#](https://cn.vuejs.org/api/composition-api-dependency-injection.html#provide)
|
||||
`inject()` | 注入一个由祖先组件提供的值 [#](https://cn.vuejs.org/api/composition-api-dependency-injection.html#inject)
|
||||
|
||||
### 组合式 API - 响应式: 核心
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`ref()` | [#](https://cn.vuejs.org/api/reactivity-core.html#ref)
|
||||
`computed ()` | [#](https://cn.vuejs.org/api/reactivity-core.html#computed)
|
||||
`reactive()` | [#](https://cn.vuejs.org/api/reactivity-core.html#reactive)
|
||||
`readonly()` | [#](https://cn.vuejs.org/api/reactivity-core.html#readonly)
|
||||
`watchEffect()` | [#](https://cn.vuejs.org/api/reactivity-core.html#watcheffect)
|
||||
`watchPostEffect()` | [#](https://cn.vuejs.org/api/reactivity-core.html#watchposteffect)
|
||||
`watchSyncEffect()` | [#](https://cn.vuejs.org/api/reactivity-core.html#watchsynceffect)
|
||||
`watch()` | [#](https://cn.vuejs.org/api/reactivity-core.html#watch)
|
||||
`ref()` | 返回一个 ref 对象 [#](https://cn.vuejs.org/api/reactivity-core.html#ref)
|
||||
`computed ()` | 定义一个计算属性 [#](https://cn.vuejs.org/api/reactivity-core.html#computed)
|
||||
`reactive()` | 返回一个对象的响应式代理 [#](https://cn.vuejs.org/api/reactivity-core.html#reactive)
|
||||
`readonly()` | 返回一个原值的只读代理 [#](https://cn.vuejs.org/api/reactivity-core.html#readonly)
|
||||
`watchEffect()` | 立即运行一个函数,同时监听 [#](https://cn.vuejs.org/api/reactivity-core.html#watcheffect)
|
||||
`watchPostEffect()` | `watchEffect()` 使用 `flush: 'post'` 选项时的别名。 [#](https://cn.vuejs.org/api/reactivity-core.html#watchposteffect)
|
||||
`watchSyncEffect()` | `watchEffect()` 使用 `flush: 'sync'` 选项时的别名。 [#](https://cn.vuejs.org/api/reactivity-core.html#watchsynceffect)
|
||||
`watch()` | 侦听一个或多个响应式数据源 [#](https://cn.vuejs.org/api/reactivity-core.html#watch)
|
||||
|
||||
### 选项式 API - 状态选项
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`data` | [#](https://cn.vuejs.org/api/options-state.html#data)
|
||||
`props` | [#](https://cn.vuejs.org/api/options-state.html#props)
|
||||
`computed` | [#](https://cn.vuejs.org/api/options-state.html#computed)
|
||||
`methods` | [#](https://cn.vuejs.org/api/options-state.html#methods)
|
||||
`watch` | [#](https://cn.vuejs.org/api/options-state.html#watch)
|
||||
`emits` | [#](https://cn.vuejs.org/api/options-state.html#emits)
|
||||
`expose` | [#](https://cn.vuejs.org/api/options-state.html#expose)
|
||||
`data` | 声明组件初始响应式状态 [#](https://cn.vuejs.org/api/options-state.html#data)
|
||||
`props` | 声明一个组件的 props [#](https://cn.vuejs.org/api/options-state.html#props)
|
||||
`computed` | 声明要在组件实例上暴露的计算属性 [#](https://cn.vuejs.org/api/options-state.html#computed)
|
||||
`methods` | 声明要混入到组件实例中的方法 [#](https://cn.vuejs.org/api/options-state.html#methods)
|
||||
`watch` | 声明在数据更改时调用的侦听回调 [#](https://cn.vuejs.org/api/options-state.html#watch)
|
||||
`emits` | 声明由组件触发的自定义事件 [#](https://cn.vuejs.org/api/options-state.html#emits)
|
||||
`expose` | 声明当组件实例被父组件通过模板引用访问时暴露的公共属性 [#](https://cn.vuejs.org/api/options-state.html#expose)
|
||||
|
||||
### 选项式 API - 生命周期选项
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`beforeCreate` | [#](https://cn.vuejs.org/api/options-lifecycle.html#beforecreate)
|
||||
`created` | [#](https://cn.vuejs.org/api/options-lifecycle.html#created)
|
||||
`beforeMount` | [#](https://cn.vuejs.org/api/options-lifecycle.html#beforemount)
|
||||
`mounted` | [#](https://cn.vuejs.org/api/options-lifecycle.html#mounted)
|
||||
`beforeUpdate` | [#](https://cn.vuejs.org/api/options-lifecycle.html#beforeupdate)
|
||||
`updated` | [#](https://cn.vuejs.org/api/options-lifecycle.html#updated)
|
||||
`beforeUnmount` | [#](https://cn.vuejs.org/api/options-lifecycle.html#beforeunmount)
|
||||
`unmounted` | [#](https://cn.vuejs.org/api/options-lifecycle.html#unmounted)
|
||||
`errorCaptured` | [#](https://cn.vuejs.org/api/options-lifecycle.html#errorcaptured)
|
||||
`renderTracked` | [#](https://cn.vuejs.org/api/options-lifecycle.html#rendertracked)
|
||||
`renderTriggered` | [#](https://cn.vuejs.org/api/options-lifecycle.html#rendertriggered-sup-classvt-badge-dev-only)
|
||||
`activated` | [#](https://cn.vuejs.org/api/options-lifecycle.html#activated)
|
||||
`deactivated` | [#](https://cn.vuejs.org/api/options-lifecycle.html#deactivated)
|
||||
`serverPrefetch` | [#](https://cn.vuejs.org/api/options-lifecycle.html#serverprefetch)
|
||||
`beforeCreate` | 组件实例初始化完成之后立即调用 [#](https://cn.vuejs.org/api/options-lifecycle.html#beforecreate)
|
||||
`created` | 组件实例处理完所有与状态相关的选项后调用 [#](https://cn.vuejs.org/api/options-lifecycle.html#created)
|
||||
`beforeMount` | 组件被挂载之前调用 [#](https://cn.vuejs.org/api/options-lifecycle.html#beforemount)
|
||||
`mounted` | 组件被挂载之后调用 [#](https://cn.vuejs.org/api/options-lifecycle.html#mounted)
|
||||
`beforeUpdate` | 状态变更而更新其 DOM 树之前调用 [#](https://cn.vuejs.org/api/options-lifecycle.html#beforeupdate)
|
||||
`updated` | 状态变更而更新其 DOM 树之后调用 [#](https://cn.vuejs.org/api/options-lifecycle.html#updated)
|
||||
`beforeUnmount` | 组件实例被卸载之前调用 [#](https://cn.vuejs.org/api/options-lifecycle.html#beforeunmount)
|
||||
`unmounted` | 组件实例被卸载之后调用 [#](https://cn.vuejs.org/api/options-lifecycle.html#unmounted)
|
||||
`errorCaptured` | 捕获了后代组件传递的错误时调用 [#](https://cn.vuejs.org/api/options-lifecycle.html#errorcaptured)
|
||||
`renderTracked` _Dev only_ | 组件渲染过程中追踪到响应式依赖时调用 [#](https://cn.vuejs.org/api/options-lifecycle.html#rendertracked)
|
||||
`renderTriggered` _Dev only_ | 响应式依赖的变更触发了组件渲染时调用 [#](https://cn.vuejs.org/api/options-lifecycle.html#rendertriggered-sup-classvt-badge-dev-only)
|
||||
`activated` | 若组件实例是 <KeepAlive> 缓存树的一部分,当组件被插入到 DOM 中时调用 [#](https://cn.vuejs.org/api/options-lifecycle.html#activated)
|
||||
`deactivated` | 若组件实例是 <KeepAlive> 缓存树的一部分,当组件从 DOM 中被移除时调用 [#](https://cn.vuejs.org/api/options-lifecycle.html#deactivated)
|
||||
`serverPrefetch` _SSR only_ | 组件实例在服务器上被渲染之前调用 [#](https://cn.vuejs.org/api/options-lifecycle.html#serverprefetch)
|
||||
|
||||
### 选项式 API - 其他杂项
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`name` | 显式声明组件展示时的名称 [#](https://cn.vuejs.org/api/options-misc.html#name)
|
||||
`inheritAttrs` | 默认的组件 `attribute` 透传行为 [#](https://cn.vuejs.org/api/options-misc.html#inheritattrs)
|
||||
`components` | [#](https://cn.vuejs.org/api/options-misc.html#components)
|
||||
`directives` | [#](https://cn.vuejs.org/api/options-misc.html#directives)
|
||||
`inheritAttrs` | 是否启用默认的组件 `attribute` 透传行为 [#](https://cn.vuejs.org/api/options-misc.html#inheritattrs)
|
||||
`components` | 注册对当前组件实例可用的组件 [#](https://cn.vuejs.org/api/options-misc.html#components)
|
||||
`directives` | 注册对当前组件实例可用的指令 [#](https://cn.vuejs.org/api/options-misc.html#directives)
|
||||
|
||||
### 选项式 API - 渲染选项
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`template` | [#](https://cn.vuejs.org/api/options-rendering.html#template)
|
||||
`render` | [#](https://cn.vuejs.org/api/options-rendering.html#render)
|
||||
`compilerOptions` | [#](https://cn.vuejs.org/api/options-rendering.html#compileroptions)
|
||||
`template` | 声明组件的字符串模板 [#](https://cn.vuejs.org/api/options-rendering.html#template)
|
||||
`render` | 编程式地创建组件虚拟 DOM 树的函数 [#](https://cn.vuejs.org/api/options-rendering.html#render)
|
||||
`compilerOptions` | 配置组件模板的运行时编译器选项 [#](https://cn.vuejs.org/api/options-rendering.html#compileroptions)
|
||||
|
||||
### 选项式 API - 组件实例
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`$data` | [#](https://cn.vuejs.org/api/component-instance.html#data)
|
||||
`$props` | [#](https://cn.vuejs.org/api/component-instance.html#props)
|
||||
`$el` | [#](https://cn.vuejs.org/api/component-instance.html#el)
|
||||
`$options` | [#](https://cn.vuejs.org/api/component-instance.html#options)
|
||||
`$parent` | [#](https://cn.vuejs.org/api/component-instance.html#parent)
|
||||
`$root` | [#](https://cn.vuejs.org/api/component-instance.html#root)
|
||||
`$slots` | [#](https://cn.vuejs.org/api/component-instance.html#slots)
|
||||
`$refs` | [#](https://cn.vuejs.org/api/component-instance.html#refs)
|
||||
`$attrs` | [#](https://cn.vuejs.org/api/component-instance.html#attrs)
|
||||
`$watch()` | [#](https://cn.vuejs.org/api/component-instance.html#watch)
|
||||
`$emit()` | [#](https://cn.vuejs.org/api/component-instance.html#emit)
|
||||
`$forceUpdate()` | [#](https://cn.vuejs.org/api/component-instance.html#forceupdate)
|
||||
`$nextTick()` | [#](https://cn.vuejs.org/api/component-instance.html#nexttick)
|
||||
`$data` | 观察的数据对象 [#](https://cn.vuejs.org/api/component-instance.html#data)
|
||||
`$props` | 组件已解析的 props 对象 [#](https://cn.vuejs.org/api/component-instance.html#props)
|
||||
`$el` | 实例管理的 DOM 根节点 [#](https://cn.vuejs.org/api/component-instance.html#el)
|
||||
`$options` | 实例的初始化选项 [#](https://cn.vuejs.org/api/component-instance.html#options)
|
||||
`$parent` | 父实例 [#](https://cn.vuejs.org/api/component-instance.html#parent)
|
||||
`$root` | 当前组件树的根实例 [#](https://cn.vuejs.org/api/component-instance.html#root)
|
||||
`$slots` | 访问被插槽分发的内容 [#](https://cn.vuejs.org/api/component-instance.html#slots)
|
||||
`$refs` | DOM 元素和组件实例 [#](https://cn.vuejs.org/api/component-instance.html#refs)
|
||||
`$attrs` | 包含了组件所有[透传 attributes](https://cn.vuejs.org/guide/components/attrs.html) [#](https://cn.vuejs.org/api/component-instance.html#attrs)
|
||||
`$watch()` | 观察 Vue 实例上的一个表达式或者一个函数计算结果的变化 [#](https://cn.vuejs.org/api/component-instance.html#watch)
|
||||
`$emit()` | 触发一个自定义事件 [#](https://cn.vuejs.org/api/component-instance.html#emit)
|
||||
`$forceUpdate()` | 强制该组件重新渲染 [#](https://cn.vuejs.org/api/component-instance.html#forceupdate)
|
||||
`$nextTick()` | 回调延迟执行 [#](https://cn.vuejs.org/api/component-instance.html#nexttick)
|
||||
|
||||
### 选项式 API - 组合选项
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`provide` | [#](https://cn.vuejs.org/api/options-composition.html#provide)
|
||||
`inject` | [#](https://cn.vuejs.org/api/options-composition.html#inject)
|
||||
`mixins` | [#](https://cn.vuejs.org/api/options-composition.html#mixins)
|
||||
`extends` | [#](https://cn.vuejs.org/api/options-composition.html#extends)
|
||||
`provide` | 提供可以被后代组件注入的值 [#](https://cn.vuejs.org/api/options-composition.html#provide)
|
||||
`inject` | 注入一个由祖先组件提供的值 [#](https://cn.vuejs.org/api/options-composition.html#inject)
|
||||
`mixins` | 接收一个混入对象的数组 [#](https://cn.vuejs.org/api/options-composition.html#mixins)
|
||||
`extends` | 要继承的“基类”组件 [#](https://cn.vuejs.org/api/options-composition.html#extends)
|
||||
|
||||
### 内置内容 - 指令
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`v-text` | [#](https://cn.vuejs.org/api/built-in-directives.html#v-text)
|
||||
`v-html` | [#](https://cn.vuejs.org/api/built-in-directives.html#v-html)
|
||||
`v-show` | [#](https://cn.vuejs.org/api/built-in-directives.html#v-show)
|
||||
`v-if` | [#](https://cn.vuejs.org/api/built-in-directives.html#v-if)
|
||||
`v-text` | 更新元素的 `textContent` [#](https://cn.vuejs.org/api/built-in-directives.html#v-text)
|
||||
`v-html` | 更新元素的 `innerHTML` [#](https://cn.vuejs.org/api/built-in-directives.html#v-html)
|
||||
`v-show` | 切换元素的 `display` css 属性 [#](https://cn.vuejs.org/api/built-in-directives.html#v-show)
|
||||
`v-if` | 有条件地渲染元素 [#](https://cn.vuejs.org/api/built-in-directives.html#v-if)
|
||||
`v-else` | [#](https://cn.vuejs.org/api/built-in-directives.html#v-else)
|
||||
`v-else-if` | [#](https://cn.vuejs.org/api/built-in-directives.html#v-else-if)
|
||||
`v-for` | [#](https://cn.vuejs.org/api/built-in-directives.html#v-for)
|
||||
`v-on` | [#](https://cn.vuejs.org/api/built-in-directives.html#v-on)
|
||||
`v-bind` | [#](https://cn.vuejs.org/api/built-in-directives.html#v-bind)
|
||||
`v-model` | [#](https://cn.vuejs.org/api/built-in-directives.html#v-model)
|
||||
`v-slot` | [#](https://cn.vuejs.org/api/built-in-directives.html#v-slot)
|
||||
`v-pre` | [#](https://cn.vuejs.org/api/built-in-directives.html#v-pre)
|
||||
`v-once` | [#](https://cn.vuejs.org/api/built-in-directives.html#v-once)
|
||||
`v-memo` | [#](https://cn.vuejs.org/api/built-in-directives.html#v-memo)
|
||||
`v-cloak` | [#](https://cn.vuejs.org/api/built-in-directives.html#v-cloak)
|
||||
`v-for` | 多次渲染元素或模板块 [#](https://cn.vuejs.org/api/built-in-directives.html#v-for)
|
||||
`v-on` | 绑定事件监听器 [#](https://cn.vuejs.org/api/built-in-directives.html#v-on)
|
||||
`v-bind` | 动态地绑定一个或多个属性 [#](https://cn.vuejs.org/api/built-in-directives.html#v-bind)
|
||||
`v-model` | 创建双向绑定 [#](https://cn.vuejs.org/api/built-in-directives.html#v-model)
|
||||
`v-slot` | 提供插槽或接收 props 的插槽 [#](https://cn.vuejs.org/api/built-in-directives.html#v-slot)
|
||||
`v-pre` | 跳过元素和它的子元素编译过程 [#](https://cn.vuejs.org/api/built-in-directives.html#v-pre)
|
||||
`v-once` | 只渲染元素和组件一次 [#](https://cn.vuejs.org/api/built-in-directives.html#v-once)
|
||||
`v-memo` _(3.2+)_ | 缓存一个模板的子树 [#](https://cn.vuejs.org/api/built-in-directives.html#v-memo)
|
||||
`v-cloak` | 保持在元素上直到实例结束编译 [#](https://cn.vuejs.org/api/built-in-directives.html#v-cloak)
|
||||
|
||||
### 内置内容 - 组件
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`<Transition>` | [#](https://cn.vuejs.org/api/built-in-components.html#transition)
|
||||
`<TransitionGroup>` | [#](https://cn.vuejs.org/api/built-in-components.html#transitiongroup)
|
||||
`<KeepAlive>` | [#](https://cn.vuejs.org/api/built-in-components.html#keepalive)
|
||||
`<Teleport>` | [#](https://cn.vuejs.org/api/built-in-components.html#teleport)
|
||||
`<Suspense>` | [#](https://cn.vuejs.org/api/built-in-components.html#suspense)
|
||||
`<Transition>` | 单个元素/组件的过渡效果 [#](https://cn.vuejs.org/api/built-in-components.html#transition)
|
||||
`<TransitionGroup>` | 多个元素/组件的过渡效果 [#](https://cn.vuejs.org/api/built-in-components.html#transitiongroup)
|
||||
`<KeepAlive>` | 缓存包裹在其中的动态切换组件 [#](https://cn.vuejs.org/api/built-in-components.html#keepalive)
|
||||
`<Teleport>` | 将其插槽内容渲染到 DOM 中的另一个位置 [#](https://cn.vuejs.org/api/built-in-components.html#teleport)
|
||||
`<Suspense>` _(Experimental)_ | 协调对组件树中嵌套的异步依赖的处理 [#](https://cn.vuejs.org/api/built-in-components.html#suspense)
|
||||
|
||||
### 内置内容 - 特殊 Attributes
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`key` | [#](https://cn.vuejs.org/api/built-in-special-attributes.html#key)
|
||||
`ref` | [#](https://cn.vuejs.org/api/built-in-special-attributes.html#ref)
|
||||
`is` | [#](https://cn.vuejs.org/api/built-in-special-attributes.html#is)
|
||||
`key` | 用在 Vue 的虚拟 DOM 算法 [#](https://cn.vuejs.org/api/built-in-special-attributes.html#key)
|
||||
`ref` | 元素或子组件注册引用信息 [#](https://cn.vuejs.org/api/built-in-special-attributes.html#ref)
|
||||
`is` | 绑定动态组件 [#](https://cn.vuejs.org/api/built-in-special-attributes.html#is)
|
||||
|
||||
### 内置内容 - 特殊元素
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`<component>` | [#](https://cn.vuejs.org/api/built-in-special-elements.html#component)
|
||||
`<slot>` | [#](https://cn.vuejs.org/api/built-in-special-elements.html#slot)
|
||||
`<component>` | 渲染一个“元组件”用于动态组件或元素 [#](https://cn.vuejs.org/api/built-in-special-elements.html#component)
|
||||
`<slot>` | 组件模板中的插槽内容出口 [#](https://cn.vuejs.org/api/built-in-special-elements.html#slot)
|
||||
|
||||
### 单文件组件 - 语法定义
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
@@ -600,14 +681,14 @@ API 参考
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`h()` | [#](https://cn.vuejs.org/api/render-function.html#h)
|
||||
`mergeProps()` | [#](https://cn.vuejs.org/api/render-function.html#mergeprops)
|
||||
`cloneVNode()` | [#](https://cn.vuejs.org/api/render-function.html#clonevnode)
|
||||
`isVNode()` | [#](https://cn.vuejs.org/api/render-function.html#isvnode)
|
||||
`resolveComponent()` | [#](https://cn.vuejs.org/api/render-function.html#resolvecomponent)
|
||||
`resolveDirective()` | [#](https://cn.vuejs.org/api/render-function.html#resolvedirective)
|
||||
`withDirectives()` | [#](https://cn.vuejs.org/api/render-function.html#withdirectives)
|
||||
`withModifiers()` | [#](https://cn.vuejs.org/api/render-function.html#withmodifiers)
|
||||
`h()` | 创建虚拟 DOM 节点 [#](https://cn.vuejs.org/api/render-function.html#h)
|
||||
`mergeProps()` | 合并多个 props 对象 [#](https://cn.vuejs.org/api/render-function.html#mergeprops)
|
||||
`cloneVNode()` | 克隆一个 vnode [#](https://cn.vuejs.org/api/render-function.html#clonevnode)
|
||||
`isVNode()` | 判断一个值是否为 vnode 类型 [#](https://cn.vuejs.org/api/render-function.html#isvnode)
|
||||
`resolveComponent()` | 按名称手动解析已注册的组件 [#](https://cn.vuejs.org/api/render-function.html#resolvecomponent)
|
||||
`resolveDirective()` | 按名称手动解析已注册的指令 [#](https://cn.vuejs.org/api/render-function.html#resolvedirective)
|
||||
`withDirectives()` | 用于给 vnode 增加自定义指令 [#](https://cn.vuejs.org/api/render-function.html#withdirectives)
|
||||
`withModifiers()` | 用于向事件处理函数添加内置 `v-on 修饰符` [#](https://cn.vuejs.org/api/render-function.html#withmodifiers)
|
||||
|
||||
### 进阶 API - 服务端渲染
|
||||
|
||||
@@ -625,17 +706,17 @@ API 参考
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`PropType<T>` | [#](https://cn.vuejs.org/api/utility-types.html#proptypet)
|
||||
`ComponentCustomProperties` | [#](https://cn.vuejs.org/api/utility-types.html#componentcustomproperties)
|
||||
`ComponentCustomOptions` | [#](https://cn.vuejs.org/api/utility-types.html#componentcustomoptions)
|
||||
`ComponentCustomProps` | [#](https://cn.vuejs.org/api/utility-types.html#componentcustomprops)
|
||||
`CSSProperties` | [#](https://cn.vuejs.org/api/utility-types.html#cssproperties)
|
||||
`PropType<T>` | 在用运行时 props 声明时给一个 prop 标注更复杂的类型定义 [#](https://cn.vuejs.org/api/utility-types.html#proptypet)
|
||||
`ComponentCustomProperties` | 增强组件实例类型以支持自定义全局属性 [#](https://cn.vuejs.org/api/utility-types.html#componentcustomproperties)
|
||||
`ComponentCustomOptions` | 扩展组件选项类型以支持自定义选项 [#](https://cn.vuejs.org/api/utility-types.html#componentcustomoptions)
|
||||
`ComponentCustomProps` | 扩展全局可用的 TSX props [#](https://cn.vuejs.org/api/utility-types.html#componentcustomprops)
|
||||
`CSSProperties` | 扩展在样式属性绑定上允许的值的类型 [#](https://cn.vuejs.org/api/utility-types.html#cssproperties)
|
||||
|
||||
### 进阶 API - 自定义渲染
|
||||
|
||||
:- | :-
|
||||
:- | :-
|
||||
`createRenderer()` | [#](https://cn.vuejs.org/api/custom-renderer.html#create-renderer)
|
||||
`createRenderer()` | 创建一个自定义渲染器 [#](https://cn.vuejs.org/api/custom-renderer.html#create-renderer)
|
||||
|
||||
另见
|
||||
---
|
||||
|
@@ -550,7 +550,6 @@ data: {
|
||||
</ul>
|
||||
```
|
||||
|
||||
|
||||
```js
|
||||
var example1 = new Vue({
|
||||
el: '#example-1',
|
||||
@@ -1195,6 +1194,7 @@ vm.selected.number // => 123
|
||||
<!--rehype:wrap-class=row-span-3-->
|
||||
|
||||
- 将 `HTML`/`CSS`/`JS` 三部分存放到一个 `Hello.vue` 文件中
|
||||
|
||||
```html
|
||||
<template>
|
||||
<p>{{ title }} World!</p>
|
||||
@@ -1222,7 +1222,9 @@ vm.selected.number // => 123
|
||||
}
|
||||
</style>
|
||||
```
|
||||
|
||||
- 使用 `Hello.vue` 组件
|
||||
|
||||
```html
|
||||
<script>
|
||||
import Vue from "vue";
|
||||
@@ -1681,7 +1683,7 @@ Vue.component('alert-box', {
|
||||
`leave-active-class` | [#](https://v2.cn.vuejs.org/v2/guide/transitions.html#自定义过渡的类名)
|
||||
`leave-to-class` _(2.1.8+)_ | [#](https://v2.cn.vuejs.org/v2/guide/transitions.html#自定义过渡的类名)
|
||||
|
||||
----
|
||||
---
|
||||
|
||||
```html
|
||||
<transition
|
||||
@@ -2026,7 +2028,6 @@ Vue 2 API 参考
|
||||
`v-on:click.passive` _(2.3.0)_ [#](https://v2.cn.vuejs.org/v2/api/#v-on) | 以 { passive: true } 模式添加侦听器
|
||||
<!--rehype:className=style-list-->
|
||||
|
||||
|
||||
### v-on (鼠标)修饰符
|
||||
|
||||
:- | :-
|
||||
|
@@ -25,7 +25,6 @@ Xcode
|
||||
`Cmd + {` | 下一个选项卡
|
||||
<!--rehype:className=shortcuts-->
|
||||
|
||||
|
||||
### 导航
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
@@ -55,7 +54,6 @@ Xcode
|
||||
`Cmd + K` | 清除控制台
|
||||
<!--rehype:className=shortcuts-->
|
||||
|
||||
|
||||
### 导航器(左侧面板)
|
||||
|
||||
快捷键 | 描述
|
||||
@@ -67,7 +65,6 @@ Xcode
|
||||
`double click` | 在新窗口中打开
|
||||
<!--rehype:className=shortcuts-->
|
||||
|
||||
|
||||
### 编辑
|
||||
|
||||
快捷键 | 描述
|
||||
@@ -83,8 +80,6 @@ Xcode
|
||||
`Cmd + Option + ]` | 下移线
|
||||
<!--rehype:className=shortcuts-->
|
||||
|
||||
|
||||
|
||||
### 实用程序(右面板)
|
||||
|
||||
快捷键 | 描述
|
||||
@@ -93,7 +88,6 @@ Xcode
|
||||
`Cmd + Option + 1-9` | 转到选项卡
|
||||
<!--rehype:className=shortcuts-->
|
||||
|
||||
|
||||
### 调试和运行
|
||||
|
||||
快捷键 | 描述
|
||||
|
@@ -118,7 +118,6 @@ $x('//a[text()="XPath"]')[0].click()
|
||||
### 运算符
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
|
||||
运算符 | 说明 | 示例
|
||||
:- | - | -
|
||||
`\|` | 计算两个节点集 | `//book \| //cd`
|
||||
@@ -137,8 +136,6 @@ $x('//a[text()="XPath"]')[0].click()
|
||||
`mod` | 模数(除法余数) | `5` mod `2`
|
||||
<!--rehype:className=show-header-->
|
||||
|
||||
|
||||
|
||||
XPath 表达式
|
||||
-----------
|
||||
|
||||
@@ -149,7 +146,6 @@ XPath 表达式
|
||||
| `//` | `ul` | `/` | `a[@id='link']` |
|
||||
| Axis | Step | Axis | Step |
|
||||
|
||||
|
||||
### 前缀
|
||||
|
||||
| 前缀 | 例子 | 意思是 |
|
||||
@@ -202,6 +198,7 @@ XPath Predicates(谓词)
|
||||
//ul[count(li) > 2]
|
||||
//ul[count(li[@class='hide']) > 0]
|
||||
```
|
||||
|
||||
```bash
|
||||
# 返回具有 `<li>` 子级的 `<ul>`
|
||||
//ul[li]
|
||||
@@ -251,6 +248,7 @@ text() # //button[text()="Submit"]
|
||||
lang(str)
|
||||
namespace-uri()
|
||||
```
|
||||
|
||||
```bash
|
||||
count() # //table[count(tr)=1]
|
||||
position() # //ol/li[position()=2]
|
||||
@@ -429,5 +427,5 @@ count(//*) # 计算所有元素
|
||||
另见
|
||||
--------
|
||||
|
||||
* [Devhints](https://devhints.io/xpath) _(devhints.io)_
|
||||
* [Xpath test bed](http://www.whitebeam.org/library/guide/TechNotes/xpathtestbed.rhtm) _(whitebeam.org)_
|
||||
- [Devhints](https://devhints.io/xpath) _(devhints.io)_
|
||||
- [Xpath test bed](http://www.whitebeam.org/library/guide/TechNotes/xpathtestbed.rhtm) _(whitebeam.org)_
|
||||
|
@@ -18,7 +18,6 @@ YAML 备忘清单
|
||||
- Ansible playbook 是 YAML 文件
|
||||
<!--rehype:className=style-round-->
|
||||
|
||||
|
||||
### 标量类型
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
@@ -350,7 +349,6 @@ set2: !!set {'one', "two"}
|
||||
|
||||
集合表示为一个映射,其中每个键都与一个空值相关联
|
||||
|
||||
|
||||
### 有序映射
|
||||
|
||||
```yaml
|
||||
@@ -450,7 +448,6 @@ YAML 参考
|
||||
| `#` | 一次性评论指示器 |
|
||||
| <code>\`@</code> | 两者都保留供将来使用 |
|
||||
|
||||
|
||||
### 核心类型(默认自动标签)
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
@@ -479,6 +476,7 @@ YAML 参考
|
||||
<!--rehype:className=cols-3 style-none-->
|
||||
|
||||
#### C
|
||||
|
||||
- `\0` (NUL)
|
||||
- `\a` (BEL)
|
||||
- `\b` (BS)
|
||||
|
@@ -394,7 +394,7 @@ yum list available --disablerepo=epel
|
||||
yum install --downloadonly vsftpd
|
||||
```
|
||||
|
||||
---
|
||||
----
|
||||
|
||||
:- | -
|
||||
:- | -
|
||||
|
15
package.json
15
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@wcj/reference",
|
||||
"version": "1.17.0",
|
||||
"version": "1.22.0",
|
||||
"description": "为开发人员分享快速参考备忘单(主要是方便自己)。",
|
||||
"author": "jaywcjlove",
|
||||
"license": "MIT",
|
||||
@@ -10,7 +10,8 @@
|
||||
"prepare": "husky install",
|
||||
"build": "node scripts/build.mjs",
|
||||
"start": "node scripts/watch.mjs",
|
||||
"prettier": "prettier --write '**/*.{mjs,css,json,prettierrc,lintstagedrc}'"
|
||||
"prettier": "prettier --write '**/*.{mjs,css,json,prettierrc,lintstagedrc}'",
|
||||
"markdownlint": "npx markdownlint-cli --fix ./docs/*.md"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -21,17 +22,25 @@
|
||||
},
|
||||
"keywords": [],
|
||||
"devDependencies": {
|
||||
"@uiw/formatter": "^1.3.3",
|
||||
"@wcj/markdown-to-html": "^2.1.2",
|
||||
"chokidar": "^3.5.3",
|
||||
"fs-extra": "^10.1.0",
|
||||
"husky": "^8.0.1",
|
||||
"lint-staged": "^13.0.3",
|
||||
"markdownlint-cli": "^0.32.2",
|
||||
"prettier": "^2.7.1",
|
||||
"recursive-readdir-files": "^2.3.0",
|
||||
"rehype-autolink-headings": "^6.1.1",
|
||||
"rehype-document": "^6.1.0",
|
||||
"rehype-parse": "^8.0.4",
|
||||
"rehype-raw": "^6.1.1",
|
||||
"rehype-rewrite": "^3.0.6",
|
||||
"rehype-slug": "^5.0.1",
|
||||
"remark-gemoji": "^7.0.1"
|
||||
"remark-gemoji": "^7.0.1",
|
||||
"unified": "^10.1.2",
|
||||
"unist-util-visit": "^4.1.1",
|
||||
"vfile": "^5.3.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.0.0"
|
||||
|
3
scripts/assets/cocoapods.svg
Normal file
3
scripts/assets/cocoapods.svg
Normal file
@@ -0,0 +1,3 @@
|
||||
<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="currentColor" height="1em" width="1em">
|
||||
<path d="M8.812 17.176c-2.968 0-4.956-2.308-4.956-5.176 0-2.705 1.776-5.176 4.91-5.176 2.407 0 3.856 1.445 4.207 3.357h3.95C16.479 6.427 13.51 3.42 8.718 3.42 3.131 3.42 0 7.523 0 12c0 4.57 3.295 8.58 8.766 8.58 4.58 0 7.549-2.822 8.18-6.272h-4.02c-.467 1.609-1.916 2.868-4.114 2.868zM24 12.068l-3.466 8.055-2.38-1.022 2.992-7.055-3.01-7.096 2.433-1.042Z"/>
|
||||
</svg>
|
After Width: | Height: | Size: 473 B |
2
scripts/assets/cpp.svg
Normal file
2
scripts/assets/cpp.svg
Normal file
@@ -0,0 +1,2 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="1em" width="1em" viewBox="0 0 187 155">
|
||||
<path fill="currentColor" d="M77.4039102,0.01171875 C104.893578,0.01171875 130.532863,14.8054453 144.312707,38.6186211 L110.875113,57.9682852 C103.978656,46.0481602 91.1520117,38.6428945 77.4039102,38.6428945 C56.1021016,38.6428945 38.7718008,55.9731953 38.7718008,77.2750039 C38.7718008,98.5758789 56.1021016,115.90618 77.4039102,115.90618 C91.1529453,115.90618 103.97959,108.500914 110.87698,96.5789219 L144.314574,115.927652 C130.53473,139.743629 104.895445,154.537355 77.4039102,154.537355 C34.800293,154.537355 0.140625,119.877688 0.140625,77.2750039 C0.140625,34.6713867 34.800293,0.01171875 77.4039102,0.01171875 Z M146.080934,64.3970117 L146.080934,72.9823398 L154.666262,72.9823398 L154.666262,81.5667344 L146.080934,81.5667344 L146.080934,90.1520625 L137.497473,90.1520625 L137.497473,81.5667344 L128.912145,81.5667344 L128.912145,72.9823398 L137.497473,72.9823398 L137.497473,64.3970117 L146.080934,64.3970117 Z M178.274047,64.3970117 L178.274047,72.9823398 L186.859375,72.9823398 L186.859375,81.5667344 L178.274047,81.5667344 L178.274047,90.1520625 L169.690586,90.1520625 L169.690586,81.5667344 L161.105258,81.5667344 L161.105258,72.9823398 L169.690586,72.9823398 L169.690586,64.3970117 L178.274047,64.3970117 Z"/></svg>
|
After Width: | Height: | Size: 1.3 KiB |
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user