Compare commits

...

108 Commits

Author SHA1 Message Date
56b4b78d7d released v1.18.0 2022-11-09 00:36:52 +08:00
f28c93b918 feat: add jq.md (#27) 2022-11-09 00:26:10 +08:00
0bfe15e4dc feat: add PostgreSQL cheatsheet. (#26) 2022-11-08 14:57:37 +08:00
c1394813bc doc: update README.md (#25) 2022-11-08 13:42:30 +08:00
06c6229cac doc: update css.md. 2022-11-08 11:35:17 +08:00
04dd94d6f8 doc: update cargo.md. 2022-11-08 00:50:27 +08:00
5f19d3feee doc: update ffmpeg.md (#24) 2022-11-07 19:52:29 +08:00
e48fd74c38 doc: update ffmpeg.md. (#24) 2022-11-07 19:50:00 +08:00
7c7f25bf9f released v1.17.0 2022-11-07 18:06:02 +08:00
2dde0c4408 doc: Update npm.md. 2022-11-07 17:40:08 +08:00
a2d7cd6e7b doc: Update npm.md. 2022-11-07 17:36:13 +08:00
10366e3317 doc: update nginx.md. 2022-11-07 16:59:00 +08:00
4bf8a55bf3 chore: add matlab logo. 2022-11-07 16:16:37 +08:00
0101ef71d0 doc: update quickreference.md. 2022-11-07 16:11:49 +08:00
aa38a0e765 doc: update css.md. 2022-11-07 16:04:39 +08:00
4a1eb6964d doc: update yum.md. 2022-11-07 11:40:32 +08:00
f6ff51be15 doc: update cargo.md. 2022-11-07 11:40:13 +08:00
6c89718254 doc: update docker.md. 2022-11-07 09:41:57 +08:00
8c79a648a4 feat: add yum.md cheatsheet. 2022-11-07 01:15:13 +08:00
f021d73b77 doc: update README.md 2022-11-06 23:39:00 +08:00
c060c36559 doc: update curl.md. 2022-11-06 23:25:58 +08:00
39aa2c4387 feat: add xcode.md cheatsheet. 2022-11-06 23:18:12 +08:00
aeca8351bd doc: update ffmpeg.md (#18) 2022-11-06 23:02:37 +08:00
d7d6b0d447 doc: update ffmpeg.md (#18) 2022-11-06 22:49:56 +08:00
4d69a0ef24 doc: update ansible.md (#23) 2022-11-06 22:18:16 +08:00
bafc15d17e released v1.16.0 2022-11-06 22:12:36 +08:00
68069fbf01 doc: Update README.md 2022-11-06 22:11:35 +08:00
ca3cf85666 doc: update README.md (#23) 2022-11-06 22:10:12 +08:00
040af8095f doc: update ansible.md (#23) 2022-11-06 22:07:24 +08:00
d1dea83330 feat: add ansible cheatsheet. (#23) 2022-11-06 20:51:51 +08:00
4503b28837 doc: update cargo.md. 2022-11-05 21:26:39 +08:00
02d0a495a6 feat: add matlab.md cheatsheet (#21). 2022-11-04 21:06:49 +08:00
c66d1c0294 chore: add .dockerignore file. 2022-11-04 13:02:33 +08:00
f2d43d65df website: fix style issue. 2022-11-04 13:02:16 +08:00
009c50760c website: Support math formula display. (#21) 2022-11-04 13:01:39 +08:00
f683ca5294 feat: add cargo cheatsheet. 2022-11-04 00:34:06 +08:00
04369f05d3 doc: update vue.md (#10) 2022-11-03 19:16:33 +08:00
ae04c01eb4 doc: update quickreference.md. 2022-11-03 16:51:53 +08:00
e66c1c57fd feat: add rust.md cheatsheet (#20). 2022-11-03 15:32:56 +08:00
c7df917009 feat: add conan.md cheatsheet. 2022-11-03 13:33:02 +08:00
a5744c23b7 doc: update README.md 2022-11-03 11:49:39 +08:00
d8ab87b0e0 feat: add default prompt changes. 2022-11-03 11:49:21 +08:00
e87ce59a88 doc: update sed.md. 2022-11-03 11:03:44 +08:00
428d8488f3 doc: update vue.md (#10). 2022-11-03 10:26:24 +08:00
e84c69f8b9 website: update style. 2022-11-03 01:20:38 +08:00
3cdc2685e6 doc: update vue.md (#10). 2022-11-03 01:09:38 +08:00
df3e04ba92 doc: update vue.md (#10). 2022-11-03 01:08:45 +08:00
4662fb8071 feat: add cmake.md cheatsheet (#19). 2022-11-03 00:27:39 +08:00
600dbc6fef feat: add gmail.md cheatsheet. 2022-11-02 23:23:20 +08:00
559fd4bd12 released v1.15.0 2022-11-02 22:19:21 +08:00
05be6476ca doc: update ffmpeg.md (#18). 2022-11-02 22:07:01 +08:00
75a0acfc5d doc: update ffmpeg.md (#18). 2022-11-02 22:03:00 +08:00
40d15647e0 doc: update ffmpeg.md (#18). 2022-11-02 21:55:42 +08:00
f19dcdf8c4 feat: add ffmpeg.md cheatsheet (#18). 2022-11-02 21:16:11 +08:00
b5f2969044 feat: add emacs.md. 2022-11-02 19:46:55 +08:00
4311bd4ed8 doc: update docker.md (#13). 2022-11-02 16:43:57 +08:00
c049ca33c4 doc: update docker.md (#13). 2022-11-02 16:36:26 +08:00
3d2c9cd978 chore: add python logo. (#13) 2022-11-02 16:32:30 +08:00
80fa7c64c3 feat: add python.md cheatsheet (#13). 2022-11-02 16:06:48 +08:00
2fbf2151b6 doc: update docker.md. 2022-11-02 13:21:08 +08:00
115a7215a5 chore: update cheatsheet-request.md. 2022-11-02 09:38:39 +08:00
a24cf740e2 doc: update README.md. 2022-11-02 01:42:17 +08:00
bd3839f648 doc: update CONTRIBUTING.md. 2022-11-02 01:41:57 +08:00
6f2da75d94 doc: update golang.md. 2022-11-02 00:26:04 +08:00
ffe4293418 doc: update quickreference.md. 2022-11-01 23:11:51 +08:00
af19ee8a8d chore: update cheatsheet-request.md. 2022-11-01 23:02:31 +08:00
a52d7d4b15 doc: update djiango.md (#16) 2022-11-01 22:46:23 +08:00
b63edf46f8 doc: update djiango.md (#16) 2022-11-01 22:24:45 +08:00
4caec0d065 feat: add djiango.md cheatsheet (#16). 2022-11-01 21:22:20 +08:00
6d602f3e89 doc: update git.md. 2022-11-01 16:35:25 +08:00
ff9d38de17 doc: update git.md. (#15) 2022-11-01 16:13:55 +08:00
ca5ddf74a0 doc: Update git.md 2022-11-01 14:34:49 +08:00
5c0f89908e doc: Update git.md 2022-11-01 14:33:46 +08:00
0fde136208 doc: Update git.md 2022-11-01 14:31:51 +08:00
8438b91448 doc: update yarn.md. 2022-11-01 10:03:14 +08:00
075b69e9ed doc: Update npm.md. 2022-11-01 09:58:29 +08:00
f14ae527b0 feat: add yarn.md cheatsheet. 2022-11-01 01:28:00 +08:00
4f68d94311 released v1.14.0 2022-11-01 00:40:33 +08:00
10d7679216 website: udpate style. 2022-11-01 00:40:00 +08:00
516ff9af69 website: update style. 2022-11-01 00:23:50 +08:00
a9896a265f feat: add java.md cheatsheet. (#12) 2022-11-01 00:20:36 +08:00
5f533d8332 chore: update issue template. (#12) 2022-10-31 16:40:12 +08:00
f60826e6da website: adjust the layout. 2022-10-31 16:38:04 +08:00
b258494776 feat: add es6.md cheatsheet. 2022-10-31 15:18:50 +08:00
8586f8a212 fix: fix show number line issue. 2022-10-31 09:45:21 +08:00
f8a706064a fix: fix show number line issue. 2022-10-31 09:25:55 +08:00
48b5d0fba3 released v1.13.0 2022-10-31 00:17:26 +08:00
18b276097d doc: update awk.md. 2022-10-31 00:16:43 +08:00
333891b7c3 doc: update awk.md. 2022-10-31 00:14:50 +08:00
e145ecc715 doc: update awk.md. 2022-10-31 00:11:50 +08:00
1e4b812bc3 doc: update awk.md. 2022-10-31 00:11:04 +08:00
909527deec feat: add awk.md cheatsheet. 2022-10-31 00:10:06 +08:00
ce02da885e doc: update css.md. 2022-10-30 23:13:21 +08:00
fb464bd4ff doc: update css.md. 2022-10-30 23:10:39 +08:00
9a2b43372a style: update website style. 2022-10-30 21:45:22 +08:00
42130cf58e released v1.12.0 2022-10-30 21:39:56 +08:00
cbc94665a5 feat: add mime.md cheatsheet. 2022-10-30 21:36:12 +08:00
2c808c7c8d feat: add iso-639-1.md cheatsheet. 2022-10-30 18:52:35 +08:00
6aa07fc077 doc: update lsof.md. 2022-10-30 17:24:27 +08:00
444f0d850c feat: update lsof.md cheatsheet. 2022-10-30 03:10:42 +08:00
8f087e03ff feat: add lsof.md cheatsheet. 2022-10-30 03:06:45 +08:00
37c9f23952 released v1.11.1 2022-10-30 02:15:36 +08:00
cb704eed88 fix: fix preview html meta issue. 2022-10-30 02:14:38 +08:00
75fece7aab feat: add vue.md cheatsheet. (#10) 2022-10-30 01:44:38 +08:00
3966175a39 doc: Update npm.md. 2022-10-30 00:54:02 +08:00
0c03059cde doc: Fix npm access public [<package>] 公开包 (#11) 2022-10-29 23:32:35 +08:00
efae1dc846 doc: add mysql.md cheatsheet. 2022-10-29 01:33:05 +08:00
4132a13a96 chore: format script code. 2022-10-29 00:24:39 +08:00
146 changed files with 15296 additions and 602 deletions

25
.dockerignore Normal file
View File

@ -0,0 +1,25 @@
.github
.husky
docs
scripts
node_modules
package-lock.json
.DS_Store
.cache
.vscode
.idea
.snap
.env
*.bak
*.tem
*.temp
#.swp
*.*~
~*.*
# IDEA
*.iml
*.ipr
*.iws

View File

@ -1,20 +1,24 @@
---
name: 🤙 备忘单请求
about: 请求添加备忘单和参考。
title: '备忘清单 请求: '
name: 🤙 备忘单请求
about: 请求添加备忘单和参考。
title: '请求添加备忘清单: '
labels: request
assignees: jaywcjlove
---
【备忘清单标题】 备忘清单
===
这是您可以在 Quick Reference 备忘清单上使用的参考!【备忘清单介绍】
您可以在这里简单的提供一些资料,方便我们在 Quick Reference 中添加您想添加的备忘清单(速查表)。
【请您在这里介绍一下工具或者语言,这很重要】
如果有一张备忘单(速查表) [`参考这里`](https://github.com/jaywcjlove/reference/blob/main/CONTRIBUTING.md) 为仓库贡献。
- [ ] 如果有一张不错的备忘单(速查表) [`参考这里`](https://github.com/jaywcjlove/reference/blob/main/CONTRIBUTING.md) 为仓库贡献。
- [ ] 如果您不方便贡献,请在下方参考资料中提供链接地址,方便共建备忘清单(速查表)
- [x] 这里为您提供了 Markdown 排版[示例教程](https://jaywcjlove.github.io/reference/docs/quickreference.html)
提供参考资料地址
----
#### 提供参考资料地址
- [参考地址 1](https://xxx.com)
- [官网地址](https://xxx.com)
提供更多参考资料有助于我们整理成备忘清单(速查表)
- 提供参考地址 https://jaywcjlove.github.io/reference
- 提供官网地址 https://jaywcjlove.github.io/reference
_⚠ 注意: 随着内容越来越多可能甚至找不到这个工具或者语言的官网请您在这里提供以便大家共同参与贡献内容_

4
.husky/pre-commit Executable file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npx --no-install lint-staged

3
.lintstagedrc Normal file
View File

@ -0,0 +1,3 @@
{
"**/*.{mjs,css,json,prettierrc,lintstagedrc}": ["prettier --write"]
}

5
.prettierignore Normal file
View File

@ -0,0 +1,5 @@
package.json
coverage
dist
build
docs

9
.prettierrc Normal file
View File

@ -0,0 +1,9 @@
{
"singleQuote": true,
"trailingComma": "all",
"printWidth": 120,
"overrides": [
{ "files": ".prettierrc", "options": { "parser": "json" } },
{ "files": ".lintstagedrc", "options": { "parser": "json" } }
]
}

View File

@ -61,6 +61,21 @@ 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-->
```
添加 `contributing` 类名,会在卡片下方添加 _`👆待完善需要您的参与`_,添加 `data-info=👆看看还缺点儿什么?`,更换默认提示文本。
```markdown
[Django](./docs/djiango.md)<!--rehype:style=background: rgb(12 75 51/var(\-\-bg\-opacity));&class=tag&data-lang=Python-->
```
添加 `class=tag&data-lang=Python` 类名和参数,会在卡片右上角标记 _`Python`_
## 本地开发
```bash

View File

@ -12,88 +12,125 @@ Quick Reference
[![Quick Reference](https://user-images.githubusercontent.com/1680273/197915058-b0aafe2c-10fc-4cc3-b54e-66329c7b4450.png)](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) 来修复它或提供更好的备忘清单,只针对【中文】用户。以下是开源天使提供的一些备忘清单和快速参考 :)。
## 正在建设中...
坑已挖,需要您的参与完善和贡献!🙏
<!--rehype:style=padding-bottom: 23px;-->
[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-->
[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-->
[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-->
## 编程
[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));-->
[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));-->
[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));-->
[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=👆看看还缺点儿什么?-->
[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-->
[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));-->
[PostgreSQL](./docs/postgres.md)<!--rehype:style=background: rgb(43 109 163/var(\-\-bg\-opacity));&class=tag&data-lang=SQL-->
[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));-->
[SwiftUI](./docs/swiftui.md)<!--rehype:style=background: rgb(10 127 247/var(\-\-bg\-opacity));&class=tag&data-lang=swift-->
[TOML](./docs/toml.md)<!--rehype:style=background: rgb(132 132 132/var(\-\-bg\-opacity));-->
[YAML](./docs/yaml.md)<!--rehype:style=background: rgb(91 163 230/var(\-\-bg\-opacity));-->
<!--rehype:class=home-card-->
## 前端
[CSS 3](./docs/css.md)<!--rehype:style=background: rgb(35 115 205/var(\-\-bg\-opacity));-->
[CSS 3](./docs/css.md)<!--rehype:style=background: rgb(35 115 205/var(\-\-bg\-opacity));&class=tag&data-lang=CSS-->
[Electron](./docs/electron.md)<!--rehype:style=background: rgb(0 72 153/var(\-\-bg\-opacity));-->
[Emmet](./docs/emmet.md)<!--rehype:style=background: rgb(122 203 23/var(\-\-bg\-opacity));-->
[ES 6](./docs/es6.md)<!--rehype:style=background: rgb(122 203 23/var(\-\-bg\-opacity));&class=tag&data-lang=JS-->
[Styled Components](./docs/styled-components.md)<!--rehype:style=background: rgb(221 60 184/var(\-\-bg\-opacity));-->
[Stylus](./docs/stylus.md)<!--rehype:style=background: rgb(109 161 63/var(\-\-bg\-opacity));-->
[Sass](./docs/sass.md)<!--rehype:style=background: rgb(207 100 154/var(\-\-bg\-opacity));-->
[Stylus](./docs/stylus.md)<!--rehype:style=background: rgb(109 161 63/var(\-\-bg\-opacity));&class=tag&data-lang=CSS-->
[Sass](./docs/sass.md)<!--rehype:style=background: rgb(207 100 154/var(\-\-bg\-opacity));&class=tag&data-lang=CSS-->
[HTML](./docs/html.md)<!--rehype:style=background: rgb(228 77 39/var(\-\-bg\-opacity));-->
[JavaScript](./docs/javascript.md)<!--rehype:style=background: rgb(203 183 31/var(\-\-bg\-opacity));-->
[Jest](./docs/jest.md)<!--rehype:style=background: rgb(153 66 91/var(\-\-bg\-opacity));-->
[Lerna](./docs/lerna.md)<!--rehype:style=background: rgb(192 132 252/var(\-\-bg\-opacity));-->
[Less.js](./docs/lessjs.md)<!--rehype:style=background: rgb(29 54 93/var(\-\-bg\-opacity));-->
[npm](./docs/npm.md)<!--rehype:style=background: rgb(203 2 0/var(\-\-bg\-opacity));-->
[package.json](./docs/package.json.md)<!--rehype:style=background: rgb(132 132 132/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-->
<!--rehype:class=home-card-->
## Nodejs
[Express.js](./docs/expressjs.md)<!--rehype:style=background: rgb(95 151 206/var(\-\-bg\-opacity));-->
[Jest](./docs/jest.md)<!--rehype:style=background: rgb(153 66 91/var(\-\-bg\-opacity));-->
[Koa.js](./docs/koajs.md)<!--rehype:style=background: rgb(95 151 206/var(\-\-bg\-opacity));-->
[Lerna](./docs/lerna.md)<!--rehype:style=background: rgb(192 132 252/var(\-\-bg\-opacity));-->
[npm](./docs/npm.md)<!--rehype:style=background: rgb(203 2 0/var(\-\-bg\-opacity));-->
[package.json](./docs/package.json.md)<!--rehype:style=background: rgb(132 132 132/var(\-\-bg\-opacity));-->
[Yarn](./docs/yarn.md)<!--rehype:style=background: rgb(33 136 182/var(\-\-bg\-opacity));-->
<!--rehype:class=home-card-->
## 工具
[nginx](./docs/nginx.md)<!--rehype:style=background: rgb(0 193 9/var(\-\-bg\-opacity));-->
[Emacs](./docs/emacs.md)<!--rehype:style=background: rgb(98 36 134/var(\-\-bg\-opacity));-->
[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(91 163 230/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));&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++-->
[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));-->
[Cron](./docs/cron.md)<!--rehype:style=background: rgb(239 68 68/var(\-\-bg\-opacity));-->
[CMake](./docs/cmake.md)<!--rehype:style=background: rgb(92 107 192/var(\-\-bg\-opacity));&class=contributing-->
[Git](./docs/git.md)<!--rehype:style=background: rgb(215 89 62/var(\-\-bg\-opacity));-->
[Grep](./docs/grep.md)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));-->
[find](./docs/find.md)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));-->
[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));-->
[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));&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));-->
[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));-->
[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));-->
[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));-->
[HTML 字符实体](./docs/html-char.md)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));-->
[HTML 字符实体](./docs/html-char.md)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));&class=tag&data-lang=HTML-->
[ISO 639-1 Language Code](./docs/iso-639-1.md)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));-->
[Emoji](./docs/emoji.md)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));-->
[MIME types](./docs/mime.md)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));-->
[Resolutions](./docs/resolutions.md)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));-->
<!--rehype:class=home-card-->

367
docs/ansible.md Normal file
View File

@ -0,0 +1,367 @@
Ansible 备忘清单
====
此快速参考备忘单提供了使用 [Ansible](https://ansible.com) 的各种方法。
入门
---
### 安装
安装命令 | 环境
:-|-
`brew install ansible` | macos
`yum install -y ansible` | centos
`pip install ansible` | python
---
- [Ansible 官方文档](https://docs.ansible.com)
### 配置位置
文件路径 | 说明
:-|-
`/etc/ansible/ansible.cfg` | 系统范围的配置
`~/ansible.cfg` | 用户特定的配置
`$pwd/ansible.cfg` | 当前目录下的配置
### Inventory文件(hosts列表)
#### 静态Inventory
`/etc/ansible/hosts`
```INI
mail.example.com
[webservers]
foo.example.com
bar.example.com
```
## 命令行(ad-hoc)
### ansible
检查Inventory是否生效
```shell
$ ansible all --list-hosts
```
ping所有目标
```shell
$ ansible all -m ping
```
ping本地(不使用SSH连接)
```shell
$ ansible all -i localhost, -e '{"ansible_connection": "local"}' -m ping
```
<!--rehype:className=wrap-text -->
本地执行命令
```shell
$ ansible all -i localhost, -e '{"ansible_connection": "local"}' -a 'hostname'
```
<!--rehype:className=wrap-text -->
获取本地主机的信息
```shell
$ ansible all -i localhost, -e '{"ansible_connection": "local"}' -m setup
```
<!--rehype:className=wrap-text -->
获取远程到本地
```shell
$ ansible target -m fetch -a "src=/tmp/seq dest=/tmp/seq"
```
<!--rehype:className=wrap-text -->
拷贝本地到远程
```shell
$ ansible target -m copy -a "src=/tmp/seq dest=/tmp/seq"
```
<!--rehype:className=wrap-text -->
### Ansible 命令帮助
<!--rehype:wrap-class=col-span-2 row-span-3-->
```bash
$ ansible
$ ansible <host-pattern> [options]
```
----
:- | -
:- | -
`-a MODULE_ARGS`, `--args=MODULE_ARGS` | 模块参数
`--ask-vault-pass` | 询问保险库密码
`-B SECONDS`, `--background=SECONDS` | 异步运行X 秒后失败 (默认=N/A)
`-C`, `--check` | 不要做任何改变;相反,尝试预测可能发生的一些变化
`-D`, `--diff` | 更改(小)文件和模板时,显示这些文件中的差异; 与 `--check` 配合使用效果很好
`-e EXTRA_VARS`, `--extra-vars=EXTRA_VARS` | 将附加变量设置为 key=value 或 YAML/JSON
`-f FORKS`, `--forks=FORKS` | 指定要使用的并行进程数 (default=5)
`-h`, `--help` | 显示此帮助信息并退出
`-i INVENTORY`, `--inventory-file=INVENTORY` | 指定清单主机路径(默认=/etc/ansible/hosts)或逗号分隔的主机列表
`-l SUBSET`, `--limit=SUBSET` | 进一步将选定主机限制为其他模式
`--list-hosts` | 输出匹配主机列表;不执行任何其他操作
`-m MODULE_NAME`, `--module-name=MODULE_NAME` | 要执行的模块名称 (default=command)
`-M MODULE_PATH`, `--module-path=MODULE_PATH` | 指定模块库的路径 (default=None)
`--new-vault-password-file=NEW_VAULT_PASSWORD_FILE` | 用于重新生成密钥的新保管库密码文件
`-o`, `--one-line` | 压缩输出
`--output=OUTPUT_FILE` | 用于加密或解密的输出文件名; 使用 - 用于标准输出
`-P POLL_INTERVAL`, `--poll=POLL_INTERVAL` | 如果使用 -B 则设置轮询间隔(default=15)
`--syntax-check` | 对 playbook 执行语法检查,但不要执行它
`-t TREE`, `--tree=TREE` | 将输出记录到此目录
`--vault-password-file=VAULT_PASSWORD_FILE` | 保险库密码文件
`-v`, `--verbose` | 详细模式(-vvv 更多,-vvvv 启用连接调试)
`--version` | 显示程序的版本号并退出
控制谁以及如何连接到主机,连接选项:
:- | -
:- | -
`-k`, `--ask-pass` | 询问连接密码
`--private-key=PRIVATE_KEY_FILE`, `--key-file=PRIVATE_KEY_FILE` | 使用此文件来验证连接
`-u REMOTE_USER`, `--user=REMOTE_USER` | 以此用户身份连接(default=None)
`-c CONNECTION`, `--connection=CONNECTION` | 要使用的连接类型 (default=smart)
`-T TIMEOUT`, `--timeout=TIMEOUT` | 以秒为单位覆盖连接超时 (default=10)
`--ssh-common-args=SSH_COMMON_ARGS` | 指定要传递给 sftp/scp/ssh 的常用参数 (e.g. ProxyCommand)
`--sftp-extra-args=SFTP_EXTRA_ARGS` | 指定仅传递给 sftp 的额外参数 (e.g. -f, -l)
`--scp-extra-args=SCP_EXTRA_ARGS` | 指定仅传递给 `scp` 的额外参数 (e.g. -l)
`--ssh-extra-args=SSH_EXTRA_ARGS` | 指定仅传递给 `ssh` 的额外参数 (e.g. -R)
控制您成为目标主机上的用户的方式和用户,特权升级选项:
:- | -
:- | -
`-s`, `--sudo` | 使用 sudo (nopasswd) 运行操作(已弃用,使用 become)
`-U SUDO_USER`, `--sudo-user=SUDO_USER` | 所需的 sudo 用户(默认=root)(已弃用,使用 become)
`-S`, `--su` | 使用 su 运行操作(已弃用,使用 become)
`-R SU_USER`, `--su-user=SU_USER` | 以该用户身份使用 su 运行操作(默认 = root)(已弃用,使用 become)
`-b`, `--become` | 使用 become 运行操作(不暗示密码提示)
`--become-method=BECOME_METHOD` | 要使用的权限提升方法(默认=sudo),有效选择:[ sudo | su | pbrun | pfexec | runas | doas | dzdo ]
`--become-user=BECOME_USER` | 以该用户身份运行操作(默认=root)
`--ask-sudo-pass` | 询问 sudo 密码(已弃用,使用 become)
`--ask-su-pass` | 询问 su 密码(已弃用,使用 become)
`-K`, `--ask-become-pass` | 要求提权密码
### Ansible Galaxy 工具
```bash
$ ansible-galaxy [delete|import|info|init|install|list|login|remove|search|setup] [--help] [options] ...
```
<!--rehype:className=wrap-text-->
---
:- | -
:- | -
`-h`, `--help` | 显示此帮助信息并退出
`-v`, `--verbose` | 详细模式(-vvv 更多,-vvvv 启用连接调试)
`--version` | 显示程序的版本号并退出
<!--rehype:className=style-list-->
---
```bash
$ ansible-galaxy search --author <AUTHOR>
$ ansible-galaxy search --platforms <PLATFORM>
$ ansible-galaxy search --galaxy-tags <TAG>
$ ansible-galaxy info <ROLE>
$ ansible-galaxy install <ROLE> -p <ROLE_DIRECTORY>
$ ansible-galaxy install -r <ROLE1> <ROLE2> <ROLE3> ...
$ ansible-galaxy list
$ ansible-galaxy remove <ROLE>
$ ansible-galaxy init <ROLE>
$ ansible-galaxy init --offline <ROLE>
```
<!--rehype:className=wrap-text-->
### ansible-doc
在本地访问文档
```bash
$ ansible-doc
$ ansible-doc [options] [module...]
```
---
:- | -
:- | -
`-h`, `--help` | 显示此帮助信息并退出
`-l`, `--list` | 列出可用模块
`-M MODULE_PATH`, `--module-path=MODULE_PATH` | 指定模块库的路径 (default=None)
`-s`, `--snippet` | 显示指定模块的剧本片段
`-v`, `--verbose` | 详细模式(-vvv 更多,-vvvv 启用连接调试)
`--version` | 显示程序的版本号并退出
<!--rehype:className=style-list-->
### ansible-vault
```bash
$ ansible-vault
$ ansible-vault [create|decrypt|edit|encrypt|rekey|view] [--help] [options] vaultfile.yml
```
---
:- | -
:- | -
`--ask-vault-pass` | 询问保险库密码
`-h`, `--help` | 显示此帮助信息并退出
`--new-vault-password-file=NEW_VAULT_PASSWORD_FILE` | 用于重新生成密钥的新保管库密码文件
`--output=OUTPUT_FILE` | 用于加密或解密的输出文件名; 使用 - 用于标准输出
`--vault-password-file=VAULT_PASSWORD_FILE` | 保险库密码文件
`-v`, `--verbose` | 详细模式(-vvv 更多,-vvvv 启用连接调试)
`--version` | 显示程序的版本号并退出
<!--rehype:className=style-list-->
### ansible-playbook
<!--rehype:wrap-class=row-span-2-->
```bash
$ ansible-playbook
$ ansible-playbook playbook.yml
```
---
:- | -
:- | -
`--ask-vault-pass` | 询问保险库密码
`-C`, `--check` | 不要做任何改变;相反,尝试预测可能发生的一些变化
`-D`, `--diff` | 更改(小)文件和模板时,显示这些文件中的差异;与 `--check` 配合使用效果很好
`-e EXTRA_VARS`, `--extra-vars=EXTRA_VARS` | 将附加变量设置为 key=value 或 YAML/JSON
`--flush-cache` | 清除事实缓存
`--force-handlers` | 即使任务失败也运行处理程序
`-f FORKS`, `--forks=FORKS` | 指定要使用的并行进程数(默认值=5
`-h`, `--help` | 显示此帮助信息并退出
`-i INVENTORY`, `--inventory-file=INVENTORY` | 指定清单主机路径(默认=/etc/ansible/hosts或逗号分隔的主机列表
`-l SUBSET`, `--limit=SUBSET` | 进一步将选定主机限制为其他模式
`--list-hosts` | 输出匹配主机列表;不执行任何其他操作
`--list-tags` | 列出所有可用的标签
`--list-tasks` | 列出所有将要执行的任务
`-M MODULE_PATH`, `--module-path=MODULE_PATH` | 指定模块库的路径(默认=无)
`--new-vault-password-file=NEW_VAULT_PASSWORD_FILE` | 用于重新生成密钥的新保管库密码文件
`--output=OUTPUT_FILE` | 用于加密或解密的输出文件名;使用 - 用于标准输出
`--skip-tags=SKIP_TAGS` | 只运行标签与这些值不匹配的播放和任务
`--start-at-task=START_AT_TASK` | 在匹配此名称的任务处启动剧本
`--step` | 一步一步:在运行前确认每个任务
`--syntax-check` | 对 playbook 执行语法检查,但不要执行它
`-t TAGS`, `--tags=TAGS` | 只运行带有这些值标记的播放和任务
`--vault-password-file=VAULT_PASSWORD_FILE` | 保险库密码文件
`-v`, `--verbose` | 详细模式(-vvv 更多,-vvvv 启用连接调试)
`--version` | 显示程序的版本号并退出
<!--rehype:className=style-list-->
连接选项:
:- | -
:- | -
`-k`, `--ask-pass` | 询问连接密码
`--private-key=PRIVATE_KEY_FILE`, `--key-file=PRIVATE_KEY_FILE` | 使用此文件来验证连接
`-u REMOTE_USER`, `--user=REMOTE_USER` | 以此用户身份连接(默认=None)
`-c CONNECTION`, `--connection=CONNECTION` | 要使用的连接类型(默认=smart)
`-T TIMEOUT`, `--timeout=TIMEOUT` | 以秒为单位覆盖连接超时(默认值 = 10)
`--ssh-common-args=SSH_COMMON_ARGS` | 指定要传递给 sftp/scp/ssh 的常用参数(例如 ProxyCommand)
`--sftp-extra-args=SFTP_EXTRA_ARGS` | 指定仅传递给 sftp 的额外参数(例如 -f、-l)
`--scp-extra-args=SCP_EXTRA_ARGS` | 指定仅传递给 scp 的额外参数(例如 -l)
`--ssh-extra-args=SSH_EXTRA_ARGS` | 指定仅传递给 ssh 的额外参数(例如 -R)
<!--rehype:className=style-list-->
特权升级选项:
:- | -
:- | -
`-s`, `--sudo` | 使用 sudo (nopasswd) 运行操作(已弃用,使用 become)
`-U SUDO_USER`, `--sudo-user=SUDO_USER` | 所需的 sudo 用户(默认=root)(已弃用使用become)
`-S`, `--su` | 使用 su 运行操作(已弃用,使用 become)
`-R SU_USER`, `--su-user=SU_USER` | 以该用户身份使用 su 运行操作(默认 = root)(已弃用使用become)
`-b`, `--become` | 使用 become 运行操作(不暗示密码提示)
`--become-method=BECOME_METHOD` | 要使用的权限提升方法(默认=sudo),有效选择:[ sudo \| su \| pbrun \| pfexec \| runas \| doas \| dzdo ]
`--become-user=BECOME_USER` | 以该用户身份运行操作(默认=root)
`--ask-sudo-pass` | 询问 sudo 密码(已弃用,使用 become)
`--ask-su-pass` | 询问 su 密码(已弃用,使用 become)
`-K`, `--ask-become-pass` | 要求提权密码
<!--rehype:className=style-list-->
### ansible-pull
<!--rehype:wrap-class=row-span-2-->
```bash
$ ansible-pull
$ ansible-pull -U <repository> [options]
```
---
:- | -
:- | -
`--accept-host-key` | 如果尚未添加,则添加 repo url 的主机密钥
`--ask-vault-pass` | 询问保险库密码
`-C CHECKOUT`, `--checkout=CHECKOUT` | 分支/标签/提交结帐。默认为存储库模块的行为。
`-d DEST`, `--directory=DEST` | 签出存储库的目录
`-e EXTRA_VARS`, `--extra-vars=EXTRA_VARS` | 将附加变量设置为 key=value 或 YAML/JSON
`-f`, `--force` | 即使无法更新存储库也运行 playbook
`--full` | 做一个完整的克隆,而不是一个浅的
`-h`, `--help` | 显示此帮助信息并退出
`-i INVENTORY`, `--inventory-file=INVENTORY` | 指定清单主机路径(默认=/etc/ansible/hosts)或逗号分隔的主机列表
`-l SUBSET`, `--limit=SUBSET` | 进一步将选定主机限制为其他模式
`--list-hosts` | 输出匹配主机列表;不执行任何其他操作
`-m MODULE_NAME`, `--module-name=MODULE_NAME` | 存储库模块名称ansible 将使用它来签出 repo。默认是 git
`-M MODULE_PATH`, `--module-path=MODULE_PATH` | 指定模块库的路径(默认=无)
`--new-vault-password-file=NEW_VAULT_PASSWORD_FILE` | 用于重新生成密钥的新保管库密码文件
`-o`, `--only-if-changed` | 仅在存储库已更新时才运行 playbook
`--output=OUTPUT_FILE` | 用于加密或解密的输出文件名;使用 - 用于标准输出
`--purge` | 剧本运行后清除结帐
`--skip-tags=SKIP_TAGS` | 只运行标签与这些值不匹配的播放和任务
`-s SLEEP`, `--sleep=SLEEP` | 在开始之前休眠随机间隔(在 0 到 n 秒之间)。这是分散 git 请求的有用方法
`-t TAGS`, `--tags=TAGS` | 只运行带有这些值标记的播放和任务
`-U URL`, `--url=URL` | 剧本存储库的 URL
`--vault-password-file=VAULT_PASSWORD_FILE` | 保险库密码文件
`-v`, `--verbose` | 详细模式(-vvv 更多,-vvvv 启用连接调试)
`--verify-commit` | 验证签出提交的 GPG 签名,如果失败则中止运行 playbook。这就需要对应的VCS模块来支持这样的操作
`--version` | 显示程序的版本号并退出
<!--rehype:className=style-list-->
连接选项:
:- | -
:- | -
`-k`, `--ask-pass` | 询问连接密码
`--private-key=PRIVATE_KEY_FILE`, `--key-file=PRIVATE_KEY_FILE` | 使用此文件来验证连接
`-u REMOTE_USER`, `--user=REMOTE_USER` | 以此用户身份连接(默认=无)
`-c CONNECTION`, `--connection=CONNECTION` | 要使用的连接类型(默认=智能)
`-T TIMEOUT`, `--timeout=TIMEOUT` | 以秒为单位覆盖连接超时(默认值 = 10)
`--ssh-common-args=SSH_COMMON_ARGS` | 指定要传递给 sftp/scp/ssh 的常用参数(例如 ProxyCommand)
`--sftp-extra-args=SFTP_EXTRA_ARGS` | 指定仅传递给 sftp 的额外参数(例如 -f、-l)
`--scp-extra-args=SCP_EXTRA_ARGS` | 指定仅传递给 scp 的额外参数(例如 -l)
`--ssh-extra-args=SSH_EXTRA_ARGS` | 指定仅传递给 ssh 的额外参数(例如 -R)
<!--rehype:className=style-list-->
特权升级选项:
:- | -
:- | -
`--ask-sudo-pass` | 询问 sudo 密码(已弃用使用become)
`--ask-su-pass` | 询问 su 密码(已弃用使用become)
`-K`, `--ask-become-pass` | 要求提权密码
<!--rehype:className=style-list-->
<!-- ### 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)

788
docs/awk.md Normal file
View File

@ -0,0 +1,788 @@
Awk 备忘清单
===
这是 [GNU awk](https://www.gnu.org/software/gawk/manual/gawk.html) 的单页快速参考备忘单,其中涵盖了常用的 `awk` 表达式和命令。
入门
------
### 试试
该程序可用于选择文件中的特定记录并对其执行操作
```shell
$ awk -F: '{print $1, $NF}' /etc/passwd
```
----
| - | - | - |
|---|---------------|---------------------------|
| | `-F:` | 冒号作为分隔符 |
| | `{...}` | awk 程序 |
| | `print` | 打印当前记录 |
| | `$1` | 第一个字段 |
| | `$NF` | 最后一个字段 |
| | `/etc/passwd` | 输入数据文件 |
### Awk 程序
```bash
BEGIN {<初始化>}
<pattern 1> {<计划动作>}
<pattern 2> {<计划动作>}
...
END {< 最后的动作 >}
```
#### 示例
```bash
awk '
BEGIN { print "\n>>>Start" }
!/(login|shutdown)/ { print NR, $0 }
END { print "<<<END\n" }
' /etc/passwd
```
### 变量
<!--rehype:wrap-class=row-span-2-->
```bash
$1 $2/$(NF-1) $3/$NF
▼ ▼ ▼
┌──────┬──────────────┬───────┐
$0/NR ▶ │ ID │ WEBSITE │ URI │
├──────┼──────────────┼───────┤
$0/NR ▶ │ 1 │ baidu.com │ awk │
├──────┼──────────────┼───────┤
$0/NR ▶ │ 2 │ google.com │ 25
└──────┴──────────────┴───────┘
```
---
```shell
# 第一个和最后一个字段
awk -F: '{print $1,$NF}' /etc/passwd
# 带行号
awk -F: '{print NR, $0}' /etc/passwd
# 倒数第二个字段
awk -F: '{print $(NF-1)}' /etc/passwd
# 自定义字符串
awk -F: '{print $1 "=" $6}' /etc/passwd
```
查看: [Awk 变量](#awk-变量)
### Awk 程序示例
<!--rehype:wrap-class=row-span-2 col-span-2-->
```shell
awk 'BEGIN {print "hello world"}' # 打印 "hello world"
awk -F: '{print $1}' /etc/passwd # -F: 指定字段分隔符
# /pattern/ 仅对匹配的模式执行操作
awk -F: '/root/ {print $1}' /etc/passwd
# BEGIN 块在开始时执行一次
awk -F: 'BEGIN { print "uid"} { print $1 }' /etc/passwd
# END 块在最后执行一次
awk -F: '{print $1} END { print "-done-"}' /etc/passwd
```
### 条件
```bash
awk -F: '$3>30 {print $1}' /etc/passwd
```
查看: [Conditions 条件](#awk-条件)
### 生成 1000 个空格
```shell
awk 'BEGIN{
while (a++ < 1000)
s=s " ";
print s
}'
```
查看: [Loops](#awk-循环)
### 数组 Arrays
```shell
awk 'BEGIN {
fruits["mango"] = "yellow";
fruits["orange"] = "orange"
for(fruit in fruits) {
print fruit " 的颜色是 " fruits[fruit]
}
}'
```
查看: [Awk 数组](#awk-数组)
### 函数 Functions
```shell
# => 5
awk 'BEGIN{print length("hello")}'
# => HELLO
awk 'BEGIN{print toupper("hello")}'
# => hel
awk 'BEGIN{print substr("hello", 1, 3)}'
```
查看: [Functions](#awk-函数)
Awk 变量
---------
### 内置变量
:- | :-
:- | :-
`$0` | 全线
`$1, $2...$NF` | 第一个,第二个……最后一个字段
`NR` | 记录总数(`N`umber of `R`ecords)
`NF` | N个字段(`N`number of `F`ields)
`OFS` | `O`utput `F`ield `S`eparator<br> 输出字段分隔符 _(default " ")_
`FS` | input `F`ield `S`eparator <br> 输入字段分隔符 _(default " ")_
`ORS` | `O`utput `R`ecord `S`eparator <br> 输出记录分隔符 _(default "\n")_
`RS` | input `R`ecord `S`eparator <br> 输入记录分隔符 _(default "\n")_
`FILENAME` | 文件名
### 表达式
<!--rehype:wrap-class=row-span-2-->
:- | :-
:- | :-
`$1 == "root"` | 第一个字段等于根
`{print $(NF-1)}` | 倒数第二个字段
`NR!=1{print $0}` | 从第 2 条记录开始
`NR > 3` | 从第 4 条记录开始
`NR == 1` | 第一次记录
`END{print NR}` | 总记录
`BEGIN{print OFMT}` | 输出格式
`{print NR, $0}` | 行号
`{print NR " " $0}` | 行号(选项卡)
`{$1 = NR; print}` | 用行号替换第一个字段
`$NF > 4` | 最后一个字段 > 4
`NR % 2 == 0` | 甚至记录
`NR==10, NR==20` | 记录 10 到 20
`BEGIN{print ARGC}` | 总 `arguments`
`ORS=NR%5?",":"\n"` | 连接记录
### 示例
<!--rehype:wrap-class=row-span-2-->
打印总和和平均值
```shell
awk -F: '{sum += $3}
END { print sum, sum/NR }
' /etc/passwd
```
打印参数
```shell
awk 'BEGIN {
for (i = 1; i < ARGC; i++)
print ARGV[i] }' a b c
```
输出字段分隔符为逗号
```shell
awk 'BEGIN { FS=":";OFS=","}
{print $1,$2,$3,$4}' /etc/passwd
```
匹配位置
```shell
awk 'BEGIN {
if (match("One Two Three", "Tw"))
print RSTART }'
```
匹配时长
```shell
awk 'BEGIN {
if (match("One Two Three", "re"))
print RLENGTH }'
```
### 仅限 GNU awk
:- | :-
:- | :-
`ENVIRON` | 环境变量
`IGNORECASE` | 忽略大小写
`CONVFMT` | 转换格式
`ERRNO` | 系统错误
`FIELDWIDTHS` | 固定宽度字段
### 环境变量
:- | :-
:- | :-
`ARGC` | 数字或参数
`ARGV` | 参数数组
`FNR` | 文件记录数(`F`ile `N`umber of `R`ecords)
`OFMT` | 数字格式 _(default "%.6g")_
`RSTART` | 字符串中的位置
`RLENGTH` | 比赛时长
`SUBSEP` | 多维数组分隔符 _(default "\034")_
`ARGIND` | 参数索引
### 定义变量
```shell
awk -v var1="Hello" -v var2="Wold" '
END {print var1, var2}
' </dev/null
```
#### 使用 shell 变量
```shell
awk -v varName="$PWD" '
END {print varName}' </dev/null
```
Awk 运算符
---------
### 运算符
:- | :-
:- | :-
`{print $1}` | 第一个字段
`$2 == "foo"` | 等于
`$2 != "foo"` | 不等于
`"foo" in array` | 在数组中
#### 正则表达式
:- | :-
:- | :-
| `/regex/` | 行匹配|
| `!/regex/` | 行不匹配|
| `$1 ~ /regex/` | 字段匹配|
| `$1 !~ /regex/` | 字段不匹配|
#### 更多条件
:- | :-
:- | :-
`($2 <= 4 \|\| $3 < 20)` | 或者
`($1 == 4 && $3 < 20)` | 和
### 运算符
#### 算术运算
- `+`
- `-`
- `*`
- `/`
- `%`
- `++`
- `--`
<!--rehype:className=cols-3 style-none-->
#### 速记作业
- `+=`
- `-=`
- `*=`
- `/=`
- `%=`
<!--rehype:className=cols-3 style-none-->
#### 比较运算符
- `==`
- `!=`
- `<`
- `>`
- `<=`
- `>=`
<!--rehype:className=cols-3 style-none-->
### 示例
```shell
awk 'BEGIN {
if ("foo" ~ "^fo+$")
print "Fooey!";
}'
```
#### 不匹配
```shell
awk 'BEGIN {
if ("boo" !~ "^fo+$")
print "Boo!";
}'
```
#### 如果在数组中
```shell
awk 'BEGIN {
assoc["foo"] = "bar";
assoc["bar"] = "baz";
if ("foo" in assoc)
print "Fooey!";
}'
```
Awk 函数
----------
### 常用功能
<!--rehype:wrap-class=col-span-2-->
函数 | 描述
:- | :-
`index(s,t)` | 字符串 `s` 中出现字符串 `t` 的位置,如果未找到则为 `0`
`length(s)` | 字符串 `s` 的长度(如果没有 `arg`,则为 `$0`)
`rand` | `0``1` 之间的随机数
`substr(s,index,len)` | 返回从索引开始的 `s``len-char` 子字符串(从 `1` 开始计数)
`srand` | 为 `rand` 设置种子并返回之前的种子
`int(x)` | 将 `x` 截断为整数值
`split(s,a,fs)` | 将字符串 `s` 拆分为数组 `a``fs` 拆分,返回 `a` 的长度
`match(s,r)` | 字符串 `s` 中出现正则表达式 `r` 的位置,如果未找到,则为 `0`
`sub(r,t,s)` | 将 `t` 替换为字符串 `s` 中第一次出现的正则表达式 `r`(如果未给出 `s`,则替换为 `$0`)
`gsub(r,t,s)` | 用 `t` 替换字符串 `s` 中所有出现的正则表达式 `r`
`system(cmd)` | 执行cmd并返回退出状态
`tolower(s)` | 字符串 `s` 转小写
`toupper(s)` | 字符串 `s` 转大写
`getline` | 将 `$0` 设置为当前输入文件中的下一个输入记录
### 用户定义函数
```shell
awk '
# 返回最小数量
function find_min(num1, num2){
if (num1 < num2)
return num1
return num2
}
# 返回最大数量
function find_max(num1, num2){
if (num1 > num2)
return num1
return num2
}
# 主功能
function main(num1, num2){
result = find_min(num1, num2)
print "Minimum =", result
result = find_max(num1, num2)
print "Maximum =", result
}
# 脚本执行从这里开始
BEGIN {
main(10, 60)
}
'
```
Awk 数组
---------
### 带索引的数组
```shell
awk 'BEGIN {
arr[0] = "foo";
arr[1] = "bar";
print(arr[0]); # => foo
delete arr[0];
print(arr[0]); # => ""
}'
```
### 带键的数组
```shell
awk 'BEGIN {
assoc["foo"] = "bar";
assoc["bar"] = "baz";
print("baz" in assoc); # => 0
print("foo" in assoc); # => 1
}'
```
### 带拆分的数组
```shell
awk 'BEGIN {
split("foo:bar:baz", arr, ":");
for (key in arr)
print arr[key];
}'
```
### 带有排序的数组
```shell
awk 'BEGIN {
arr[0] = 3
arr[1] = 2
arr[2] = 4
n = asort(arr)
for (i = 1; i <= n ; i++)
print(arr[i])
}'
```
### 多维
```shell
awk 'BEGIN {
multidim[0,0] = "foo";
multidim[0,1] = "bar";
multidim[1,0] = "baz";
multidim[1,1] = "boo";
}'
```
### 多维迭代
```shell
awk 'BEGIN {
array[1,2]=3;
array[2,3]=5;
for (comb in array) {
split(comb,sep,SUBSEP);
print sep[1], sep[2],
array[sep[1],sep[2]]
}
}'
```
Awk 条件
----------
### if-else 语句
```shell
awk -v count=2 'BEGIN {
if (count == 1)
print "Yes";
else
print "Huh?";
}'
```
#### 三元运算符
```shell
awk -v count=2 'BEGIN {
print (count==1) ? "Yes" : "Huh?";
}'
```
### 存在
```shell
awk 'BEGIN {
assoc["foo"] = "bar";
assoc["bar"] = "baz";
if ("foo" in assoc)
print "Fooey!";
}'
```
#### 不存在
```shell
awk 'BEGIN {
assoc["foo"] = "bar";
assoc["bar"] = "baz";
if ("Huh" in assoc == 0 )
print "Huh!";
}'
```
### switch
```shell
awk -F: '{
switch (NR * 2 + 1) {
case 3:
case "11":
print NR - 1
break
case /2[[:digit:]]+/:
print NR
default:
print NR + 1
case -1:
print NR * -1
}
}' /etc/passwd
```
Awk 循环
----------
### for...i
```shell
awk 'BEGIN {
for (i = 0; i < 10; i++)
print "i=" i;
}'
```
#### 1 到 100 之间的 2 的幂
```shell
awk 'BEGIN {
for (i = 1; i <= 100; i *= 2)
print i
}'
```
### for...in
```shell
awk 'BEGIN {
assoc["key1"] = "val1"
assoc["key2"] = "val2"
for (key in assoc)
print assoc[key];
}'
```
#### Arguments
```shell
awk 'BEGIN {
for (argnum in ARGV)
print ARGV[argnum];
}' a b c
```
### 示例
<!--rehype:wrap-class=row-span-3-->
#### 反向记录
```shell
awk -F: '{ x[NR] = $0 }
END {
for (i = NR; i > 0; i--)
print x[i]
}
' /etc/passwd
```
#### 反向字段
```shell
awk -F: '{
for (i = NF; i > 0; i--)
printf("%s ",$i);
print ""
}' /etc/passwd
```
#### 按记录求和
```shell
awk -F: '{
s=0;
for (i = 1; i <= NF; i++)
s += $i;
print s
}' /etc/passwd
```
#### 总结整个文件
```shell
awk -F: '
{for (i = 1; i <= NF; i++)
s += $i;
};
END{print s}
' /etc/passwd
```
### while
<!--rehype:wrap-class=row-span-2-->
```shell
awk 'BEGIN {
while (a < 10) {
print "- " " concatenation: " a
a++;
}
}'
```
#### do...while
```shell
awk '{
i = 1
do {
print $0
i++
} while (i <= 5)
}' /etc/passwd
```
### Break
```shell
awk 'BEGIN {
break_num = 5
for (i = 0; i < 10; i++) {
print i
if (i == break_num)
break
}
}'
```
### Continue
```shell
awk 'BEGIN {
for (x = 0; x <= 10; x++) {
if (x == 5 || x == 6)
continue
printf "%d ", x
}
print ""
}'
```
Awk 格式化打印
---------
### 用法
#### 右对齐
```shell
awk 'BEGIN{printf "|%10s|\n", "hello"}'
# | hello|
```
#### 左对齐
```shell
awk 'BEGIN{printf "|%-10s|\n", "hello"}'
# |hello |
```
### 通用说明符
特征符 | 描述
:- | :-
`c` | ASCII 字符
`d` | 十进制整数
`e`, `E`, `f` | 浮点格式
`o` | 无符号八进制值
`s` | 细绳
`%` | 文字百分比
### Space 空间
```shell
awk -F: '{
printf "%-10s %s\n", $1, $(NF-1)
}' /etc/passwd | head -n 3
```
输出
```shell
root /root
bin /bin
daemon /sbin
```
### Header 标题头
```shell
awk -F: 'BEGIN {
printf "%-10s %s\n", "User", "Home"
printf "%-10s %s\n", "----","----"}
{ printf "%-10s %s\n", $1, $(NF-1) }
' /etc/passwd | head -n 5
```
输出
```shell
User Home
---- ----
root /root
bin /bin
daemon /sbin
```
各种各样的
-------------
### 正则表达式元字符
- `\`
- `^`
- `$`
- `.`
- `[`
- `]`
- `|`
- `(`
- `)`
- `*`
- `+`
- `?`
<!--rehype:className=cols-3 style-none-->
### 转义序列
:- | :-
:- | :-
`\b` | 退格
`\f` | 换页
`\n` | 换行(换行)
`\r` | 回车
`\t` | 水平选项卡
`\v` | 垂直选项卡
### 运行脚本
```shell
$ cat demo.awk
#!/usr/bin/awk -f
BEGIN { x = 23 }
{ x += 2 }
END { print x }
$ awk -f demo.awk /etc/passwd
69
```
另见
--------
- [GNU awk 用户指南](https://www-zeuthen.desy.de/dv/documentation/unixguide/infohtml/gawk/gawk.html) _(www-zeuthen.desy.de)_
- [AWK cheatsheet](https://gist.github.com/Rafe/3102414) _(gist.github.com)_

431
docs/cargo.md Normal file
View File

@ -0,0 +1,431 @@
Cargo 备忘清单
===
此快速参考备忘清单 [Cargo](https://conan.io/) 提供了编译 [Rust](./rust.md) 常用命令和示例
入门
--------
### 安装/升级 Rust 和 Cargo
```bash
$ curl -sSf https://static.rust-lang.org/rustup.sh | sh
```
<!--rehype:className=wrap-text-->
在 Linux 和 macOS 系统上,这可以通过以上方命令完成
- [Cargo 开源仓库](https://github.com/rust-lang/cargo) _(github.com)_
- [Cargo 官网](https://doc.rust-lang.org/cargo) _(doc.rust-lang.org)_
- [Cargo 官网(中文)](https://www.rustwiki.org.cn/zh-CN/cargo/index.html) _(rustwiki.org.cn)_
- [Rust 社区的 crate 仓库](https://crates.io/) _(crates.io)_
### 命令说明
<!--rehype:wrap-class=col-span-2-->
:- | :-
:- | :-
`cargo version` | 显示版本信息以确认 Cargo 已安装
`cargo new` | 创建一个新项目
`cargo test` | 在项目中运行单元测试
`cargo check` | 快速编译项目,无需生成二进制文件来检查错误
`cargo fmt` | 自动格式化代码
`cargo build` | 编译一个项目
`cargo run` | 一步编译和运行项目
`cargo clippy --all-targets -- --D warnings` | Linter 检查错误
`cargo tarpaulin --ignore-tests` | 检查代码覆盖率
### 切换源
<!--rehype:wrap-class=col-span-2&style=background:#e91e63;--->
```bash
$ touch ~/.cargo/config # 添加配置文件
$ vim ~/.cargo/config # 编辑配置文件
```
配置文件 `config` 内容
```toml
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = 'tuna' # 👈 如果需要提交包注释配置源
[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"
# registry = "git://mirrors.ustc.edu.cn/crates.io-index"
```
💥 注意切换源需要删除缓存目录
```bash
$ rm -rf ~/.cargo/.package-cache # ⚠️ 删除缓存目录内容
```
### 创建新项目
<!--rehype:wrap-class=row-span-3-->
```bash
$ cargo new hello_world --bin
```
---
- `--bin` 正在制作一个二进制程序
- `--lib` 正在创建一个库(lib)
得到如下目录:
```bash
$ cd hello_world
$ tree .
.
├── Cargo.toml
└── src
└── main.rs
```
`Cargo.toml` 被称为一个 `manifest` 元清单,它包含了 `Cargo` 编译项目所需的所有元数据
```toml
[package]
name = "hello_world"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]
edition = "2018"
[dependencies]
```
入口文件 `src/main.rs`
```rust
fn main() {
println!("Hello, world!");
}
```
运行编译生成 `hello_world` 二进制文件
```bash
$ cargo build
# 文件放入 `target/release` 目录
$ cargo build --release
```
然后运行它:
```bash
$ ./target/debug/hello_world
Hello, world!
```
也可以直接使用 `cargo run`,它会自行`编译``运行`它:
```bash
$ cargo run
Running `target/hello_world`
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
```
### 编译测试
```bash
# 编译输出二进制文件,放入 `target/debug` 目录
$ cargo build
# 输出二进制文件,放入 `target/release` 目录
$ cargo build --release
$ cargo run # 编译并运行
$ cargo test # 运行您的测试
$ cargo test foo # 传递过滤器,来运行特定测试
```
### 配置目标
<!--rehype:wrap-class=row-span-2-->
```toml
[package]
# ...
[lib]
# 生成目标与库的名称. 本该默认是包名, 替换所有破折号为 下划线. (Rust `extern crate` 声明会参考该名因此该值必须是可用的有效Rust标识符)
name = "foo"
# 该字段,指向 crate 的入口(位置), 路径相对于 `Cargo.toml`.
path = "src/lib.rs"
# 一个给目标启用单元测试 的 标志. 会被 `cargo test`使用.
test = true
# 一个给目标启用文档测试 的 标志. 只与库相关, 不会影响其他部分。会被 `cargo test`使用.
doctest = true
# 一个给目标启用基准 的 标志. 会被 `cargo bench`使用.
bench = true
# 一个给目标启用文档 的 标志. 会被 `cargo doc`使用.
doc = true
# 若该目标为 编译器扩展, 那要把该字段设为 true以让 Cargo 正确编译和,可用于所有依赖项.
plugin = false
# 若该目标为 "macros 1.1" 程序宏, 那要把该字段设为 true
proc-macro = false
# 若设为 false, `cargo test` 会为 rustc 省略 `--test` 标志, 这阻止它生成测试工具 这在二进制存在,构建管理测试运行器本身的情况下,有用.
harness = true
# 若设置了,那 目标会使用一个与`[package]`配置不同的版本, 也许是,编译一个库 2018年版本或编译单元测试的2015年版本. 默认情况下所有目标都使用`[package]`中指定的版本进行编译。
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"
```
<!--rehype:className=wrap-text -->
### 配置
```toml
# 每个源都有自己的表格,名称即是表名
[source.the-source-name]
# 命令 `the-source-name` 会被 `another-source`取代
replace-with = "another-source"
# 有几种可用的源定义(接下来有所描述)
registry = "https://example.com/path/to/index"
local-registry = "path/to/registry"
directory = "path/to/vendor"
```
<!--rehype:className=wrap-text -->
更换源的配置通过完成 `.cargo/config`,上面是全套可用字段
包相关命令
---
### init/new
<!--rehype:wrap-class=row-span-2-->
创建一个新的 `cargo`
```bash
$ cargo init [options] [path]
$ cargo new [options] [path]
```
- `--bin` 创建具有二进制目标 (src/main.rs) 的包(默认行为)
- `--lib` 使用库目标 (src/lib.rs) 创建一个包
- `--edition edition` 指定要使用的 Rust 版本。默认值为 `2021`。可能的值2015、2018、2021
- `--name name` 设置包名。默认为目录名称
- `--vcs vcs` 为给定的版本控制系统git、hg、pijul 或fossil初始化一个新的 VCS 存储库,或者根本不初始化任何版本控制(无)
- `--registry registry` 限制仅发布到该注册表
<!--rehype:className=style-arrow-->
```bash
$ cargo new foo
```
### 安装包
<!--rehype:wrap-class=row-span-2-->
```bash
# 从 crates.io 安装或升级软件包:
$ cargo install ripgrep
# 在当前目录安装或重新安装包:
$ cargo install --path .
# 查看已安装包的列表:
$ cargo install --list
```
----
- `--vers version`
- `--version version` 指定要安装的版本
- `--git url` 用于安装指定 crate 的 Git URL
- `--branch branch` 从 git 安装时要使用的分支
- `--tag tag` 从 git 安装时使用的标记
- `--rev sha` 从 git 安装时使用的特定提交
- `--path path` 要安装的本地 crate 的文件系统路径
- `--list` 列出所有已安装的软件包及其版本
- `-f`, `--force` 强制覆盖现有的 crate 或二进制文件
### 搜索包
```bash
$ cargo search [options] [query...]
```
- `--limit limit` 限制结果数量(默认值10最大值100)
- `--index index` 要使用的注册表索引的 URL
- `--registry registry` 要使用的注册表的名称
```bash
$ cargo search serde
```
### 卸载包
```bash
$ cargo uninstall [options] [spec...]
```
- `-p`, `--package spec...` 要卸载的软件包
- `--bin name...` 仅卸载二进制名称
- `--root dir` 从中卸载软件包的目录
```bash
$ cargo uninstall ripgrep
```
发布命令
---
### 登录
```bash
$ cargo login [options] [token]
```
----
:-|:-
:-|:-
`--registry` | 要使用的注册表的名称
----
:-|:-
:-|:-
`-v`, `--verbose` | 启用更加详细的输出
`-q`, `--quiet` | 不输出Cargo的日志信息
`--color when` | 输出内容的颜色 `auto`, `always`, `never`
### 所有者
```bash
# 列出包的所有者:
$ cargo owner --list foo
# 邀请所有者加入包:
$ cargo owner --add username foo
# 从包中删除所有者:
$ cargo owner --remove username foo
```
----
:-|:-
:-|:-
`--token token` | 身份验证时使用的 API 令牌
`--index index` | 要使用的注册表索引的 URL
### 打包 & 发布公共选项
<!--rehype:wrap-class=row-span-3-->
选择包
- `-p spec...`, `--package spec...` Package 指定包
- `--workspace` Package 工作区中的全体成员
- `--exclude SPEC...` 排除指定包
编译选项
- `--target triple` 为指定架构执行 Package
- `--target-dir directory` 用于存放生成的工件以及中间文件的目录
特性选择
- `--features features` 传递以空格或者逗号分隔的列表,其中给出要启用的特性
- `--all-features` 为给定的包启用全部可用特性
- `--no-default-features` 不启用给定包的default特性
清单选项
- `--manifest-path path` 用于指定 Cargo.toml 文件的路径
- `--frozen`, `--locked` 这两个选项用于保证Cargo.lock文件是最新的
- `--offline` 禁止Cargo访问网络
混杂选项
- `-j N`, `--jobs N` 要并行运行的作业数量
### 打包
将本地包打包为可分发的压缩文件
```bash
$ cargo package [options]
```
----
- `-l`, `--list` 输出包中包含的文件(不实际进行打包)。
- `--no-verify` 构建包时不进行校验。
- `--no-metadata` 忽略 缺少可读的元信息(如描述信息或采用的授权协议) 时产生的警告。
- `--allow-dirty` 允许打包 在版本控制系统中仍有未提交内容 的包。
### 发布
<!--rehype:wrap-class=row-span-2-->
```bash
$ cargo publish [options]
```
发布选项
- `--dry-run` 在不上传的情况下执行所有检查
- `--token token` 身份验证时使用的 API 令牌
- `--no-verify` 不要通过构建内容来验证内容
- `--allow-dirty` 允许打包具有未提交的 VCS 更改的工作目录
- `--index index` 要使用的注册表索引的 URL
- `--registry registry` 要发布到的注册表的名称
打包选择
- `-p spec`, `--package spec` 要发布的包
### yank
从服务器的索引中删除以前发布的 crate 版本
```bash
$ cargo yank --vers 1.0.7 foo
```
- `--vers version` 要 yank 或 un-yank 的版本
- `--undo` 撤消 yank将版本放回索引中
- `--token token` 身份验证时使用的 API 令牌
- `--index index` 要使用的注册表索引的 URL
- `--registry registry` 要使用的注册表名称
另见
---
- [The Cargo Book](https://doc.rust-lang.org/stable/cargo/) _(doc.rust-lang.org)_
- [Cargo 手册 中文版](https://www.rustwiki.org.cn/zh-CN/cargo/index.html) _(rustwiki.org.cn)_

View File

@ -277,7 +277,8 @@ $ find /path -type f -exec chmod 644 {} \;
* [使用 chmod 修改文件权限](https://www.linode.com/docs/guides/modify-file-permissions-with-chmod/) _(linode.com)_
<!--rehype:ignore:start-->
### 以下是 Chmod 生成器 JS 代码(代码用于网站请忽略不要删除)
以下是 Chmod 生成器 JS 代码(代码用于网站请忽略不要删除)
---
<!--rehype:ignore:end-->
```html preview

114
docs/cmake.md Normal file
View File

@ -0,0 +1,114 @@
CMake 备忘清单
===
本清单提供了对 CMake 的入门简要概述,以及 CMake 常用示例
入门
---
### Hello CMake
CMake 是一个用于配置跨平台源代码项目应该如何配置的工具建立在给定的平台上。
```bash
├┈ CMakeLists.txt # 希望运行的 CMake 命令
╰┈ main.cpp # 带有 main 的源文件
```
在此项目上运行 `CMake` 时,系统会要求您提供二进制目录,运行 `CMake` 不会创建最终的可执行文件,而是会为 `Visual Studio``XCode``makefile` 生成项目文件。 使用这些工具构建该项目
#### CMakeLists.txt
```cmake
# 设置可以使用的最低 CMake 版本
cmake_minimum_required(VERSION 3.5)
# 设置项目名称
project (hello_cmake)
# 添加可执行文件
add_executable(hello_cmake main.cpp)
```
#### main.cpp
```c
#include <iostream>
int main(int argc, char *argv[])
{
std::cout << "Hello CMake!" << std::endl;
return 0;
}
```
#### 编译示例
```bash
$ mkdir build # 创建 build 目录
$ cd build # 进入目录
$ cmake .. # 目录的上一级目录运行命令
$ ./hello_cmake # 运行生成的 hello_cmake
Hello CMake!
```
### cmake
<!--rehype:wrap-class=col-span-2-->
生成项目构建系统
```bash
$ cmake [<options>] <path-to-source | path-to-existing-build>bash
$ cmake [<options>] -S <path-to-source> -B <path-to-build>
```
建立一个项目
```bash
$ cmake --build <dir> [<options>] [-- <build-tool-options>]
```
安装项目
```bash
$ cmake --install <dir> [<options>]
```
打开一个项目
```bash
$ cmake --open <dir>
```
运行脚本
```bash
$ cmake [-D <var>=<value>]... -P <cmake-script-file>
```
运行命令行工具
```bash
$ cmake -E <command> [<options>]
```
运行查找包工具
```bash
$ cmake --find-package [<options>]
```
运行工作流预设
```bash
$ cmake --workflow [<options>]
```
查看帮助
```bash
$ cmake --help[-<topic>]
```
另见
----
- [CMake Examples](http://ttroy50.github.io/cmake-examples/) _(ttroy50.github.io)_

228
docs/conan.md Normal file
View File

@ -0,0 +1,228 @@
Conan 备忘清单
===
这个 [Conan](https://conan.io/) 快速参考备忘清单显示了它的常用命令使用清单
入门
---
### 介绍
Conan 是开源、去中心化和多平台的软件包,管理器来创建和共享您的所有本机二进制文件
- [Conan 官网](https://conan.io/)
#### 安装
```bash
$ pip install conan
$ pip install conan --upgrade
```
初始化配置文件
```bash
$ conan config init
```
### 显示本地客户端配置
Conan 应用配置
```bash
# 查看 Conan 主目录
$ conan config home
# 显示部分或全部配置项
$ conan config get [<section>.<config>]
# 显示完整的 conan.conf 文件
$ conan config get
# 在“日志”部分显示“级别”项
$ conan config get log.level
```
配置文件的内容(例如默认值)
```bash
$ conan profile show default
```
远程存储库
```bash
$ conan remote list
```
### 添加和修改配置
安装配置集合
```bash
$ conan config install <url>
$ conan config install ./my_config.conf
```
更改单个配置值
```bash
$ conan config set general.revisions_enabled=1
```
<!--rehype:className=wrap-text -->
添加遥控器
```bash
$ conan remote add my_remote <url>
```
提供远程凭据
```bash
$ conan user -p <password> -r my_remote <username>
```
<!--rehype:className=wrap-text -->
### 显示来自 inspect 或 reference 的信息
显示 `conanfile.py` 的属性
```bash
$ conan inspect <path> -a <attribute>
```
显示 `conanfile.py` 的内容以供参考
```bash
$ conan get <reference>
```
显示 `recipe` 的依赖关系图信息
```bash
$ conan info <path_or_reference>
```
### 搜索包
<!--rehype:wrap-class=col-span-2-->
在远程搜索包
```bash
# 列出本地缓存中的包名称
$ conan search
$ conan search <package>/<revision>@<user>/<channel> # 输出取决于给出了多少包引用。
# 支持通配符
[--table=file.html] # 将输出保存在 HTML 文件中
[-r=<remote>] # 查看远程存储库(默认为本地缓存)
$ conan search mylib/1.0@user/channel # 显示本地缓存中 mylib/1.0@user/channel 的所有包
$ conan search "zlib/*" -r=all # 在所有远程中显示所有版本的 zlib
$ conan search zlib -r conan-center
# 显示包的修订:
$ conan search <package>/<revision>@<user>/<channel> --revisions
```
### 安装包
<!--rehype:wrap-class=row-span-2-->
仅使用参考安装包
```bash
$ conan install <package_reference>
```
从 conanfile 安装软件包列表
```bash
$ cat conanfile.txt
[requires]
zlib/1.2.11
$ conan install <path_to_conanfile>
```
通过生成器在构建系统中使用包
```bash
$ cat conanfile.txt
[requires]
zlib/1.2.11
[generators]
cmake_find_package
msbuild
make
```
安装需求并生成文件
```bash
$ mkdir build && cd build
$ conan install ..
```
运行您的构建系统(以下之一)
```bash
$ cmake .. && cmake --build .
$ msbuild myproject.sln
$ make
```
### 创建一个包
从模板创建配方 (conanfile.py)
```bash
$ conan new <reference> -m <template>
```
只需将配方导出到本地缓存
```bash
$ conan export <path_to_conanfile>
```
从 recipe 为一种配置创建包
也隐含地安装和导出步骤
```bash
$ conan create . -pr <profile>
```
### 检查包裹
完整打印包装配方:
```bash
$ conan get <package>/<revision>@<user>/<channel>
$ conan get boost/1.74.0
```
<!--rehype:className=wrap-text -->
包装配方的打印属性:
```bash
$ conan inspect <package>/<revision>@<user>/<channel>
$ conan inspect boost/1.74.0
```
<!--rehype:className=wrap-text -->
请参阅 [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
创建一个锁文件:
```bash
$ conan lock create <package>/conanfile.py --user=<user> --channel=<channel>
```
<!--rehype:className=wrap-text -->
`conan create``conan install` 期间使用 lockfile
```bash
$ conan <command> --lockfile conan.lock
```
查看 [conan lock](https://docs.conan.io/en/latest/reference/commands/misc/lock.html) 参考

View File

@ -262,14 +262,14 @@ p:first-child {
选择器 | 说明
:- | :-
`a[target]` | 带有 <yel>target</yel> 属性
`a[target="_blank"]` | 在新标签中打开
`a[href^="/index"]` | 以 <yel>/index</yel> 开头
`[class\|="chair"]` | 以<yel>chair</yel>开头
`[class*="chair"]` | 包含<yel>chair</yel>
`[title~="chair"]` | 包含单词 <yel>chair</yel>
`a[href$=".doc"]` | 以 <yel>.doc</yel> 结尾
`[type="button"]` | 指定类型
`a[target]` | 带有 <yel>target</yel> 属性 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/Attribute_selectors#attr)
`a[target="_blank"]` | 在新标签中打开 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/Attribute_selectors#attrvalue)
`a[href^="/index"]` | 以 <yel>/index</yel> 开头 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/Attribute_selectors#attrvalue_4)
`[class\|="chair"]` | 以<yel>chair</yel>开头 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/Attribute_selectors#attrvalue_3)
`[class*="chair"]` | 包含<yel>chair</yel> [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/Attribute_selectors#attrvalue_6)
`[title~="chair"]` | 包含单词 <yel>chair</yel> [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/Attribute_selectors#attrvalue_2)
`a[href$=".doc"]` | 以 <yel>.doc</yel> 结尾 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/Attribute_selectors#attrvalue_5)
`[type="button"]` | 指定类型 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/Attribute_selectors#attrvalue)
另见: [属性选择器](https://developer.mozilla.org/zh-CN/docs/Web/CSS/Attribute_selectors)
@ -282,6 +282,19 @@ p:first-child {
`a:hover ` | 鼠标悬停链接 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:hover)
`a:visited ` | 访问链接 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:visited)
---
```css
/* 未访问链接 */
a:link { color: blue; }
/* 已访问链接 */
a:visited { color: purple; }
/* 用户鼠标悬停 */
a:hover { background: yellow; }
/* 激活链接 */
a:active { color: red; }
```
### 伪类
选择器 | 说明
@ -297,6 +310,10 @@ p:first-child {
`div:empty` | 没有子元素的元素 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:empty)
`p:lang(en)` | 带有 en 语言属性的 P [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:lang)
`:not(span)` | 不是跨度的元素 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:not)
`:host` | shadowDOM 中选择自定义元素 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:root)
`::backdrop` | 处于全屏模式的元素样式 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/::backdrop)
`::marker` | `li` 项目符号或者数字 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/::marker)
`::file-selector-button` | type="file" `input` 按钮 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/::file-selector-button)
### 输入伪类
@ -305,6 +322,8 @@ p:first-child {
`input:checked` | 检查 `input` [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:checked)
`input:disabled` | 禁用 `input` [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:disabled)
`input:enabled` | 启用的 `input` [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:enabled)
`input:default` | 有默认值的元素 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:default)
`input:blank` | 空的输入框 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:blank)
`input:focus` | `input` 有焦点 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:focus)
`input:in-range` | 范围内的值 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:in-range)
`input:out-of-range` | `input` 值超出范围 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:out-of-range)
@ -331,6 +350,11 @@ p:first-child {
`p:nth-last-of-type(2)` | ...从后面 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:nth-last-of-type)
`p:only-of-type` | 其父级的唯一性 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:only-of-type)
`p:only-child` | 其父母的唯一孩子 [#](https://developer.mozilla.org/zh-CN/docs/Web/CSS/:only-child)
`: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)
CSS 字体
------
@ -1092,7 +1116,7 @@ grid-row-gap: length;
### minmax() 函数
<!--rehype:wrap-class=col-span-2-->
```css {.wrap}
```css
.grid {
display: grid;
grid-template-columns: 100px minmax(100px, 500px) 100px;
@ -1350,10 +1374,11 @@ a[href^="http"]:empty::before {
}
```
如果你的 `<a>` 标签里面没有内容,将 `href` 的值作为内容展示
如果 `<a>` 标签里面没有内容,将 `href` 的值作为内容展示
### 使用 :root 表示灵活类型
<!--rehype:wrap-class=row-span-2-->
响应式布局中的字体大小应该能够根据每个视口进行调整,您可以使用 `:root` 根据视口高度和宽度计算字体大小
@ -1363,7 +1388,7 @@ a[href^="http"]:empty::before {
}
```
现在您可以根据 `:root` 计算的值使用根 `em` 单位:
您可以根据 `:root` 计算的值使用根 `em` 单位:
```css
body {
@ -1371,6 +1396,40 @@ 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
div {
-webkit-user-modify:
read-write-plaintext-only;
}
```
<!--rehype:className=wrap-text -->
通过样式来控制一个元素 `div` 是否可以编辑
另见
---------

View File

@ -228,3 +228,58 @@ curl "https://{foo,bar}.com/file_[1-4].webp" --output "#1_#2.webp"
<!--rehype:className=wrap-text -->
下载一系列文件(输出`foo_file1.webp``foo_file2.webp…bar_file1_webp`等)
### 将输出重定向到文件
<!--rehype:wrap-class=col-span-3-->
```bash
$ curl http://url/file > file
```
### 基本认证
<!--rehype:wrap-class=col-span-3-->
```bash
$ curl --user username:password http://example.com/
$ curl -u username:password http://example.com/
```
### 写入文件而不是标准输出
<!--rehype:wrap-class=col-span-2-->
```bash
$ curl -o file http://url/file
$ curl --output file http://url/file
```
### 下载头信息
```bash
$ curl -I url
# 显示头信息
```
### 将输出写入名为远程文件的文件
<!--rehype:wrap-class=col-span-2-->
```bash
$ curl -o file http://url/file
$ curl --output file http://url/file
```
### 执行远程脚本
<!--rehype:wrap-class=col-span-2-->
```bash
$ curl -s http://url/myscript.sh
```
### 配置文件
<!--rehype:wrap-class=col-span-2-->
```bash
curl -K file
# 从文件中读取配置
curl --config file
$HOME/.curlrc # 类 UNIX 系统中的默认配置文件
```

775
docs/djiango.md Normal file
View File

@ -0,0 +1,775 @@
Django 备忘清单
===
Django 是 Python 的一款 Web 框架,本备忘单旨在快速理解 [Django](https://www.djangoproject.com/) 所涉及的主要概念,提供了最常用的 API 示例参考
入门
----
### 准备环境
<!--rehype:wrap-class=row-span-1-->
```bash
$ python --version
# Python 3.9.2
$ pip --version
# pip 20.2.3 from c:\python39\lib\site-packages\pip (python 3.9)
```
<!--rehype:className=wrap-text -->
如果你没有安装 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
├┈Lib
├┈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
# Unix/MacOS:
(myproject) ... $ python -m pip install Django
```
<!--rehype:className=wrap-text -->
<!--rehype:className=style-timeline-->
### 创建项目
<!--rehype:wrap-class=row-span-3-->
```bash
$ django-admin startproject myworld
```
创建了一个 `myworld` 文件夹,内容如下:
```bash
myworld
├┈ manage.py
╰┈ myworld/
├┈ __init__.py
├┈ asgi.py
├┈ settings.py
├┈ urls.py
╰┈ wsgi.py
```
运行 Django 项目
```bash
$ py manage.py runserver # Windows
$ python manage.py runserver # Unix/MacOS
```
打开一个新的浏览器窗口并在地址栏中输入 127.0.0.1:8000
### 检查 Django 版本
```bash
(myproject) C:\Users\Your Name>django-admin --version
# 4.0.3
```
### 创建应用
<!--rehype:wrap-class=row-span-2-->
```bash
$ py manage.py startapp members
```
项目中创建了一个名为 `members` 的文件夹,内容如下:
```bash
myworld
├┈ manage.py
├┈ myworld/
╰┈ members/
├┈ migrations/
┆ ╰┈ __init__.py
├┈ __init__.py
├┈ admin.py
├┈ apps.py
├┈ models.py
├┈ tests.py
╰┈ views.py
```
首先,看一下名为 `views.py` 的文件。这是我们收集发送回正确响应所需的信息的地方。
### 应用目录介绍
- `Django` 接收 URL检查 `urls.py` 文件,并调用与 URL 匹配的视图。
- 位于 `views.py` 中的视图检查相关模型。
- 模型是从 `models.py` 文件中导入的。
- 然后视图将数据发送到模板文件夹中的指定模板。
- 模板包含 `HTML` 和 `Django` 标记,并使用数据将完成的 `HTML` 内容返回给浏览器
### 视图
Django 视图是接受 `http` 请求并返回 `http` 响应的 `Python` 函数,就像 `HTML` 文档一样。
使用 `Django` 的网页充满了不同任务和任务的视图。
视图通常放在一个名为 `views.py` 的文件中,该文件位于应用程序的文件夹中。
您的 `members` 文件夹中有一个 `views.py`,如下所示:
```PY
from django.shortcuts import render
# Create your views here.
```
找到它并打开它,并将内容替换为:
```PY
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello world!")
```
这是一个关于如何将响应发送回浏览器的简单示例。
但是我们如何执行视图呢? 好吧,我们必须通过 URL 调用视图。
### URLs
在与 `views.py` 文件相同的文件夹中创建一个名为 `urls.py` 的文件,并在其中输入以下代码:
```py
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
```
刚刚创建的 `urls.py` 文件是特定于成员应用程序的。我们还必须在根目录 `myworld` 中进行一些路由。
在 `myworld` 文件夹中有一个名为 `urls.py` 的文件,打开该文件并在 `import` 语句中添加 `include` 模块,并在列表中添加一个 `path()` 函数。文件将如下所示:
```py
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('members/', include('members.urls')),
path('admin/', admin.site.urls),
]
```
如果服务器未运行,请导航到 `/myworld` 文件夹并在命令提示符下执行此命令:
```bash
$ py manage.py runserver
```
在浏览器窗口的地址栏中输入 `127.0.0.1:8000/members/`
### 模板
<!--rehype:wrap-class=row-span-2-->
在 `members` 文件夹中创建一个 `templates` 文件夹,并创建一个名为 `myfirst.html` 的 `HTML` 文件。文件结构应该是这样的:
```bash
myworld
├┈ manage.py
├┈ myworld/
╰┈ members/
╰┈ templates/
╰┈ myfirst.html
```
打开 `HTML` 文件并插入以下内容:
```html
<!DOCTYPE html>
<html>
<body>
<h1>Hello World!</h1>
<p>欢迎来到我的第一个 Django 项目!</p>
</body>
</html>
```
修改视图 `members/views.py`
```py
from django.http import HttpResponse
from django.template import loader
def index(request):
template = loader.get_template('myfirst.html')
return HttpResponse(template.render())
```
#### 更改设置
为了能够处理比“Hello World”更复杂的东西我们必须告诉 `Django` 一个新的应用程序已创建
这是在 `myworld` 文件夹的 `myworld/settings.py` 文件中完成的。查找 `INSTALLED_APPS[]` 列表并添加成员应用程序,如下所示:
```py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'members.apps.MembersConfig'
]
```
然后运行这个命令:
```bash
$ py manage.py migrate
```
通过导航到 `/myworld` 文件夹启动服务器并执行以下命令:
```bash
$ py manage.py runserver
```
在浏览器窗口的地址栏中输入 127.0.0.1:8000/members/
### 创建表(模型)
<!--rehype:wrap-class=col-span-2-->
在 `/members/` 文件夹中,打开 `models.py` 文件。要在我们的数据库中添加成员表,首先创建一个成员类,并描述其中的表字段:
```py
from django.db import models
class Members(models.Model):
firstname = models.CharField(max_length=255)
lastname = models.CharField(max_length=255)
```
然后导航到 `/myworld/` 文件夹并运行以下命令:
```bash
$ py manage.py makemigrations members
# Migrations for 'members':
# members\migrations\0001_initial.py
# - Create model Members
```
创建一个包含任何新更改的文件并将该文件存储在 `/migrations/` 文件夹中。下次运行 `py manage.py migrate` 时Django 将根据迁移文件夹中新文件的内容创建并执行一条 SQL 语句。运行迁移命令:
```bash
$ py manage.py migrate
```
从模型创建的 SQL 语句是:
```sql
CREATE TABLE "members_members" (
"id" INT NOT NULL PRIMARY KEY AUTOINCREMENT,
"firstname" varchar(255) NOT NULL,
"lastname" varchar(255) NOT NULL
);
```
Django 模板
---
### 模板变量
<!--rehype:wrap-class=col-span-2 row-span-2-->
```django
<!-- template.html -->
<h1>你好 {{ firstname }},你好吗?</h1>
```
在视图 (`views.py`) 中创建变量,上面示例中的变量 `firstname` 通过视图发送到模板:
```py
from django.http import HttpResponse
from django.template import loader
def testing(request):
template = loader.get_template('template.html')
context = {
'firstname': '狂徒张三',
}
return HttpResponse(template.render(context, request))
```
### 模板中创建变量
```django
{% with firstname="Tobias" %}
<h1>你好 {{ firstname }},你好吗?</h1>
```
### 数组循环
```django
<ul>
{% for x in mymembers %}
<li>{{ x.firstname }}</li>
{% endfor %}
</ul>
```
### 模板标签参考
<!--rehype:wrap-class=row-span-5-->
标签 | 描述
:- | :-
`autoescape` | 指定自动转义模式是打开还是关闭
`block` | 指定块部分
`comment` | 指定注释部分
`csrf_token` | 保护表单免受跨站点请求伪造
`cycle` | 指定要在循环的每个循环中使用的内容
`debug` | 指定调试信息
`extends` | 指定父模板
`filter` | 在返回之前过滤内容
`firstof` | 返回第一个非空变量
`for` | 指定一个 for 循环
`if` | 指定一个 if 语句
`ifchanged` | 仅当自上次迭代以来值已更改时才输出块<br> _(用于 for 循环)_
`include` | 指定包含的内容/模板
`load` | 从另一个库加载模板标签
`lorem` | 输出随机文本
`now` | 输出当前日期/时间
`regroup` | 按组对对象进行排序
`resetcycle` | 循环使用,重置循环
`spaceless` | 删除 HTML 标签之间的空格
`templatetag` | 输出指定的模板标签
`url` | 返回 URL 的绝对 URL 部分
`verbatim` | 指定不应由模板引擎呈现的内容
`widthratio` | 给定值和最大值之间的比率计算宽度值
`with` | 指定要在块中使用的变量
<!--rehype:className=show-header-->
### If 语句
```django
{% if greeting == 1 %}
<h1>Hello</h1>
{% elif greeting == 2 %}
<h1>Welcome</h1>
{% else %}
<h1>Goodbye</h1>
{% endif %}
```
### For 循环
<!--rehype:wrap-class=row-span-2-->
```django
{% for x in cars %}
<h1>{{ x.brand }}</h1>
<p>{{ x.model }}</p>
<p>{{ x.year }}</p>
{% endfor %}
```
数据 cars 空的展示内容:
```django
<ul>
{% for x in cars %}
<h1>{{ x.brand }}</h1>
<p>{{ x.model }}</p>
<p>{{ x.year }}</p>
{% empty %}
<li>No members</li>
{% endfor %}
</ul>
```
### 循环变量
<!--rehype:wrap-class=row-span-2-->
- `forloop.counter` 当前循环,从 1 开始
- `forloop.counter0` 当前循环,从 0 开始
- `forloop.first` 循环是否在其第一次循环中
- `forloop.last` 循环是否在其最后一次循环中
- `forloop.parentloop`
- `forloop.revcounter` 如果从末尾开始并向后计数,则以 1 结束
- `forloop.revcounter0` 如果从末尾开始并向后计数,则以 0 结束
### 过滤值
```django
<h1>你好 {{ firstname|upper }},你好吗?</h1>
```
返回带有大写字母的变量名
### 注释
<!--rehype:wrap-class=row-span-2-->
```django
<h1>欢迎大家{# 较小的注释 #}</h1>
{% comment %}
<h1>欢迎女士们先生们</h1>
{% endcomment %}
```
#### 注释描述
```django
<h1>欢迎大家{# 较小的注释 #}</h1>
{% comment "这是最初的欢迎信息" %}
<h1>欢迎女士们先生们</h1>
{% endcomment %}
```
注释允许您拥有应该被忽略的代码部分
### 双过滤值
```django
<h1>你好 {{ firstname|first|upper }},你好吗?</h1>
```
返回变量 `firstname` 的第一个字符,小写
### 过滤器标签
```django
{% filter upper %}
<h1>Hello everyone, how are you?</h1>
{% endfilter %}
```
返回内容大写
### cycle
<!--rehype:wrap-class=col-span-2 row-span-3-->
如果你想为每次循环使用新的背景颜色,你可以使用 `cycle` 标签来做到这一点
```django
<ul>
{% for x in members %}
<li style='background-color:{% cycle 'lightblue' 'pink' 'yellow' 'coral' 'grey' %}'>
{{ x.firstname }}
</li>
{% endfor %}
</ul>
```
将参数值保存在变量中,以便以后使用:
```django
<ul>
{% for x in members %}
{% cycle 'lightblue' 'pink' 'yellow' 'coral' 'grey' as bgcolor silent %}
<li style='background-color:{{ bgcolor }}'>
{{ x.firstname }}
</li>
{% endfor %}
</ul>
```
你注意到 `silent` 关键字了吗? 确保添加这个,否则参数值将在输出中显示两次
```django
<ul>
{% for x in members %}
{% cycle 'lightblue' 'pink' 'yellow' 'coral' 'grey' as bgcolor silent %}
{% if forloop.counter == 3 %}
{% resetcycle %}
{% endif %}
<li style='background-color:{{ bgcolor }}'>
{{ x.firstname }}
</li>
{% endfor %}
</ul>
```
您可以使用 `{% resetcycle %}` 标签强制循环重新开始
### 每一行添加行号
```django
{% filter upper|linenumbers %}Hello!
my name is
Emil.
What is your name?{% endfilter %}
```
返回内容`大写`并在每一行添加`行号`
### 导入模板
`footer.html`:
```django
<p>您已到达本页底部,感谢您抽出宝贵时间</p>
```
`template.html`:
```django
<h1>Hello</h1>
<p>此页面包含模板中的页脚</p>
{% include 'footer.html' %}
```
### 导入模板传入变量
`mymenu.html`:
```django
<div>HOME | {{ me }} | ABOUT | FORUM | {{ sponsor }}</div>
```
<!--rehype:className=wrap-text -->
`template.html`:
```django
{% include mymenu.html with me="张三" sponsor="Reference" %}
<h1>Welcome</h1>
<p>This is my webpage</p>
```
<!--rehype:className=wrap-text -->
### 过滤器参考
<!--rehype:wrap-class=col-span-2 row-span-2-->
Keyword | 描述
:- | :-
`add` | 添加指定的值
`addslashes` | 在任何引号字符之前添加一个斜杠,以转义字符串
`capfirst` | 返回大写的第一个字母
`center` | 使值在指定宽度的中间居中
`cut` | 删除任何指定的字符或短语
`date` | 以指定格式返回日期
`default` | 如果值为 `False`,则返回指定值
`default_if_none` | 如果值为 `None`,则返回指定的值
`dictsort` | 按给定值对字典进行排序
`dictsortreversed` | 按给定值对字典进行反向排序
`divisibleby` | 如果该值可以除以指定的数字,则返回 `True`,否则返回 `False`
`escape` | 从字符串中转义 `HTML` 代码
`escapejs` | 从字符串中转义 `JavaScript` 代码
`filesizeformat` | 将数字返回为文件大小格式
`first` | 返回对象的第一项(对于字符串,返回第一个字符)
`floatformat` | 将浮点数四舍五入到指定的小数位数,默认为一位小数
`force_escape` | 从字符串中转义 `HTML` 代码
`get_digit` | 返回数字的特定数字
`iriencode` | 将 `IRI` 转换为 `URL` 友好字符串
`join` | 将列表中的项目返回为字符串
`json_script` | 将一个对象返回为由 `<script></script>` 标签包围的 `JSON` 对象
`last` | 返回对象的最后一项(对于字符串,返回最后一个字符)
`length` | 返回对象中的项目数,或字符串中的字符数
`length_is` | 如果长度与指定的数字相同,则返回 `True`
`linebreaks` | 返回带有 `<br>` 而不是换行符和 `<p>` 而不是多个换行符的文本
`linebreaksbr` | 返回带有 `<br>` 的文本,而不是换行符
`linenumbers` | 返回每行带有行号的文本
`ljust` | 根据指定的宽度左对齐值
`lower` | 以小写字母返回文本
`make_list` | 将值转换为列表对象
`phone2numeric` | 将带字母的电话号码转换为数字电话号码
`pluralize` | 如果指定的数值不是 `1`,则在值的末尾添加一个 `s`
`pprint` |
`random` | 返回对象的随机项
`rjust` | 根据指定的宽度右对齐值
`safe` | 标记此文本是安全的,不应进行 `HTML` 转义
`safeseq` | 将对象的每个项目标记为安全且项目不应进行 `HTML` 转义
`slice` | 返回文本或对象的指定切片
`slugify` | 将文本转换为一个长字母数字小写单词
`stringformat` | 将值转换为指定格式
`striptags` | 从文本中删除 `HTML` 标记
`time` | 以指定格式返回时间
`timesince` | 返回两个日期时间之间的差
`timeuntil` | 返回两个日期时间之间的差
`title` | 文本中每个单词的第一个字符大写,所有其他字符都转换为小写
`truncatechars` | 将字符串缩短为指定数量的字符
`truncatechars_html` | 将字符串缩短为指定数量的字符,而不考虑任何 `HTML` 标记的长度
`truncatewords` | 将字符串缩短为指定数量的单词
`truncatewords_html` | 将字符串缩短为指定数量的单词,而不考虑任何 `HTML` 标记
`unordered_list` | 将对象的项目返回为无序列的 `HTML` 列表
`upper` | 以大写字母返回文本
`urlencode` | `URL` 对字符串进行编码
`urlize` | 将字符串中的任何 `URL` 作为 `HTML` 链接返回
`urlizetrunc` | 将字符串中的任何 `URL` 作为 `HTML` 链接返回,但会将链接缩短为指定的字符数
`wordcount` | 返回文本中的单词数
`wordwrap` | 以指定的字符数换行
`yesno` | 将布尔值转换为指定值
`i18n` |
`l10n` |
`tz` |
### 字段查询参考
Keyword | 描述
:- | :-
`contains` | 包含短语
`icontains` | 与包含相同,但不区分大小写
`date` | 匹配日期
`day` | 匹配日期(日期1-31)(日期)
`endswith` | 以。。结束
`iendswith` | 与 endwidth 相同,但不区分大小写
`exact` | 完全匹配
`iexact` | 与精确相同,但不区分大小写
`in` | 匹配其中一个值
`isnull` | 匹配 NULL 值
`gt` | 比...更棒
`gte` | 大于或等于
`hour` | 匹配一个小时(对于日期时间)
`lt` | 少于
`lte` | 小于或等于
`minute` | 匹配一分钟(对于日期时间)
`month` | 匹配一个月(日期)
`quarter` | 匹配一年中的一个季度 (1-4)(用于日期)
`range` | 之间的匹配
`regex` | 匹配正则表达式
`iregex` | 与正则表达式相同,但不区分大小写
`second` | 匹配一秒(对于日期时间)
`startswith` | 以 ... 开始
`istartswith` | 与 `startswith` 相同,但不区分大小写
`time` | 匹配时间(用于日期时间)
`week` | 匹配周数 (`1-53`)(用于日期)
`week_day` | 匹配一周中的某一天 (1-7) 1 是星期日
`iso_week_day` | 匹配 ISO 8601 星期几 (1-7) 1 是星期一
`year` | 匹配一年(日期)
`iso_year` | 匹配 ISO 8601 年份(日期)
添加静态文件
---
### 添加 CSS 文件
```bash {7}
myworld
├┈ manage.py
├┈ myworld/
╰┈ members/
├┈ templates/
├┈ static/
╰┈ myfirst.css
```
打开 `CSS` 文件 (`members/static/myfirst.css`) 并插入以下内容:
```css
body {
background-color: lightblue;
font-family: verdana;
}
```
修改模板 (`members/templates/template.html`) 引入 css 文件
```django {1,4}
{% load static %}
<!DOCTYPE html>
<html>
<link rel="stylesheet" href="{% static 'myfirst.css' %}">
<body>
```
<!--rehype:className=wrap-text -->
### 添加 JS 文件
```bash {7}
myworld
├┈ manage.py
├┈ myworld/
╰┈ members/
├┈ templates/
├┈ static/
╰┈ myfirst.js
```
打开 `JS` 文件 (`members/static/myfirst.js`) 并插入以下内容:
```js
function myFunction() {
alert("Hello from a static file!");
}
```
修改模板 (`members/templates/template.html`) 引入 `JS` 文件
```django {1,4,6}
{% load static %}
<!DOCTYPE html>
<html>
<script src="{% static 'myfirst.js' %}"></script>
<body>
<button onclick="myFunction()">Click me!</button>
```
<!--rehype:className=wrap-text -->
### 添加图片文件
```bash {7}
myworld
├┈ manage.py
├┈ myworld/
╰┈ members/
├┈ templates/
├┈ static/
╰┈ pineapple.jpg
```
打开 `JS` 文件 (`members/static/pineapple.jpg`) 并插入以下内容:
```js
function myFunction() {
alert("Hello from a static file!");
}
```
修改模板 (`members/templates/template.html`) 引入 `jpg` 文件
```django {1,5}
{% load static %}
<!DOCTYPE html>
<html>
<body>
<img src="{% static 'pineapple.jpg' %}">
</body>
</html>
```
<!--rehype:className=wrap-text -->
另见
----
- [Django 官网](https://www.djangoproject.com/) _(djangoproject.com)_
- [Django 教程](https://www.runoob.com/django/django-tutorial.html) _(runoob.com)_
- [Django 框架教程](http://c.biancheng.net/django/) _(biancheng.net)_
- [Django 4 中文教程](https://www.w3cschool.cn/django4/) _(w3cschool.cn)_
- [Django Tutorial](https://www.w3schools.com/django/index.php) _(w3schools.com)_

View File

@ -134,6 +134,7 @@ Docker 镜像
<!--rehype:body-class=cols-2-->
### 操控
<!--rehype:wrap-class=row-span-2-->
| `Example` | Description |
|-----------|-----------|
@ -159,6 +160,12 @@ $ docker build -f myOtherDockerfile .
$ curl example.com/remote/Dockerfile | docker build -f - .
```
### 删除 \<none> 镜像
```bash
$ docker rmi -f $(docker images | grep "none" | awk '{print $3}')
```
Docker 网络
----
<!--rehype:body-class=cols-2-->
@ -350,6 +357,306 @@ $ docker volume prune
`docker-machine scp docker-compose.yml myvm1:~` | 将文件复制到节点的主目录
`docker-machine ssh myvm1 "docker stack deploy -c <file> <app>"` | 部署应用
### docker 主要命令
:- | :-
:- | :-
`attach` | 将本地标准输入、输出和错误流附加到正在运行的容器
`build` | 从 Dockerfile 构建镜像
`commit` | 从容器的更改创建新图像
`cp` | 在容器和本地文件系统之间复制文件/文件夹
`create` | 创建一个新容器
`diff` | 检查容器文件系统上文件或目录的更改
`events` | 从服务器获取实时事件
`exec` | 在正在运行的容器中运行命令
`export` | 将容器的文件系统导出为 tar 存档
`history` | 显示图像的历史
`images` | 列出图像
`import` | 从 tarball 导入内容以创建文件系统映像
`info` | 显示系统范围的信息
`inspect` | 返回有关 Docker 对象的低级信息
`kill` | 杀死一个或多个正在运行的容器
`load` | 从 tar 存档或 STDIN 加载图像
`login` | 登录到 Docker 注册表
`logout` | 从 Docker 注册表中注销
`logs` | 获取容器的日志
`pause` | 暂停一个或多个容器内的所有进程
`port` | 列出容器的端口映射或特定映射
`ps` | 列出容器
`pull` | 从注册表中提取图像或存储库
`push` | 将图像或存储库推送到注册表
`rename` | 重命名容器
`restart` | 重启一个或多个容器
`rm` | 移除一个或多个容器
`rmi` | 移除一张或多张图片
`run` | 在新容器中运行命令
`save` | 将一个或多个图像保存到 tar 存档(默认流式传输到 STDOUT
`search` | 在 `Docker Hub` 中搜索图像
`start` | 启动一个或多个停止的容器
`stats` | 显示容器资源使用统计的实时流
`stop` | 停止一个或多个正在运行的容器
`tag` | 创建一个引用 SOURCE_IMAGE 的标记 TARGET_IMAGE
`top` | 显示容器的运行进程
`unpause` | 取消暂停一个或多个容器中的所有进程
`update` | 更新一个或多个容器的配置
`version` | 显示 Docker 版本信息
`wait` | 阻塞直到一个或多个容器停止,然后打印它们的退出代码
### docker run/create
<!--rehype:wrap-class=row-span-3-->
```bash
--add-host list # 添加自定义主机到 IP 映射 (host:ip)
-a, --attach list # 连接到 STDIN、STDOUT 或 STDERR
--blkio-weight uint16 # 块 IO相对权重介于 10 和 1000 之间,或 0 禁用(默认 0
--blkio-weight-device list # 块 IO 权重(相对设备权重)(默认 []
--cap-add list # 添加 Linux 功能
--cap-drop list # 放弃 Linux 功能
--cgroup-parent string # 容器的可选父 cgroup
--cgroupns string # 要使用的 Cgroup 命名空间(主机|私有)
# 'host': 在 Docker 主机的 cgroup 命名空间中运行容器
# 'private': 在自己的私有 cgroup 命名空间中运行容器
# '': 使用由守护进程上的
# default-cgroupns-mode 选项配置的 cgroup 命名空间(默认)
--cidfile string # 将容器 ID 写入文件
--cpu-period int # 限制 CPU CFS完全公平调度器周期
--cpu-quota int # 限制 CPU CFS完全公平调度器配额
--cpu-rt-period int # 以微秒为单位限制 CPU 实时周期
--cpu-rt-runtime int # 以微秒为单位限制 CPU 实时运行时间
-c, --cpu-shares int # CPU 份额(相对权重)
--cpus decimal # CPU 数量
--cpuset-cpus string # 允许执行的 CPU (0-3, 0,1)
--cpuset-mems string # 允许执行的 MEM (0-3, 0,1)
--device list # 将主机设备添加到容器
--device-cgroup-rule list # 将规则添加到 cgroup 允许的设备列表
--device-read-bps list # 限制设备的读取速率(每秒字节数)(默认 []
--device-read-iops list # 限制设备的读取速率(每秒 IO默认 []
--device-write-bps list # 限制设备的写入速率(每秒字节数)(默认 []
--device-write-iops list # 限制设备的写入速率(每秒 IO默认 []
--disable-content-trust # 跳过图像验证(默认为 true
--dns list # 设置自定义 DNS 服务器
--dns-option list # 设置 DNS 选项
--dns-search list # 设置自定义 DNS 搜索域
--domainname string # 容器 NIS 域名
--entrypoint string # 覆盖图像的默认入口点
-e, --env list # 设置环境变量
--env-file list # 读入环境变量文件
--expose list # 公开一个端口或一系列端口
--gpus gpu-request # 要添加到容器中的 GPU 设备(“全部”以传递所有 GPU
--group-add list # 添加其他组以加入
--health-cmd string # 运行以检查运行状况的命令
--health-interval duration # 运行检查之间的时间 (ms|s|m|h) (默认 0s)
--health-retries int # 需要报告不健康的连续失败
--health-start-period duration # 开始健康重试倒计时之前容器初始化的开始时间ms|s|m|h默认 0s
--health-timeout duration # 允许运行一项检查的最长时间 (ms|s|m|h) (默认 0s)
--help # 打印使用
-h, --hostname string # 容器主机名
--init # 在容器内运行一个 init 来转发信号并收获进程
-i, --interactive # 即使没有连接,也保持 STDIN 打开
--ip string # IPv4 地址(例如 172.30.100.104
--ip6 string # IPv6 地址例如2001:db8::33
--ipc string # 要使用的 IPC 模式
--isolation string # 容器隔离技术
--kernel-memory bytes # 内核内存限制
-l, --label list # 在容器上设置元数据
--label-file list # 读入以行分隔的标签文件
--link list # 添加到另一个容器的链接
--link-local-ip list # 容器 IPv4/IPv6 链路本地地址
--log-driver string # 容器的日志记录驱动程序
--log-opt list # 日志驱动程序选项
--mac-address string # 容器 MAC 地址(例如 92:d0:c6:0a:29:33
-m, --memory bytes # 内存限制
--memory-reservation bytes # 内存软限制
--memory-swap bytes # 交换限制等于内存加上交换:'-1' 启用无限交换
--memory-swappiness int # 调整容器内存交换0 到 100默认 -1
--mount mount # 将文件系统挂载附加到容器
--name string # 为容器分配名称
--network network # 将容器连接到网络
--network-alias list # 为容器添加网络范围的别名
--no-healthcheck # 禁用任何容器指定的 HEALTHCHECK
--oom-kill-disable # 禁用 OOM 杀手
--oom-score-adj int # 调整主机的 OOM 首选项(-1000 到 1000
--pid string # 要使用的 PID 命名空间
--pids-limit int # 调整容器 pids 限制(设置 -1 表示无限制)
--platform string # 如果服务器支持多平台,则设置平台
--privileged # 授予此容器扩展权限
-p, --publish list # 将容器的端口发布到主机
-P, --publish-all # 将所有暴露的端口发布到随机端口
--pull string # 创建前拉取图像("always"|"missing"|"never")(默认"missing")
--read-only # 将容器的根文件系统挂载为只读
--restart string # 容器退出时应用的重启策略(默认“否”)
--rm # 容器退出时自动移除
--runtime string # 用于此容器的运行时
--security-opt list # 安全选项
--shm-size bytes # /dev/shm 的大小
--stop-signal string # 停止容器的信号默认“SIGTERM”
--stop-timeout int # 停止容器的超时(以秒为单位)
--storage-opt list # 容器的存储驱动程序选项
--sysctl map # Sysctl 选项(默认 map[]
--tmpfs list # 挂载 tmpfs 目录
-t, --tty # 分配一个伪 TTY
--ulimit ulimit # ulimit 选项(默认 []
-u, --user string # 用户名或 UID格式<name|uid>[:<group|gid>]
--userns string # 要使用的用户命名空间
--uts string # 要使用的 UTS 命名空间
-v, --volume list # 绑定挂载卷
--volume-driver string # 容器的可选卷驱动程序
--volumes-from list # 从指定容器挂载卷
-w, --workdir string # 容器内的工作目录
```
`run`/`create` 大部分参数一致
### docker 全局参数
```bash
--config string # 客户端配置文件的位置(默认“~/.docker”
-c, --context string # 用于连接到守护程序的上下文的名称(
# 覆盖 DOCKER_HOST 环境变量和使用“docker context use”设置的默认上下文
-D, --debug # 启用调试模式
-H, --host list # 要连接的守护进程套接字
-l, --log-level string # 设置日志级别("debug"\|"info"\|"warn"\|"error"\|"fatal") 默认“info”
--tls # 使用 TLS 由 --tlsverify 暗示
--tlscacert string # 仅由该 CA 签署的信任证书(默认为“~/.docker/ca.pem”
--tlscert string # TLS证书文件路径默认“~/.docker/cert.pem”
--tlskey string # TLS 密钥文件的路径(默认为“~/.docker/key.pem”
--tlsverify # 使用 TLS 并验证远程
-v, --version # 打印版本信息并退出
```
### docker 管理命令
<!--rehype:wrap-class=row-span-2-->
:- | :-
:- | :-
`docker builder` | 管理构建
`docker buildx*` | Docker BuildxDocker Inc.v0.7.1
`docker compose*` | Docker ComposeDocker Inc.v2.2.3
`docker config` | 管理 Docker 配置
`docker container` | 管理容器
`docker context` | 管理上下文
`docker image` | 管理图像
`docker manifest` | 管理 Docker 镜像清单和清单列表
`docker network` | 管理网络
`docker node` | 管理 Swarm 节点
`docker plugin` | 管理插件
`docker scan*` | Docker 扫描Docker Inc.v0.16.0
`docker secret` | 管理 Docker 机密
`docker service` | 管理服务
`docker stack` | 管理 Docker 堆栈
`docker swarm` | 管理群
`docker system` | 管理 Docker
`docker trust` | 管理对 Docker 映像的信任
`docker volume` | 管理卷
### docker images
```bash
-a, --all 显示所有图像(默认隐藏中间图像)
--digests 显示摘要
-f, --filter filter 根据提供的条件过滤输出
--format string 使用 Go 模板打印漂亮的图像
--no-trunc 不要截断输出
-q, --quiet 仅显示图像 ID
```
Docker 示例
---
<!--rehype:body-class=cols-2-->
### Docker Web 管理工具 portainer
```bash
$ docker run -d --name portainer \
-p 8000:8000 \
-p 9443:9443 \
--restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $HOME/portainer:/data \
portainer/portainer-ee:latest
```
### 在线代码编辑器 Code Server
```bash
$ mkdir -p ~/.config
$ docker run -it --name code-server \
-p 127.0.0.1:8080:8080 \
-v "$HOME/.config/code-server:/home/coder/.config" \
-v "$PWD:/home/coder/project" \
-u "$(id -u):$(id -g)" \
-e "DOCKER_USER=$USER" \
codercom/code-server:latest
```
### MySQL
```bash
$ docker run --name mysql \
-p 3306:3306 \
-v $HOME/mysql/conf.d:/etc/mysql/conf.d \
-v $HOME/mysql/data:/var/lib/mysql \
-v /etc/localtime:/etc/localtime:ro \
-e MYSQL_ROOT_PASSWORD=123456 \
-d mysql:5.7.23
```
### Redis
```bash
$ docker run -d --name myredis \
-v $HOME/redis/conf:/usr/local/etc/redis \
-v /etc/localtime:/etc/localtime:ro \
redis redis-server /usr/local/etc/redis/redis.conf
```
### Nginx
```bash
$ docker run --name my-nginx \
-v "$HOME/nginx/nginx.conf:/etc/nginx/nginx.conf:ro" \
-v "$HOME/nginx/html:/usr/share/nginx/html:ro" \
-p 8080:80 \
-d nginx
```
### PostgreSQL
```bash
$ docker run --name my-postgres \
-e POSTGRES_PASSWORD=mysecretpassword \
-e PGDATA=/var/lib/postgresql/data/pgdata \
-v $HOME/nginx/mount:/var/lib/postgresql/data \
-d postgres
```
### 媒体管理工具 Dim
```bash
$ docker run --name my-dim \
-p 8000:8000/tcp \
-v $HOME/.config/dim:/opt/dim/config \
-v $HOME/dim/media:/media:ro \
-d ghcr.io/dusk-labs/dim:dev
```
[Github](https://github.com/Dusk-Labs/dim)
### Gitlab
```bash
$ docker run -d --name gitlab \
--hostname gitlab.example.com \
--publish 8443:443 --publish 8081:80 -p 2222:22 \
--restart always \
--volume $HOME/gitlab/config:/etc/gitlab \
--volume $HOME/gitlab/logs:/var/log/gitlab \
--volume $HOME/gitlab/data:/var/opt/gitlab \
-v /etc/localtime:/etc/localtime \
--shm-size 256m \
gitlab/gitlab-ce:latest
```
另见
----

526
docs/emacs.md Normal file
View File

@ -0,0 +1,526 @@
Emacs 备忘清单
====
[Emacs](https://www.gnu.org/software/emacs) 是可扩展的、可定制的、自记录的实时显示文本编辑器。此参考适用于 Emacs 27+
入门
----
### 启动 Emacs
要进入 Emacs只需输入其名称
```shell
$ emacs
```
------
:- | :-
:- | :-
`C-z` | 挂起 Emacs
`C-x` `C-c` | 永久退出 Emacs
<!--rehype:className=shortcuts-->
### 全局描述
:- | :-
:- | :-
`C-<key>` | 表示按住控件,然后按 `<key>`
`M-<key>` | 表示按 `Esc` 一次,然后按 `<key>`
<!--rehype:className=shortcuts-->
注意:本备忘单遵循上述规则
### 移动
<!--rehype:wrap-class=row-span-2-->
返回 | 向前 | 要移动的实体
:- | :- | :-
`C-b` | `C-f` | Haracter
`M-b` | `M-f` | 单词
`C-p` | `C-n` | 线
`C-a` | `C-e` | 行开头<br/>_或结尾_
`M-a` | `M-e` | 句子
`M-{` | `M-}` | 段落
`C-x` `[` | `C-x` `]` | 页
`C-M-b` | `C-M-f` | Sexp
`C-M-a` | `C-M-e` | 功能
`M-<` | `M->` | 缓冲区开始<br>_或结束_
<!--rehype:className=shortcuts show-header-->
### 案例变更
:- | :-
:- | :-
`M-u` | 大写单词
`M-l` | 小写单词
`M-c` | 大写单词
`C-x` `C-u` | 大写区域
`C-x` `C-l` | 小写区域
<!--rehype:className=shortcuts-->
### 文件
:- | :-
:- | :-
`C-x` `C-f` | 将文件读入 Emacs
`C-x` `C-s` | 将文件保存回磁盘
`C-x` `s` | 保存所有文件
`C-x` `i` | 将另一个文件的内容插入此缓冲区
`C-x` `C-v` | 将此文件替换为您的文件
`C-x` `C-w` | 将缓冲区写入指定文件
`C-x` `C-q` | 切换缓冲区的只读状态
<!--rehype:className=shortcuts-->
### 错误恢复
:- | :-
:- | :-
`C-g` | 中止部分键入或执行的命令
`M-x` 恢复会话 | 恢复因系统崩溃而丢失的文件
`C-x` `u` `C-_` `C-/` | 撤消不需要的更改
`M-x` 恢复缓冲器 | 将缓冲区恢复到其原始内容
`C-l` | 重绘垃圾屏幕
<!--rehype:className=shortcuts-->
### Transposing
<!--rehype:wrap-class=row-span-2-->
:- | :-
:- | :-
`C-t` | 转置字符
`M-t` | 转置词
`C-x` `C-t` | 转置线
`C-M-t` | 转置性别
<!--rehype:className=shortcuts-->
#### Scroll
:- | :-
:- | :-
`C-v` | 滚动到下一个屏幕
`M-v` | 滚动到上一个屏幕
`C-x` `<` | 向左滚动
`C-x` `>` | 向右滚动
`C-l` | 将当前行滚动到 <br> _center, top, bottom_
<!--rehype:className=shortcuts-->
#### 跳转
:- | :-
:- | :-
`M-g` `g` | 转到行
`M-g` `c` | 转到字符
`M-m` | 返回缩进
<!--rehype:className=shortcuts-->
### 标记
:- | :-
:- | :-
`C-@` `C-SPC` | 在标记在这里
`C-x` `C-x` | 交换点和标记
`M-@` | 设置标记 arg 单词
`M-h` | 标记段落
`C-x` `C-p` | 标记页面
`C-M-@` | 标记性
`C-M-h` | 标记功能
`C-x` `h` | 标记整个缓冲区
<!--rehype:className=shortcuts-->
### 杀死和删除
<!--rehype:wrap-class=row-span-2-->
向后 | 向前 | 要杀死的实体
:- | :- | :-
`DEL` | `C-d` | 字符 <br>_(删除)_
`M-DEL` | `M-d` | 单词
`M-0` `C-k` | `C-k` | 行 <br/> _(到结尾)_
`C-x` `DEL` | `M-k` | 句子
`M--` `C-M-k` | `C-M-k` | 性爱
<!--rehype:className=shortcuts show-header-->
#### 杀死
:- | :-
:- | :-
`C-W` | 杀死区域 C-w
`M-w` | 复制区域杀死环
`M-z` char | 杀死下一次出现的字符
`C-y` | 拉回最后一个被杀的东西
`M-y` | 用之前的杀戮替换最后的猛拉
<!--rehype:className=shortcuts-->
### 获得帮助
:- | :-
:- | :-
`C-x` `1` | 删除帮助窗口
`C-M-v` | 滚动帮助窗口
`C-h` `a` | Apropos显示匹配字符串的命令
`C-h` `k` | 描述一个键运行的功能
`C-h` `f` | 描述一个函数
`C-h` `m` | 获取特定于模式的信息
<!--rehype:className=shortcuts-->
帮助系统很简单。键入 `C-h`(或 `F1`)并按照说明进行操作。如果您是第一次使用,请键入 `C-h` `t` 以获得教程
### 多个窗口
<!--rehype:wrap-class=col-span-2 row-span-2-->
当显示两个命令时,第二个命令是用于框架而不是窗口的类似命令
:- | :- | :-
:- | :- | :-
`C-x` `5` `1` | `C-x` `1` | 删除所有其他窗口
`C-x` `5` `2` | `C-x` `2` | 拆分窗口,上方和下方
`C-x` `5` `0` | `C-x` `0` | 删除此窗口
<!--rehype:className=shortcuts-->
:- | :- | :-
:- | :- | :-
&nbsp; | `C-x` `3` | 拆分窗口,并排
&nbsp; | `C-M-v` | 滚动其他窗口
<!--rehype:className=shortcuts-->
:- | :- | :-
:- | :- | :-
`C-x` `5` `o` | `C-x` `o` | 将光标切换到另一个窗口
`C-x` `5` `b` | `C-x` `4` `b` | 在其他窗口中选择缓冲区
`C-x` `5` `C-o` | `C-x` `4` `C-o` | 在其他窗口中显示缓冲区
`C-x` `5` `f` | `C-x` `4` `f` | 在其他窗口中查找文件
`C-x` `5` `r` | `C-x` `4` `r` | 在其他窗口中以只读方式查找文件
`C-x` `5` `d` | `C-x` `4` `d` | 在其他窗口中运行 Dired
`C-x` `5` `.` | `C-x` `4` `.` | 在其他窗口中查找标签
<!--rehype:className=shortcuts-->
:- | :- | :-
:- | :- | :-
&nbsp; | `C-x` `^` | 让窗户变高
&nbsp; | `C-x` `{` | 缩小窗口
&nbsp; | `C-x` `}` | 让窗口变宽
<!--rehype:className=shortcuts-->
### 格式化
:- | :-
:- | :-
`TAB` | 缩进当前行(取决于模式)
`C-M-\` | 缩进区域(取决于模式)
`C-M-q` | 缩进 sexp取决于模式
`C-x` `TAB` | 缩进区域刚性 arg 列
`M-;` | 缩进评论
`C-o` | 在点后插入换行符
`C-M-o` | 将其余行垂直向下移动
`C-x` `C-o` | 删除点周围的空行
`M-^` | 与上一个加入行(带 arg下一个
`M-\` | 删除点周围的所有空白
`M-SPC` | 在点上正好放一个空格
`M-q` | 填写段落
`C-x` `f` | 将填充列设置为 arg
`C-x` `.` | 设置每行开头的前缀
`M-o` | 设置面
<!--rehype:className=shortcuts-->
### 信息
<!--rehype:wrap-class=row-span-3-->
:- | :-
:- | :-
`C-h` `i` | 输入信息文档阅读器
`C-h` `S` | 在 Info 中查找指定的函数或变量
<!--rehype:className=shortcuts-->
#### 在节点内移动
:- | :-
:- | :-
`SPC` | 向前滚动
`DEL` | 反向滚动
`b` | 节点的开始
<!--rehype:className=shortcuts-->
#### 在节点之间移动
:- | :-
:- | :-
`n` | 下一个节点
`p` | 上一个节点
`u` | 提升
`m` | 按名称选择菜单项
`n` | 按编号 (19) 选择第 n 个菜单项
`f` | 遵循交叉引用(用 l 返回)
`l` | 返回您看到的最后一个节点
`d` | 返回目录节点
`t` | 转到信息文件的顶部节点
`g` | 按名称转到任何节点
<!--rehype:className=shortcuts-->
#### 其他
:- | :-
:- | :-
`h` | 运行信息教程
`i` | 在索引中查找主题
`s` | 搜索节点以查找正则表达式
`q` | 退出信息
<!--rehype:className=shortcuts-->
### 小缓冲区
<!--rehype:wrap-class=row-span-2-->
以下键在 `minibuffer` 中定义
:- | :-
:- | :-
`TAB` | 尽可能完成
`SPC` | 最多完成一个单词
`RET` | 完成并执行
`?` | 显示可能的完成
`M-p` | 获取先前的 `minibuffer` 输入
`M-n` | 获取稍后的 `minibuffer` 输入或默认值
`M-r` | 正则表达式向后搜索历史
`M-s` | 正则表达式向前搜索历史
`C-g` | 中止命令
<!--rehype:className=shortcuts-->
键入 `C-x` `ESC` `ESC` 以编辑并重复使用 `minibuffer` 的最后一个命令。键入 `F10` 以激活文本终端上的菜单栏项
### 标签
:- | :-
:- | :-
`M-.` | 查找标签(定义)
`C-u` `M-.` | 查找标签的下一个出现
`M-x` 访问标签表 | 指定一个新的标签文件
`M-x` 标签搜索 | 正则表达式搜索标签表中的所有文件
`M-x` 标签查询替换 | 对所有文件运行查询替换
`M-,` | 继续最后一个标签搜索或查询替换
<!--rehype:className=shortcuts-->
### 缓冲器
:- | :-
:- | :-
`C-x` `b` | 选择另一个缓冲区
`C-x` `C-b` | 列出所有缓冲区
`C-x` `k` | 杀死一个缓冲区
<!--rehype:className=shortcuts-->
### 矩形
:- | :-
:- | :-
`C-x` `r` `r` | 复制矩形进行注册
`C-x` `r` `k` | 杀死矩形
`C-x` `r` `y` | 拉长矩形
`C-x` `r` `o` | 打开矩形,向右移动文本
`C-x` `r` `c` | 空白矩形
`C-x` `r` `t` | 用字符串为每一行添加前缀
<!--rehype:className=shortcuts-->
### 键盘宏
:- | :-
:- | :-
`C-x` `(` | 开始定义键盘宏
`C-x` `)` | 结束键盘宏定义
`C-x` `e` | 执行最后定义的键盘宏
`C-u` `C-x` `(` | 附加到最后一个键盘宏
`M-x` name-last-kbd-macro | 命名最后一个键盘宏
`M-x` insert-kbd-macro | 在缓冲区中插入 Lisp 定义
<!--rehype:className=shortcuts-->
Emacs 搜索
------
### 正则表达式(常用)
<!--rehype:wrap-class=row-span-2-->
:- | :-
:- | :-
`.` `(dot)` | 除换行符外的任何单个字符
`*` | 零次或多次重复
`+` | 一次或多次重复
`?` | 零次或一次重复
`\` | 引用特殊字符
`\c` | 引用正则表达式特殊字符 c
`\|` | 替代(“或”)
`\(...\)` | 分组
`\(:?...\)` | 害羞的分组
`\(:NUM...\)` | 显式编号分组
`\n` | 与第 n 组相同的文本
`\b` | 在断字时
`\B` | 不在断字
### 正则表达式(条目)
开始 | 结束 | 实体
:- | :- | :-
`^` | `$` | 行
`\<` | `\>` | 单词
`\_<` | `\_>` | 象征
`\` | `\` | 缓冲
<!--rehype:className=show-header-->
### 正则表达式(冲突)
这些 | 其他 | class
:- | :- | :-
`[...]` | `[^...]` | 显式集
`\w` | `\W` | 单词语法字符
`\sc` | `\Sc` | 具有语法 c 的字符
`\cc` | `\Cc` | 类别 c 的字符
<!--rehype:className=show-header-->
### 增量搜索
:- | :-
:- | :-
`C-s` | 向前搜索
`C-r` | 向后搜索
`C-M-s` | 正则表达式搜索
`C-M-r` | 反向正则表达式搜索
`M-p` | 选择上一个搜索字符串
`M-n` | 选择下一个稍后搜索字符串
`RET` | 退出增量搜索
`DEL` | 最后一个字符的撤消效果
`C-g` | 中止当前搜索
<!--rehype:className=shortcuts-->
再次使用 `C-s``C-r` 在任一方向重复搜索。 如果 Emacs 仍在搜索,`C-g` 只取消不匹配的部分
### 查询替换
:- | :-
:- | :-
`M-%` | 以交互方式替换文本字符串
`M-x` regexp | 使用正则表达式
`SPC` / `y` | 替换这个,继续下一个
`,` | 换这个,别动
`DEL` / `n` | 不更换就跳到下一个
`!` | 替换所有剩余的匹配项
`^` | 回到上一场比赛
`RET` | 退出查询替换
`C-r` | 进入递归编辑C-M-c 退出)
<!--rehype:className=shortcuts-->
杂项
----
### Shell
:- | :-
:- | :-
`M-!` | 执行一个shell命令
`M-&` | 异步执行shell命令
`M-` | 在区域上运行 shell 命令
`C-u` `M-` | 通过 shell 命令过滤区域
`M-x` shell | 在window shell中启动一个shell
<!--rehype:className=shortcuts-->
### 国际字符集
<!--rehype:wrap-class=row-span-2-->
:- | :-
:- | :-
`C-x` `RET` `l` | 指定主要语言
`M-x` list-input-methods | 显示所有输入法
`C-\` | 启用或禁用输入法
`C-x` `RET` `c` | 为下一个命令设置编码系统
`M-x` list-coding-systems | 显示所有编码系统
`M-x` prefer-coding-system | 选择首选的编码系统
<!--rehype:className=shortcuts-->
### 寄存器
:- | :-
:- | :-
`C-x` `r` `s` | 在寄存器中保存区域
`C-x` `r` `i` | 将寄存器内容插入缓冲区
`C-x` `r` `SPC` | 将点的值保存在寄存器中
`C-x` `r` `j` | 跳转到保存在寄存器中的点
<!--rehype:className=shortcuts-->
### 各种各样的
:- | :-
:- | :-
`C-u` num | 数值参数
`M--` | 否定论点
`C-q` char | 带引号的插页
<!--rehype:className=shortcuts-->
### 处理 Emacs Lisp 的命令
:- | :-
:- | :-
`C-x` `C-e` | 评估点前的性
`C-M-x` | 评估电流定义
`M-x` eval-region | 评估区
`M-:` | 读取和评估 minibuffer
`M-x` load-library | 从加载路径加载 Lisp 库
<!--rehype:className=shortcuts-->
### 简单的定制
:- | :-
:- | :-
`M-x` `customize` | 自定义变量和面
在 Emacs Lisp 中进行全局键绑定:
```emacs
(global-set-key (kbd "C-c g") search-forward)
(global-set-key (kbd "M-#") query-replace-regexp)
```
<!--rehype:className=wrap-text -->
### 缩写
:- | :-
:- | :-
`C-x` `a` `g` | 添加全局缩写
`C-x` `a` `l` | 添加模式本地缩写
`C-x` `a` `i` `g` | 为这个缩写添加全局扩展
`C-x` `a` `i` `l` | 为这个缩写添加模式本地扩展
`C-x` `a` `e` | 显式扩展缩写
`M-/` | 动态扩展前一个单词
<!--rehype:className=shortcuts-->
### 拼写检查
:- | :-
:- | :-
`M-$` | 检查当前单词的拼写
`M-x` ispell 地区 | 检查区域内所有单词的拼写
`M-x` ispell 缓冲区 | 检查整个缓冲区的拼写
`M-x` flyspell 模式 | 切换即时拼写检查
<!--rehype:className=shortcuts-->
### 编写命令
<!--rehype:wrap-class=col-span-2-->
#### 语法
```emacs
(defun command-name (args)
"documentation" (interactive "template")
body)
```
<!--rehype:className=wrap-text -->
#### 示例
```emacs
(defun this-line-to-top-of-window (line)
"Reposition current line to top of window.
With prefix argument LINE, put point on LINE."
(interactive "P")
(recenter (if (null line)
0
(prefix-numeric-value line))))
```

View File

@ -74,7 +74,7 @@ a{Click me}
p>{Click }+a{here}+{ 继续}
```html {.wrap}
```html
<p>Click <a href="">here</a> 继续</p>
```

727
docs/es6.md Normal file
View File

@ -0,0 +1,727 @@
ES2015+ 备忘清单
===
快速浏览 ES2015、ES2016、ES2017、ES2018 及以后的 JavaScript 新特性
常用
---
### 块范围
<!--rehype:wrap-class=row-span-2-->
#### Let
```js {2,4}
function fn () {
let x = 0
if (true) {
let x = 1 // 只在这个`if`里面
}
}
```
#### Const
```js
const a = 1
```
`let` 是新的 `var`。 常量(`const`) 就像 `let` 一样工作,但不能重新分配。
请参阅:[Let 和 const](https://babeljs.io/learn-es2015/#let--const)
### 反引号字符串
<!--rehype:wrap-class=row-span-2-->
#### 插值
```js
const message = `Hello ${name}`
```
#### 多行字符串
```js
const str = `
hello
world
`
```
模板和多行字符串。
请参阅:[模板字符串](https://babeljs.io/learn-es2015/#template-strings)
### 二进制和八进制文字
```js
let bin = 0b1010010
let oct = 0o755
```
请参阅:[二进制和八进制文字](https://babeljs.io/learn-es2015/#binary-and-octal-literals)
### 指数运算符
```js {1}
const byte = 2 ** 8
// 同: Math.pow(2, 8)
```
### 新方法
#### 新的字符串方法
```js
"hello".repeat(3)
"hello".includes("ll")
"hello".startsWith("he")
"hello".padStart(8) // " hello"
"hello".padEnd(8) // "hello "
"hello".padEnd(8, '!') // hello!!!
"\u1E9B\u0323".normalize("NFC")
```
#### 新的数字方法
```js
Number.EPSILON
Number.isInteger(Infinity) // false
Number.isNaN("NaN") // false
```
#### 新的 Math 方法
```js
Math.acosh(3) // 1.762747174039086
Math.hypot(3, 4) // 5
Math.imul(Math.pow(2, 32) - 1, Math.pow(2, 32) - 2) // 2
```
#### 新的 Array 方法
```js
// 返回一个真实的数组
Array.from(document.querySelectorAll("*"))
// 类似于 new Array(...),但没有特殊的单参数行为
Array.of(1, 2, 3)
```
请参阅: [新方法](https://babeljs.io/learn-es2015/#math--number--string--object-apis)
### 类
```js
class Circle extends Shape {
```
#### 构造函数
```js {1}
constructor (radius) {
this.radius = radius
}
```
#### 方法
```js {1}
getArea () {
return Math.PI * 2 * this.radius
}
```
#### 调用超类方法
```js {2}
expand (n) {
return super.expand(n) * Math.PI
}
```
#### 静态方法
```js {1}
static createFromDiameter(diameter) {
return new Circle(diameter / 2)
}
}
```
原型的语法糖。
请参阅: [类](https://babeljs.io/learn-es2015/#classes)
Promises
--------
### 做出承诺
```js {1}
new Promise((resolve, reject) => {
if (ok) { resolve(result) }
else { reject(error) }
})
```
用于异步编程。
请参阅:[Promises](https://babeljs.io/learn-es2015/#promises)
### 使用 Promises
```js {2,3}
promise
.then((result) => { ··· })
.catch((error) => { ··· })
```
### 在 finally 中使用 Promise
```js {4}
promise
.then((result) => { ··· })
.catch((error) => { ··· })
.finally(() => {
/* 独立于成功/错误的逻辑 */
})
```
当承诺被履行或被拒绝时,处理程序被调用
### Promise 函数
```js
Promise.all(···)
Promise.race(···)
Promise.reject(···)
Promise.resolve(···)
```
### Async-await
```js {2,3}
async function run () {
const user = await getUser()
const tweets = await getTweets(user)
return [user, tweets]
}
```
`async` 函数是使用函数的另一种方式。
请参阅:[异步函数](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function)
解构 Destructuring
-------------
### 解构赋值
#### Arrays
```js {1}
const [first, last] = ['Nikola', 'Tesla']
```
#### Objects
```js {1}
let {title, author} = {
title: 'The Silkworm',
author: 'R. Galbraith'
}
```
支持匹配数组和对象。
请参阅:[解构](https://babeljs.io/learn-es2015/#destructuring)
### 默认值
```js
const scores = [22, 33]
const [math = 50, sci = 50, arts = 50] = scores
```
----
```js
// Result:
// math === 22, sci === 33, arts === 50
```
可以在解构数组或对象时分配默认值
### 函数参数
```js {1}
function greet({ name, greeting }) {
console.log(`${greeting}, ${name}!`)
}
```
----
```js
greet({ name: 'Larry', greeting: 'Ahoy' })
```
对象和数组的解构也可以在函数参数中完成
### 默认值
```js {1}
function greet({ name = 'Rauno' } = {}) {
console.log(`Hi ${name}!`);
}
```
----
```js
greet() // Hi Rauno!
greet({ name: 'Larry' }) // Hi Larry!
```
### 重新分配键
```js {1}
function printCoordinates({ left: x, top: y }) {
console.log(`x: ${x}, y: ${y}`)
}
```
----
```js
printCoordinates({ left: 25, top: 90 })
```
此示例将 `x` 分配给 `left` 键的值
### 循环
```js {1}
for (let {title, artist} of songs) {
···
}
```
赋值表达式也在循环中工作
### 对象解构
```js {1}
const { id, ...detail } = song;
```
使用 `rest(...)` 运算符单独提取一些键和对象中的剩余键
扩展运算符 Spread
------
### 对象扩展
#### 与对象扩展
```js {2}
const options = {
...defaults,
visible: true
}
```
#### 没有对象扩展
```js
const options = Object.assign(
{}, defaults,
{ visible: true })
```
对象扩展运算符允许您从其他对象构建新对象。
请参阅:[对象传播](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator)
### 数组扩展
#### 具有数组扩展
```js {2,3}
const users = [
...admins,
...editors,
'rstacruz'
]
```
#### 没有数组扩展
```js
const users = admins
.concat(editors)
.concat([ 'rstacruz' ])
```
扩展运算符允许您以相同的方式构建新数组。
请参阅:[扩展运算符](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator)
函数 Functions
---------
### 函数参数
<!--rehype:wrap-class=row-span-3-->
#### 默认参数
```js {1}
function greet (name = 'Jerry') {
return `Hello ${name}`
}
```
#### Rest 参数
```js {1}
function fn(x, ...y) {
// y 是一个数组
return x * y.length
}
```
#### 扩展
```js {1}
fn(...[1, 2, 3])
// 与 fn(1, 2, 3) 相同
```
Default(默认), rest, spread(扩展)。
请参阅:[函数参数](https://babeljs.io/learn-es2015/#default--rest--spread)
### 箭头函数
<!--rehype:wrap-class=row-span-3-->
#### 箭头函数
```js {1}
setTimeout(() => {
···
})
```
#### 带参数
```js {1}
readFile('text.txt', (err, data) => {
...
})
```
#### 隐式返回
```js {1,4,5,6}
arr.map(n => n*2)
// 没有花括号 = 隐式返回
// 同: arr.map(function (n) { return n*2 })
arr.map(n => ({
result: n*2
}))
// 隐式返回对象需要在对象周围加上括号
```
类似函数,但保留了 `this`。
请参阅:[箭头函数](https://babeljs.io/learn-es2015/#arrows-and-lexical-this)
### 参数设置默认值
```js
function log(x, y = 'World') {
console.log(x, y);
}
log('Hello') // Hello World
log('Hello', 'China') // Hello China
log('Hello', '') // Hello
```
### 与解构赋值默认值结合使用
```js
function foo({x, y = 5} = {}) {
console.log(x, y);
}
foo() // undefined 5
```
### name 属性
```js
function foo() {}
foo.name // "foo"
```
Objects
-------
### 速记语法
```js
module.exports = { hello, bye }
```
同下:
```js
module.exports = {
hello: hello, bye: bye
}
```
请参阅:[对象字面量增强](https://babeljs.io/learn-es2015/#enhanced-object-literals)
### 方法
```js {2}
const App = {
start () {
console.log('running')
}
}
// 同: App = { start: function () {···} }
```
请参阅:[对象文字增强](https://babeljs.io/learn-es2015/#enhanced-object-literals)
### Getters and setters
```js {2,5}
const App = {
get closed () {
return this.status === 'closed'
},
set closed (value) {
this.status = value ? 'closed' : 'open'
}
}
```
请参阅:[对象字面量增强](https://babeljs.io/learn-es2015/#enhanced-object-literals)
### 计算属性名称
```js {3}
let event = 'click'
let handlers = {
[`on${event}`]: true
}
// 同: handlers = { 'onclick': true }
```
请参阅:[对象字面量增强](https://babeljs.io/learn-es2015/#enhanced-object-literals)
### 提取值
```js {3,5}
const fatherJS = { age: 57, name: "张三" }
Object.values(fatherJS)
// [57, "张三"]
Object.entries(fatherJS)
// [["age", 57], ["name", "张三"]]
```
Modules 模块
-------
### Imports 导入
```js
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
```
`import` 是新的 `require()`。
请参阅:[Module imports](https://babeljs.io/learn-es2015/#modules)
### Exports 导出
```js
export default function () { ··· }
// 又名: module.exports.default = ···
```
----
```js
export function mymethod () { ··· }
// 又名: module.exports.mymethod = ···
```
----
```js
export const pi = 3.14159
// 又名: module.exports.pi = ···
```
----
```js
const firstName = 'Michael';
const lastName = 'Jackson';
const year = 1958;
export { firstName, lastName, year };
```
----
```js
export * from "lib/math";
```
`export` 是新的`module.exports`。
请参阅:[Module exports](https://babeljs.io/learn-es2015/#modules)
### `as` 关键字重命名
```js {2,8,12-14}
import {
lastName as surname // 导入重命名
} from './profile.js';
function v1() { ... }
function v2() { ... }
export { v1 as default };
// 等同于 export default v1;
export {
v1 as streamV1, // 导出重命名
v2 as streamV2, // 导出重命名
v2 as streamLatestVersion // 导出重命名
};
```
### 动态加载模块
```js
button.addEventListener('click', event => {
import('./dialogBox.js')
.then(dialogBox => {
dialogBox.open();
})
.catch(error => {
/* Error handling */
})
});
```
[ES2020提案](https://github.com/tc39/proposal-dynamic-import) 引入 `import()` 函数
### import() 允许模块路径动态生成
```js
const main = document.querySelector('main')
import(`./modules/${someVariable}.js`)
.then(module => {
module.loadPageInto(main);
})
.catch(err => {
main.textContent = err.message;
});
```
### import.meta
[ES2020](https://github.com/tc39/proposal-import-meta) 为 `import` 命令添加了一个元属性 `import.meta`,返回当前模块的元信息
```js
new URL('data.txt', import.meta.url)
```
Node.js 环境中,`import.meta.url`返回的总是本地路径,即 `file:URL` 协议的字符串,比如 `file:///home/user/foo.js`
Generators
----------
### Generator 函数
```js
function* idMaker () {
let id = 0
while (true) { yield id++ }
}
```
---
```js
let gen = idMaker()
gen.next().value // → 0
gen.next().value // → 1
gen.next().value // → 2
```
情况很复杂。
请参阅:[Generators](https://babeljs.io/learn-es2015/#generators)
### For..of + 迭代器(iterator)
<!--rehype:wrap-class=row-span-2-->
```js
let fibonacci = {
[Symbol.iterator]() {
let pre = 0, cur = 1;
return {
next() {
[pre, cur] = [cur, pre + cur];
return { done: false, value: cur }
}
}
}
}
for (var n of fibonacci) {
// 在 1000 处截断序列
if (n > 1000) break;
console.log(n);
}
```
用于迭代生成器和数组。
请参阅:[For..of iteration](https://babeljs.io/learn-es2015/#iterators--forof)
### 与 Iterator 接口的关系
```js
var gen = {};
gen[Symbol.iterator] = function* () {
yield 1;
yield 2;
yield 3;
};
[...gen] // => [1, 2, 3]
```
`Generator` 函数赋值给 `Symbol.iterator` 属性,从而使得 `gen` 对象具有了 `Iterator` 接口,可以被 `...` 运算符遍历了
### Symbol.iterator 属性
```js
function* gen() { /* some code */ }
var g = gen();
g[Symbol.iterator]() === g // true
```
`gen` 是一个 `Generator` 函数,调用它会生成一个遍历器对象`g`。它的 `Symbol.iterator` 属性,也是一个遍历器对象生成函数,执行后返回它自己
另见
---
- [Learn ES2015](https://babeljs.io/docs/en/learn/) _(babeljs.io)_
- [ECMAScript 6 功能概述](https://github.com/lukehoban/es6features#readme) _(github.com)_
- [ECMAScript 6 入门教程 (阮一峰)](https://es6.ruanyifeng.com/) _(ruanyifeng.com)_

591
docs/ffmpeg.md Normal file
View File

@ -0,0 +1,591 @@
FFmpeg 备忘清单
===
本备忘清单是 [FFmpeg](https://ffmpeg.org/) 中常见视频处理操作的备忘清单
FFmpeg 参考
---
### 安装
<!--rehype:wrap-class=row-span-2-->
Linux
```
$ apt-get install ffmpeg
$ yum install ffmpeg
```
MacOS
```bash
$ brew install ffmpeg
```
### 示例
<!--rehype:wrap-class=row-span-2-->
mp4 转 avi:
```bash
$ ffmpeg -i input.mp4 output.avi
```
webm 转 mp4:
```bash
$ ffmpeg -i movie.webm movie.mp4
```
### 全局选项
:- | -
:- | -
`-y` | 覆盖输出文件
`-n` | 不要覆盖输出文件
### 主要选项
:- | -
:- | -
`-f fmt` | 强制输入或输出文件格式
`-i fName` | 输入文件名,未指定显示内容流的摘要
`-c codecName` | 指定编解码器 [输入或输出]
`-fs Nbytes` | 以 Nbytes 指定最大输出文件大小
### 基础参数
:- | -
:- | -
`-codecs` | 列出可用编码
`-formats` | 列出支持的格式
`-protocols` | 列出支持的协议
`-i input.mp4` | 指定输入文件
`-c:v libx264` | 指定视频编码
`-c:a aac` | 指定音频编码
`-vcodec libx264` | 旧写法
`-acodec aac` | 旧写法
`-fs SIZE` | 指定文件大小
### 视频参数
<!--rehype:wrap-class=col-span-2 row-span-2-->
:- | -
:- | -
`-b bRate` | 设置视频比特率(单位 kbit/s)
`-fixaspect` | 固定纵横比
`-bt tolerance` | 设置视频比特率容差(单位 kbit/s)
`-maxrate bRate` | 设置最大视频比特率容差(单位 kbit/s)
`-minrate bRate` | 设置最小视频比特率容差(单位 kbit/s)
`-bufsize size` | 设置速率控制缓冲区大小(以 kByte 为单位)
`-sameq` | 使用与源相同的视频质量(意味着 VBR)
`-newvideo` | 将新的视频流添加到当前输出流
`-aspect RATIO` | 纵横比(4:3、16:9 或 1.25)
`-r RATE` | 每秒帧率
`-s WIDTHxHEIGHT` | 帧大小
`-vn` | 没有视频
### 码率设置
```bash
-b:v 1M # 视频比特率(1M = 1Mbit/s)
-b:a 1M # 音频比特率(1M = 1Mbit/s)
```
### 尺寸规格
:- | - | - | -
:- | - | - | -
`K``k` | 103 | 1000 字节 | 千字节 Kilobytes
`M` | 106 | 1000000 字节 | 兆字节 Megabytes
`G` | 109 | 1000000000 | 千兆字节 Gigabytes
`Ki` | 210 | 1024 | 千字节 Kibibyte
`Mi` | 220 | 1048576 | 兆字节 Mebibyte
`Gi` | 230 | 1073741824 | Gibibyte
### 音频参数
<!--rehype:wrap-class=col-span-2-->
:- | -
:- | -
`-ab bRate` | 设置音频比特率(单位 kbit/s)
`-aframes N` | 设置要录制的音频帧数 [-frames:a 的别名]
`-aq q` | 设置音频质量(特定于编解码器VBR) [-q:a 的别名]
`-an` | 禁用录音
`-acodec codec` | 设置音频编解码器。[-codec:a 的别名] 使用 'copy' 复制流。
`-vol` | 以 256 的倍数更改音频音量,其中 256 = 100%(正常)音量。例如 512 = 200%
`-newaudio` | 将新的音频流添加到当前输出流
`-alang code` | 设置当前音频流的 ISO 639 语言代码(3 个字母)
视频编辑
---
<!--rehype:body-class=cols-2-->
### 裁剪
<!--rehype:wrap-class=row-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 <输出>
```
<!--rehype:className=wrap-text -->
### 视频帧速率
```bash
$ ffmpeg -i input.avi -r 24 output.avi
```
将输出文件的帧速率强制为 24 fps
```bash
$ 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-->
```bash
$ ffmpeg -y -i <input> -c:v libx265 -b:v 2600k \
-x265-params pass=1 \
-an -f mp4 /dev/null && \
ffmpeg -i <input> \
-c:v libx265 -b:v 2600k \
-x265-params pass=2 \
-c:a aac -b:a 128k output.mp4
```
<!--rehype:className=wrap-text -->
对于 `H265 2-pass` 编码,您需要组合 `2``ffmpeg` 调用
### 视频比特率设置
```bash
$ ffmpeg -i input.avi -b:v 64k -bufsize 64k output.avi
```
将输出文件的视频比特率设置为 64 kbit/s
### 固定旋转
```bash
$ ffmpeg -i <input> -c copy -metadata:s:v:0 rotate=90 <output>
```
<!--rehype:className=wrap-text -->
不要为旋转重新编码,而是简单地为旋转角度添加一个视频元数据字段
### 放慢视频速度
```bash
$ ffmpeg -i in.mp4 -filter:v "setpts=4.0*PTS" out.mp4
```
使用过滤器减慢视频。 此示例将视频减慢四倍
### 缩放到特定宽度
```bash
$ ffmpeg -i in.mp4 -filter:v scale="538:trunc(ow/a/2)*2" -c:a copy out.mp4
```
给定所需的视频宽度,例如 538 像素,您可以使用以下方法将视频调整为该宽度,同时保持宽高比
重新包装
---
### 提取音频流
```bash
$ ffmpeg -i file.mp4 -vn -acodec copy output.aac
```
<!--rehype:className=wrap-text -->
`-vn`(无视频)与 `-acodec copy` 结合起来。请注意,输出文件扩展名必须与输入文件中的音频编解码器匹配,`-acodec copy` 才能工作。
### 创建缩略图
<!--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 -->
### 处理 id3 标签
<!--rehype:wrap-class=row-span-2-->
提取
```bash
$ ffmpeg -i file.mp3 -f ffmetadata metadata.txt
```
<!--rehype:className=wrap-text -->
设置
```bash
$ ffmpeg -i file.mp3 -acodec copy -metadata title="<title>" -metadata artist="<artist>" -metadata album="<album>" out.mp3
```
<!--rehype:className=wrap-text -->
更多[请查看](https://gist.github.com/eyecatchup/0757b3d8b989fe433979db2ea7d95a01)
### 重新采样/转换音频
```bash
$ ffmpeg -i file.aac -acodec mp3 -ar 44100 -ab 128000 output.mp3
```
<!--rehype:className=wrap-text -->
### 切换容器(转换类型)
<!--rehype:wrap-class=row-span-2-->
将容器从 `MKV` 更改为 `MP4`
```bash
$ ffmpeg -i file.mkv -acodec copy -vcodec copy file.mp4
```
<!--rehype:className=wrap-text -->
要将视频从 `.mov` 更改为 `.mp4`
```bash
$ ffmpeg -i in.mov out.mp4
```
### 音视频同步
<!--rehype:wrap-class=row-span-2-->
将音频延迟 3 秒
```bash
$ ffmpeg -i input.mov -itsoffset 3 -i input.mov -map 0:v -map 1:a -codec:a copy -codec:v copy output.mov
```
<!--rehype:className=wrap-text -->
将视频延迟 3 秒(即将音频提前 3 秒)
```bash
$ ffmpeg -i input.mov -itsoffset 3 -i input.mov -map 1:v -map 0:a -codec:a copy -codec:v copy output.mov
```
<!--rehype:className=wrap-text -->
### 图片中的视频
如果您有多个编号的图像 image1.jpg、image2.jpg... 像这样从它们创建一个视频
```bash
$ ffmpeg -f image2 -i image%d.jpg video.mp4
```
<!--rehype:className=wrap-text -->
### 将视频拆分为图像
```bash
$ ffmpeg -i video.mp4 image%d.jpg
```
### 转换为 Gif
<!--rehype:wrap-class=col-span-2 row-span-3-->
```bash
$ ffmpeg -ss 2 -t 28 -i input.mp4 -vf "fps=10,scale=1080:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 output.gif
```
<!--rehype:className=wrap-text -->
上面有关更多信息,请参阅 [StackOverflow 问题](https://superuser.com/a/556031)
```bash
# 转换为 GIF
$ ffmpeg -i input.mov output.gif
# 从 GIF 转换
$ ffmpeg -i input.gif output.mov
# 在非 GIF 格式之间转换
$ 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
```
### 字幕
<!--rehype:wrap-class=col-span-2 row-span-2-->
将字幕写入视频
```bash
$ ffmpeg -i input.mov -filter:v 'subtitles=subtitles.srt' -codec:a copy output.mov
```
将字幕写入视频,具有自定义字幕样式
```bash
$ ffmpeg -i input.mov -filter:v "subtitles=subtitles.srt:force_style='FontName=Menlo Bold,Fontsize=18'" -codec:a copy output.mov
```
<!--rehype:className=wrap-text -->
### 制造 1 分钟的音频噪音
```bash
$ ffmpeg -ar 48000 -t 60 -f s16le -acodec pcm_s16le -i /dev/u­random -ab 64K -f mp2 -acodec mp2 -y noise.mp2
```
<!--rehype:className=wrap-text -->
### 从视频中提取图像
```bash
$ ffmpeg -i foo.avi -r 1 -s WxH -f image2 outFil­e%0­3d.png
```
<!--rehype:className=wrap-text -->
### 音量
<!--rehype:wrap-class=col-span-2 row-span-2-->
将音量减半
```bash
$ ffmpeg -i input.mov -codec:v copy -filter:a 'volume=0.5' output.mov
```
音量加倍
```bash
$ ffmpeg -i input.mov -codec:v copy -filter:a 'volume=2' output.mov
```
### 将图像文件转换为其他格式
```bash
$ ffmpeg -i foo012­2.png foo.tiff
```
pgm, ppm, pam, pgmyuv, jpeg, gif, png, tiff, sgi
### 将图像转换为 AVI 文件
```bash
$ ffmpeg -f image2 -i foo-%0­3d.jpeg -r 12 -s WxH foo.avi
```
<!--rehype:className=wrap-text -->
### 将 WAV 文件转换为 MP3
```bash
$ ffmpeg -i source­_so­ng.wav -vn -ar 44100 -ac 2 -ab 192 -f mp3 final_­son­g.mp3
```
<!--rehype:className=wrap-text -->
### 从视频中提取音频,将其转码为 MP3
```bash
$ ffmpeg -i source.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 sound.mp3
```
<!--rehype:className=wrap-text -->
### 将 .avi 转换为 .flv
```bash
$ ffmpeg -i source.avi -ab 56 -ar 44100 -b 200 -r 15 -s 320x240 -f flv output.flv
```
<!--rehype:className=wrap-text -->
### 将图片附加到 mp3
```bash
$ ffmpeg -i input.mp3 -i cover.png -c copy -metad­ata:s:v title=­"­Album cover" -metad­ata:s:v commen­t="Cover (Front­)" out.mp3
```
<!--rehype:className=wrap-text -->
### 将视频与声音文件混合
```bash
$ ffmpeg -i song.wav -i source­_vi­deo.avi outvid­eo.mpg
```
<!--rehype:className=wrap-text -->
### 编写带有 ID3v2.3 页眉和 ID3v1 页脚的 mp3
```bash
$ ffmpeg -i inFile -id3v2­_ve­rsion 3 -write­_id3v1 1 outFil­e.mp3
```
<!--rehype:className=wrap-text -->
### 连接输入文件
```bash
$ cat inFile1 inFile2 | ffmpeg -f mpeg -i - -vcodec copy -acodec copy outFil­e.mpg
```
<!--rehype:className=wrap-text -->
### 使用比特率和 mp3 音频的编解码器对剪辑进行编码
```bash
$ ffmpeg -i clip.avi -vcodec libxvid -b 800000 -acodec libmp3lame -ab 128 new-cl­ip.avi
```
<!--rehype:className=wrap-text -->
### 将音频流与来自不同文件的视频流合并
```bash
$ ffmpeg -i audioS.mp4 -i videoS.mp4 -c copy -map 0:a -map 1:v outFil­e.mp4
```
<!--rehype:className=wrap-text -->
### 合并视频
<!--rehype:wrap-class=col-span-2 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 -->
### 合并音频与图片
合并多个音频,自定义背景图片,生成视频音乐
```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 -->
### 添加水印
在视频左上方 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 -->
### 去除水印
设置一个矩形覆盖区域 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 -->
另见
---
- [FFmpeg 官网地址](https://ffmpeg.org/) _(ffmpeg.org)_
- [FFmpeg Cheat Sheet](https://lzone.de/cheat-sheet/ffmpeg) _(lzone.de)_
- [FFmpeg Cheat Sheet](https://devhints.io/ffmpeg) _(devhints.io)_
- [FFmpeg Cheat Sheet](https://github.com/yuanqing/ffmpeg-cheatsheet) _(github.com)_
- [FFmpeg Cheat Sheet](https://cheatography.com/thetartankilt/cheat-sheets/ffmpeg/) _(cheatography.com)_

View File

@ -11,23 +11,29 @@ Git 备忘清单
创建一个新的本地存储库
```shell
$ git init [project name]
$ git init [项目名称]
```
克隆存储库
克隆存储库(代码仓库)
```shell
$ git clone git_url
$ git clone <git_url>
```
将存储库克隆到指定目录
```shell
$ git clone git_url 指定目录
$ git clone <git_url> 指定目录
```
将存储库克隆到指定目录,并指定分支
```shell
$ git clone <git_url> -b <分支名称> 指定目录
```
### 做出改变
<!--rehype:wrap-class=row-span-2-->
<!--rehype:wrap-class=row-span-3-->
在工作目录中**显示**修改后的文件,为您的下一次提交暂存
@ -89,8 +95,8 @@ $ git diff --staged
$ git rebase [branch]
```
### 配置
<!--rehype:wrap-class=row-span-2-->
设置将附加到您的提交和标签的名称
@ -116,7 +122,20 @@ $ git config --global color.ui auto
$ git config --global --edit
```
显示本地 `repo` 配置设置
```shell
$ git config --list
```
删除全局设置
```bash
$ git config --global --unset <entry-name>
```
### 使用分支
<!--rehype:wrap-class=row-span-3-->
列出所有本地分支
@ -130,25 +149,25 @@ $ git branch
$ git branch -av
```
切换到 my_branch并更新工作目录
切换到 `my_branch`,并更新工作目录
```shell
$ git checkout my_branch
```
创建一个名为 new_branch 的新分支
创建一个名为 `new_branch` 的新分支
```shell
$ git checkout -b new_branch
```
删除名为 my_branch 的分支
删除名为 `my_branch` 的分支
```shell
$ git branch -d my_branch
```
将分支 A 合并到分支 B
将分支 `A` 合并到分支 `B`
```shell
$ git checkout branchB
@ -161,7 +180,31 @@ $ git merge branchA
$ git tag my_tag
```
从远程分支中创建并切换到本地分支
```shell
$ git checkout -b <branch-name> origin/<branch-name>
```
### 临时提交
```shell
# 保存已修改和分阶段的更改
$ git stash
# 列出隐藏文件更改的堆栈顺序
$ git stash list
# 从存储堆栈顶部编写工作
$ git stash pop
# 丢弃存储堆栈顶部的更改
$ git stash drop
# 回到某个 stash 的状态
$ git stash apply <stash@{n}>
# 删除所有的 stash
$ git stash clear
```
### 观察你的存储库
<!--rehype:wrap-class=row-span-2-->
显示当前活动分支的提交历史
@ -193,7 +236,21 @@ $ git diff branchB...branchA
$ git show [SHA]
```
### 重构文件名
```bash
# 从工作目录中删除文件并暂存删除
git rm <filename>
# 从版本控制中删除文件但在本地保留文件
git rm --cached <filename>
# 更改文件名并准备提交
git mv <filename-orig> <filename-renamed>
```
### 同步
<!--rehype:wrap-class=row-span-2-->
从该 Git 远程获取所有分支
@ -230,6 +287,7 @@ $ git cherry-pick [commit_id]
```
### 远程
<!--rehype:wrap-class=row-span-2-->
添加一个 git URL 作为别名
@ -261,32 +319,6 @@ $ git remote rm [remote repo name]
$ git remote set-url origin [git_url]
```
### 临时提交
保存已修改和分阶段的更改
```shell
$ git stash
```
列出隐藏文件更改的堆栈顺序
```shell
$ git stash list
```
从存储堆栈顶部编写工作
```shell
$ git stash pop
```
丢弃存储堆栈顶部的更改
```shell
$ git stash drop
```
### 跟踪路径更改
从项目中删除文件并暂存删除以进行提交
@ -309,7 +341,7 @@ $ git log --stat -M
### 忽略文件
```gitignore
```gitignore showLineNumbers
/logs/*
# “!” 意思是不要忽视
!logs/.gitkeep
@ -323,6 +355,19 @@ node_modules
`.gitignore` 文件指定了 Git 应该忽略的未跟踪的文件
### git 配置 ssh 代理
```bash
$ cat ~/.ssh/config
Host gitlab.com
# 直接使用 shadowsocks 提供的 socks5 代理端口
ProxyCommand nc -X 5 -x 127.0.0.1:1080 %h %p
Host github.com
ProxyCommand nc -X 5 -x 127.0.0.1:1080 %h %p
```
<!--rehype:className=wrap-text-->
Git 技巧
------
@ -380,7 +425,7 @@ $ git branch -vv
$ git checkout -
```
只获取远程分支
只获取所有远程分支
```shell
$ git branch -r
@ -515,12 +560,6 @@ $ git branch --merged master | grep -v '^\*\| master' | xargs -n 1 git branch -
```
<!--rehype:className=wrap-text-->
### 中文乱码的解决方案
```shell
$ git config --global core.quotepath false
```
### 把 A 分支的某一个 commit放到 B 分支上
```shell
@ -528,4 +567,327 @@ $ git config --global core.quotepath false
$ git checkout <B>
# 将 A 分支 <hash-id> 的内容 pick 到 B 分支
$ git cherry-pick <hash-id>
```
```
### 回到远程仓库的状态
```bash
$ git fetch --all && git reset --hard origin/master
```
<!--rehype:className=wrap-text-->
抛弃本地所有的修改,回到远程仓库的状态
### 重设第一个 commit
```bash
$ git update-ref -d HEAD
```
把所有的改动都重新放回工作区,并**清空所有的 commit**,这样就可以重新提交第一个 `commit` 了
### 查看冲突文件列表
```bash
$ git diff --name-only --diff-filter=U
```
### 展示工作区的冲突文件列表
<!--rehype:wrap-class=row-span-2-->
输出工作区和暂存区的 different (不同)。
```bash
$ git diff
```
还可以展示本地仓库中任意两个 commit 之间的文件变动:
```bash
$ git diff <commit-id> <commit-id>
```
### 展示暂存区和最近版本的不同
```bash
git diff --cached
```
### 中文乱码的解决方案
```shell
$ git config --global core.quotepath false
```
### 展示暂存区、工作区和最近版本的不同
```bash
$ git diff HEAD
```
输出工作区、暂存区 和本地最近的版本(commit)的different(不同)。
### 删除已经合并到 master 的分支
```bash
$ git branch --merged master | grep -v '^\*\| master' | xargs -n 1 git branch -d
```
<!--rehype:className=wrap-text-->
### 关联远程分支
<!--rehype:wrap-class=row-span-2-->
```bash
$ git branch -u origin/mybranch
```
或者在 `push` 时加上 `-u` 参数
```bash
git push origin/mybranch -u
```
关联之后,`git branch -vv` 就可以展示关联的远程分支名了, 同时推送到远程仓库直接:`git push`,不需要指定远程仓库
### 查看远程分支和本地分支的对应关系
```bash
$ git remote show origin
```
### 展示当前分支的最近的 tag
```bash
$ git describe --tags --abbrev=0
```
### 查看某段代码是谁写的
```bash
$ git blame <file-name>
```
`blame` 的意思为`责怪`,你懂的。
### 修改作者名
```bash
$ git commit --amend --author='Author Name <email@address.com>'
```
### 修改远程仓库的 url
```bash
$ git remote set-url origin <URL>
```
### 增加远程仓库
```bash
$ git remote add origin <remote-url>
```
<!--rehype:className=wrap-text-->
### 列出所有远程仓库
```bash
$ git remote -v
```
### 查看两个星期内的改动
```bash
$ git whatchanged --since='2 weeks ago'
```
### 从 stash 中拿出某个文件的修改
```bash
$ git checkout <stash@{n}> -- <file-path>
```
<!--rehype:className=wrap-text-->
### 展示所有 tracked 的文件
```bash
$ git ls-files -t
```
### 展示所有 untracked 的文件
```bash
$ git ls-files --others
```
### 展示所有忽略的文件
```bash
$ git ls-files --others -i --exclude-standard
```
<!--rehype:className=wrap-text-->
### 把某一个分支导出成一个文件
```bash
$ git bundle create <file> <branch-name>
```
### 从包中导入分支
<!--rehype:wrap-class=row-span-2-->
```bash
$ git clone repo.bundle <repo-dir> -b <branch-name>
```
<!--rehype:className=wrap-text-->
新建一个分支,分支内容就是上面 `git bundle create` 命令导出的内容
### 执行 rebase 之前自动 stash
```bash
$ git rebase --autostash
```
### 从远程仓库根据 ID拉下某一状态到本地分支
```bash
$ git fetch origin pull/<id>/head:<branch-name>
```
### 详细展示一行中的修改
```bash
$ git diff --word-diff
```
### 清除 gitignore 文件中记录的文件
```bash
$ git clean -X -f
```
### 展示忽略的文件
```bash
$ git status --ignored
```
### commit 历史中显示 Branch1 有的但是 Branch2 没有 commit
```bash
$ git log Branch1 ^Branch2
```
### 在 commit log 中显示 GPG 签名
```bash
$ git log --show-signature
```
### 新建并切换到新分支上,同时这个分支没有任何 commit
```bash
$ git checkout --orphan <branch-name>
```
相当于保存修改,但是重写 commit 历史
### 展示任意分支某一文件的内容
```bash
$ git show <branch-name>:<file-name>
```
### 配置 http 和 socks 代理
<!--rehype:wrap-class=row-span-4-->
```bash
# 查看代理
$ git config --global http.proxy
$ git config --global https.proxy
$ git config --global socks.proxy
# 设置代理
# 适用于 privoxy 将 socks 协议转为 http 协议的 http 端口
$ git config --global http.proxy http://127.0.0.1:1080
$ git config --global https.proxy http://127.0.0.1:1080
$ git config --global socks.proxy 127.0.0.1:1080
# 取消代理
$ git config --global --unset http.proxy
$ git config --global --unset https.proxy
$ git config --global --unset socks.proxy
# 只对 github.com 设置代理
$ git config --global http.https://github.com.proxy socks5://127.0.0.1:1080
$ git config --global https.https://github.com.proxy socks5://127.0.0.1:1080
# 取消 github.com 代理
$ git config --global --unset http.https://github.com.proxy
$ git config --global --unset https.https://github.com.proxy
```
### clone 最新一次提交
```bash
$ git clone --depth=1 https://github.com/user/repo.git
```
只会 `clone` 最近一次提交,将减少 `clone` 时间
### 忽略某个文件的改动
<!--rehype:wrap-class=row-span-2-->
关闭 track 指定文件的改动,也就是 Git 将不会在记录这个文件的改动
```bash
git update-index --assume-unchanged path/to/file
```
<!--rehype:className=wrap-text-->
恢复 track 指定文件的改动
```bash
git update-index --no-assume-unchanged path/to/file
```
<!--rehype:className=wrap-text-->
### 以最后提交的顺序列出所有 Git 分支
```bash
git for-each-ref --sort=-committerdate --format='%(refname:short)' refs/heads
```
最新的放在最上面
### 在 commit log 中查找相关内容
```bash
git log --all --grep='<given-text>'
```
通过 grep 查找given-text: 所需要查找的字段
### 把暂存区的指定 file 放到工作区中
```bash
git reset <file-name>
```
不添加参数,默认是 `-mixed`
### 配置 SSH 协议代理
```shell
# 对于使用 git@ 协议的,可以配置 socks5 代理
# macOS 系统编辑 ~/.ssh/config 文件,添加这几行,设置 github 代理
Host github.com
ProxyCommand nc -X 5 -x 127.0.0.1:1080 %h %p
```
<!--rehype:className=wrap-text-->
另见
---
- [最常用的 git 提示和技巧](https://github.com/git-tips/tips)

129
docs/gmail.md Normal file
View File

@ -0,0 +1,129 @@
Gmail 备忘清单
===
本备忘单总结了常用的 [Gmail](https://gmail.com/) 快捷键,以供快速参考。
Gmail 快捷键
---
### Gmail 导航
:- | :-
:- | :-
`u` | 返回话题列表(或刷新话题列表)
`k` / `j` | 较新/较旧的对话
`o` or `Enter` | 打开对话; 折叠/展开
`p` / `n` | 阅读上一条/下一条消息
<code>\`</code> | 转到下一个收件箱部分
`~` | 转到上一个收件箱部分
<!--rehype:className=shortcuts-->
### Gmail 应用程序
:- | :-
:- | :-
`c` | 撰写
`d` | 添加 cc 撰写
`b` | 添加 cc 和 bcc 撰写
`/` | 搜索
`q` | 焦点聊天联系人搜索
`?` | 打开快捷方式帮助
<!--rehype:className=shortcuts-->
### Gmail 操作
<!--rehype:wrap-class=row-span-3-->
:- | :-
:- | :-
`,` | 将焦点移至工具栏
`x` | 选择对话
`s` | 旋转超级巨星
`y` | 删除标签
`e` | 档案
`m` | 忽略对话
`!` | 报告为垃圾邮件
`v` | 打开移动到菜单
`#` | 移到废纸篓
`r` | 回复
`Shift+r` | 在新窗口中回复
`a` | 全部回复
`Shift+a` | 在新窗口中回复所有
`f` | 向前
`Shift+f` | 在新窗口中转发
`Shift+n` | 更新对话
`Tab` 然后 `Enter` | 发邮件
`Esc` | 焦点最后聊天痣
`]` / `[` | 删除并转到上一个/下一个
`}` / `{` | 存档并转到上一个/下一个
`z` | 撤消上一个操作
`.` | 打开更多操作菜单
`l` | 打开标签菜单
`Shift+i` | 标记为已读
`Shift+u` | 标记为未读
`_` | 将所选邮件标记为未读
`Ctrl+s` | 保存草稿
`+``=` | 标记为重要
`-` | 标记为不重要
`Shift+l` | 喜欢/不喜欢嗡嗡声
`h` | 抢先看
`g` 然后 `p` | 打个电话
`&` | 启动老蛇
`Shift+t` | 将对话添加到任务
<!--rehype:className=shortcuts-->
### Gmail 跳转
:- | :-
:- | :-
`g` 然后 `i` | 打开收件箱
`g` 然后 `s` | 打开已加星标的对话
`g` 然后 `t` | 打开已发送消息
`g` 然后 `d` | 打开草稿
`g` 然后 `a` | 打开所有消息
`g` 然后 `c` | 打开联系人
`g` 然后 `b` | 去嗡嗡声
`g` 然后 `l` | 转到标签
`g` 然后 `k` | 前往任务
<!--rehype:className=shortcuts-->
### Gmail 主题列表选择
:- | :-
:- | :-
`*` 然后 `a` | 选择所有对话
`*` 然后 `n` | 取消选择所有对话
`*` 然后 `r` | 选择阅读对话
`*` 然后 `u` | 选择未读对话
`*` 然后 `s` | 选择加星标的对话
`*` 然后 `t` | 选择未加星标的对话
<!--rehype:className=shortcuts-->
### Gmail 搜索语法
:- | :-
:- | :-
`from:[arg]` | 从
`to:[arg]` | 至
`label:­[arg]` | 标签
`subjec­t:[arg]` | 主题
`-[arg]` | 不包含
`has:at­tac­hment` | 有附件
`filena­me:­[fi­lename]` | 附件文件名
`before­:20­11/­11/20` | 之前(日期)
`after:­201­1/11/20` | 之后(日期)
`from:annie``from:david` | 或运算符
`list:[arg]` | 邮件列表
`subjec­t:(­word1 word2)` | 组词
`in:any­where` | 在所有框中搜索(垃圾邮件和垃圾邮件除外)
`in:trash in:inbox in:spam` | 在特定框中搜索
`is:starred is:read is:unread` | 搜索特定消息
`is:chat` | 在聊天中搜索
`cc:[arg] bcc:[arg]` | 搜索副本收件人
<!--rehype:className=shortcuts-->
### Gmail 提示和技巧
-`u` 刷新话题列表
- 对于多选,选择一个对话,然后 `shift+单击`另一个对话以选择其间的所有对话
- 在主题中添加 `EOM`(消息结尾)以避免 `no-text-in-body` 警告

View File

@ -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]))
@ -947,12 +947,12 @@ func main() {
| | | | | | | | | |
|---|----|-----|-----|------|----|-----|---|---|
| `+` | & | += | &= | && | == | != | ( | ) |
| `-` | \| | -= | \|= | \|\| | < | <= | [ | ] |
| `*` | ^ | *= | ^= | <- | > | >= | { | } |
| `/` | << | /= | <<= | ++ | = | := | , | ; |
| `%` | >> | %= | >>= | -- | ! | ... | . | : |
| | &^ | &^= | | | | | | |
| `+` | `&` | `+=` | `&=` | `&&` | `==` | `!=` | `(` | `)` |
| `-` | `\|` | `-=` | `\|=` | `\|\|` | `<` | `<=` | `[` | `]` |
| `*` | `^` | `*=` | `^=` | `<-` | `>` | `>=` | `{` | `}` |
| `/` | `<<` | `/=` | `<<=` | `++` | `=` | `:=` | `,` | `;` |
| `%` | `>>` | `%=` | `>>=` | `--` | `!` | `...` | `.` | `:` |
| | `&^` | `&^=` | | | | | | |
另见
--------

237
docs/iso-639-1.md Normal file
View File

@ -0,0 +1,237 @@
ISO 639-1 Language Code 备忘清单
===
这是一个符合 ISO 639-1 标准的 ISO 语言代码列表,它为多语言网站提供参考。
入门
----
### 介绍
<!--rehype:style=display:none;&wrap-style=padding-top:0;&wrap-class=col-span-3-->
- [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) 是用于对语言进行分类的标准化命名法
- [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) 代码涵盖世界主要语言
- 这些代码是用于指示语言的有用的国际和正式速记
- 两个字母的代码
- 用于多语言网站,即国际化 (`i18n`)
- [i18n](https://en.wikipedia.org/wiki/Internationalization_and_localization) 语言代码
<!--rehype:className=style-round-->
ISO 639-1 代码列表
----
### 完整代码
<!--rehype:wrap-class=col-span-3-->
639-1 代码 | ISO 语言(中文)名称 | ISO 语言名称 | 本地名称 (地名)
:-|:-|:-|:-
`aa` | 阿法尔语 | Afar | Afaraf
`ab` | 阿布哈兹语 | Abkhaz | аҧсуа бызшәа
`ae` | 阿维斯陀语 | Avestan | avesta
`af` | 南非語 | Afrikaans | Afrikaans
`ak` | 阿坎语 | Akan | Akan
`am` | 阿姆哈拉语 | Amharic | አማርኛ
`an` | 阿拉贡语 | Aragonese | aragonés
`ar` | 阿拉伯语 | Arabic | اللغة العربية
`as` | 阿萨姆语 | Assamese | অসমীয়া
`av` | 阿瓦尔语 | Avaric | авар мацӀ
`ay` | 艾马拉语 | Aymara | aymar aru
`az` | 阿塞拜疆语 | Azerbaijani | azərbaycan dili
`ba` | 巴什基尔语 | Bashkir | башҡорт теле
`be` | 白俄罗斯语 | Belarusian | беларуская мова
`bg` | 保加利亚语 | Bulgarian | български език
`bh` | 比哈尔语 | Bihari | भोजपुरी
`bi` | 比斯拉马语 | Bislama | Bislama
`bm` | 班巴拉语 | Bambara | bamanankan
`bn` | 孟加拉语 | Bengali | বাংলা
`bo` | 藏语 | Tibetan | བོད་ཡིག
`br` | 布列塔尼语 | Breton | brezhoneg
`bs` | 波斯尼亚语 | Bosnian | bosanski jezik
`ca` | 加泰隆语 | Catalan | Català
`ce` | 车臣语 | Chechen | нохчийн мотт
`ch` | 查莫罗语 | Chamorro | Chamoru
`co` | 科西嘉语 | Corsican | corsu
`cr` | 克里语 | Cree | ᓀᐦᐃᔭᐍᐏᐣ
`cs` | 捷克语 | Czech | čeština
`cu` | 古教会斯拉夫语 | Old Church Slavonic | ѩзыкъ словѣньскъ
`cv` | 楚瓦什语 | Chuvash | чӑваш чӗлхи
`cy` | 威尔士语 | Welsh | Cymraeg
`da` | 丹麦语 | Danish | dansk
`de` | 德语 | German | Deutsch
`dv` | 迪维西语 | Divehi | Dhivehi
`dz` | 不丹语 | Dzongkha | རྫོང་ཁ
`ee` | 埃维语 | Ewe | Eʋegbe
`el` | 现代希腊语 | Greek | Ελληνικά
`en` | 英语 | English | English
`eo` | 世界语 | Esperanto | Esperanto
`es` | 西班牙语 | Spanish | Español
`et` | 爱沙尼亚语 | Estonian | eesti
`eu` | 巴斯克语 | Basque | euskara
`fa` | 波斯语 | Persian | فارسی
`ff` | 富拉语 | Fula | Fulfulde
`fi` | 芬兰语 | Finnish | suomi
`fj` | 斐济语 | Fijian | Vakaviti
`fo` | 法罗语 | Faroese | føroyskt
`fr` | 法语 | French | Français
`fy` | 弗里西亚语 | Western Frisian | Frysk
`ga` | 爱尔兰语 | Irish | Gaeilge
`gd` | 苏格兰盖尔语 | Scottish Gaelic | Gàidhlig
`gl` | 加利西亚语 | Galician | galego
`gn` | 瓜拉尼语 | Guarani | avañe'ẽ
`gu` | 古吉拉特语 | Gujarati | ગુજરાતી
`gv` | 马恩岛语 | Manx | Gaelg
`ha` | 豪萨语 | Hausa | هَوُسَ
`he` | 希伯来语 | Hebrew | עברית
`hi` | 印地语 | Hindi | हिन्दी
`ho` | 希里莫图语 | Hiri Motu | Hiri Motu
`hr` | 克罗地亚语 | Croatian | Hrvatski
`ht` | 海地克里奥尔语 | Haitian | Kreyòl ayisyen
`hu` | 匈牙利语 | Hungarian | magyar
`hy` | 亚美尼亚语 | Armenian | Հայերեն
`hz` | 赫雷罗语 | Herero | Otjiherero
`ia` | 因特语 | Interlingua | Interlingua
`id` | 印尼语 | Indonesian | Bahasa Indonesia
`ie` | 西方国际语 | Interlingue | Interlingue
`ig` | 伊博语 | Igbo | Asụsụ Igbo
`ii` | 四川彝语(诺苏语) | Nuosu | ꆈꌠ꒿ Nuosuhxop
`ik` | 伊努皮克语 | Inupiaq | Iñupiaq
`io` | 伊多语 | Ido | Ido
`is` | 冰岛语 | Icelandic | Íslenska
`it` | 意大利语 | Italian | Italiano
`iu` | 因纽特语 | Inuktitut | ᐃᓄᒃᑎᑐᑦ
`ja` | 日语 | Japanese | 日本語
`jv` | 爪哇语 | Javanese | basa Jawa
`ka` | 格鲁吉亚语 | Georgian | ქართული
`kg` | 刚果语 | Kongo | Kikongo
`ki` | 基库尤语 | Kikuyu | Gĩkũyũ
`kj` | 宽亚玛语 | Kwanyama | Kuanyama
`kk` | 哈萨克语 | Kazakh | қазақ тілі
`kl` | 格陵兰语 | Kalaallisut | kalaallisut
`km` | 高棉语 | Khmer | ខេមរភាសា
`kn` | 卡纳达语 | Kannada | ಕನ್ನಡ
`ko` | 朝鲜语、韩语 | Korean | 한국어
`kr` | 卡努里语 | Kanuri | Kanuri
`ks` | 克什米尔语 | Kashmiri | कश्मीरी
`ku` | 库尔德语 | Kurdish | Kurdî
`kv` | 科米语 | Komi | коми кыв
`kw` | 康沃尔语 | Cornish | Kernewek
`ky` | 吉尔吉斯语 | Kyrgyz | Кыргызча
`la` | 拉丁语 | Latin | latine
`lb` | 卢森堡语 | Luxembourgish | Lëtzebuergesch
`lg` | 卢干达语 | Ganda | Luganda
`li` | 林堡语 | Limburgish | Limburgs
`ln` | 林加拉语 | Lingala | Lingála
`lo` | 老挝语 | Lao | ພາສາ
`lt` | 立陶宛语 | Lithuanian | lietuvių kalba
`lu` | 卢巴语 | Luba-Katanga | Tshiluba
`lv` | 拉脱维亚语 | Latvian | latviešu valoda
`mg` | 马达加斯加语 | Malagasy | fiteny malagasy
`mh` | 马绍尔语 | Marshallese | Kajin M̧ajeļ
`mi` | 毛利语 | Māori | te reo Māori
`mk` | 马其顿语 | Macedonian | македонски јазик
`ml` | 马拉雅拉姆语 | Malayalam | മലയാളം
`mn` | 蒙古语 | Mongolian | Монгол хэл
`mo` | 摩尔达维亚语 | Moldovan | Лимба молдовеняскэ
`mr` | 马拉地语 | Marathi | मराठी
`ms` | 马来语 | Malay | Bahasa Malaysia
`mt` | 马耳他语 | Maltese | Malti
`my` | 缅甸语 | Burmese | ဗမာစာ
`na` | 瑙鲁语 | Nauru | Ekakairũ Naoero
`nb` | 书面挪威语 | Norwegian Bokmål | Norsk bokmål
`nd` | 北恩德贝莱语 | Northern Ndebele | isiNdebele
`ne` | 尼泊尔语 | Nepali | नेपाली
`ng` | 恩敦加语 | Ndonga | Owambo
`nl` | 荷兰语 | Dutch | Nederlands
`nn` | 新挪威语 | Norwegian Nynorsk | Norsk nynorsk
`no` | 挪威语 | Norwegian | Norsk
`nr` | 南恩德贝莱语 | Southern Ndebele | isiNdebele
`nv` | 纳瓦霍语 | Navajo | Diné bizaad
`ny` | 尼扬贾语 | Chichewa | chiCheŵa
`oc` | 奥克语 | Occitan | occitan
`oj` | 奥杰布瓦语 | Ojibwe | ᐊᓂᔑᓈᐯᒧᐎᓐ
`om` | 奥罗莫语 | Oromo | Afaan Oromoo
`or` | 奥里亚语 | Oriya | ଓଡ଼ିଆ
`os` | 奥塞梯语 | Ossetian | ирон æвзаг
`pa` | 旁遮普语 | Panjabi | ਪੰਜਾਬੀ
`pi` | 巴利语 | Pāli | पाऴि
`pl` | 波兰语 | Polish | Polski
`ps` | 普什图语 | Pashto | پښتو
`pt` | 葡萄牙语 | Portuguese | Português
`qu` | 克丘亚语 | Quechua | Runa Simi
`rm` | 罗曼什语 | Romansh | rumantsch grischun
`rn` | 基隆迪语 | Kirundi | Ikirundi
`ro` | 罗马尼亚语 | Romanian | Română
`ru` | 俄语 | Russian | Русский
`rw` | 卢旺达语 | Kinyarwanda | Ikinyarwanda
`sa` | 梵语 | Sanskrit | संस्कृतम्
`sc` | 撒丁语 | Sardinian | sardu
`sd` | 信德语 | Sindhi | सिन्धी
`se` | 北萨米语 | Northern Sami | Davvisámegiella
`sg` | 桑戈语 | Sango | yângâ tî sängö
`sh` | 塞尔维亚-克罗地亚语 | Serbo-Croatian | Српскохрватски језик
`si` | 僧伽罗语 | Sinhala | සිංහල
`sk` | 斯洛伐克语 | Slovak | slovenčina
`sl` | 斯洛文尼亚语 | Slovenian | slovenščina
`sm` | 萨摩亚语 | - | -
`sn` | 修纳语 | Shona | chiShona
`so` | 索马里语 | Somali | Soomaaliga
`sq` | 阿尔巴尼亚语 | Albanian | Shqip
`sr` | 塞尔维亚语 | Serbian | српски језик
`ss` | 斯威士语 | Swati | SiSwati
`st` | 塞索托语 | Southern Sotho | Sesotho
`su` | 巽他语 | Sundanese | Basa Sunda
`sv` | 瑞典语 | Swedish | Svenska
`sw` | 斯瓦希里语 | Swahili | Kiswahili
`ta` | 泰米尔语 | Tamil | தமிழ்
`te` | 泰卢固语 | Telugu | తెలుగు
`tg` | 塔吉克语 | Tajik | тоҷикӣ
`th` | 泰语 | Thai | ไทย
`ti` | 提格雷尼亚语 | Tigrinya | ትግርኛ
`tk` | 土库曼语 | Turkmen | Türkmen
`tl` | 他加禄语 | Tagalog | Wikang Tagalog
`tn` | 茨瓦纳语 | Tswana | Setswana
`to` | 汤加语 | Tonga | faka Tonga
`tr` | 土耳其语 | Turkish | Türkçe
`ts` | 宗加语 | Tsonga | Xitsonga
`tt` | 塔塔尔语 | Tatar | татар теле
`tw` | 特威语 | Twi | Twi
`ty` | 塔希提语 | Tahitian | Reo Tahiti
`ug` | 维吾尔语 | Uyghur | ئۇيغۇرچە‎
`uk` | 乌克兰语 | Ukrainian | Українська
`ur` | 乌尔都语 | Urdu | اردو
`uz` | 乌兹别克语 | Uzbek | Ўзбек
`ve` | 文达语 | Venda | Tshivenḓa
`vi` | 越南语 | Vietnamese | Tiếng Việt
`vo` | 沃拉普克语 | Volapük | Volapük
`wa` | 瓦隆语 | Walloon | walon
`wo` | 沃洛夫语 | Wolof | Wollof
`xh` | 科萨语 | Xhosa | isiXhosa
`yi` | 依地语 | Yiddish | ייִדיש
`yo` | 约鲁巴语 | Yoruba | Yorùbá
`za` | 壮语 | Zhuang | Saɯ cueŋƅ
`zh` | 汉语(中文) | Chinese | 中文
`zu` | 祖鲁语 | Zulu | isiZulu
<!--rehype:className=show-header-->
### SO 639-1 新增了以下语言
<!--rehype:wrap-class=col-span-3-->
ISO 639-1 | ISO 639-2 | 名称 | 更改日期 | 更改类型 | 曾用代码
:-|:-|:-|:-|:-|:-
io | ido | 伊多语 | 2002年1月15日 | 新增 | art
wa | wln | 瓦隆语 | 2002年1月29日 | 新增 | roa
li | lim | 林堡语 | 2002年8月2日 | 新增 | gem
ii | iii | 四川省彝语(诺苏语) | 2002年10月14日 | 新增 | -
an | arg | 阿拉贡语 | 2002年12月23日 | 新增 | roa
ht | hat | 海地克里奥尔语 | 2003年2月26日 | 新增 | cpf
<!--rehype:className=show-header-->
自 [RFC 3066](https://tools.ietf.org/html/rfc3066) 出版后ISO 639-1 新增了以上语言
另见
---
<!--rehype:wrap-class=col-span-3-->
- [国际化与本地化](https://zh.wikipedia.org/wiki/国际化与本地化) _(wikipedia.org)_
- [ISO_639-1](https://zh.wikipedia.org/wiki/ISO_639-1) _(wikipedia.org)_

774
docs/java.md Normal file
View File

@ -0,0 +1,774 @@
Java 备忘清单
===
该备忘单是针对 Java 初学者的速成课程,有助于复习 Java 语言的基本语法。
入门
--------
### Hello.java
<!--rehype:wrap-class=row-span-2-->
```java
public class Hello {
// 主要方法
public static void main(String[] args)
{
// 输出: Hello, world!
System.out.println("Hello, world!");
}
}
```
编译和运行
```shell
$ javac Hello.java
$ java Hello
Hello, world!
```
### 变量 Variables
```java
int num = 5;
float floatNum = 5.99f;
char letter = 'D';
boolean bool = true;
String site = "quickref.me";
```
### 原始数据类型
<!--rehype:wrap-class=row-span-2-->
| 数据类型 | 大小 | 默认 | 范围 |
|-----------|--------|---------|---------------------|
| `byte` | 1 byte | 0 | -128 ^to^ 127 |
| `short` | 2 byte | 0 | -2^15^ ^to^ 2^15^-1 |
| `int` | 4 byte | 0 | -2^31^ ^to^ 2^31^-1 |
| `long` | 8 byte | 0 | -2^63^ ^to^ 2^63^-1 |
| `float` | 4 byte | 0.0f | _N/A_ |
| `double` | 8 byte | 0.0d | _N/A_ |
| `char` | 2 byte | \\u0000 | 0 ^to^ 65535 |
| `boolean` | _N/A_ | false | true / false |
<!--rehype:className=show-header-->
### 字符串 Strings
```java
String first = "John";
String last = "Doe";
String name = first + " " + last;
System.out.println(name);
```
查看: [Strings](#java-字符串)
### 循环 Loops
```java
String word = "QuickRef";
for (char c: word.toCharArray()) {
System.out.print(c + "-");
}
// 输出: Q-u-i-c-k-R-e-f-
```
查看: [Loops](#java-循环)
### 数组 Arrays
```java
char[] chars = new char[10];
chars[0] = 'a'
chars[1] = 'b'
String[] letters = {"A", "B", "C"};
int[] mylist = {100, 200};
boolean[] answers = {true, false};
```
查看: [Arrays](#java-数组)
### Swap
```java
int a = 1;
int b = 2;
System.out.println(a + " " + b); // 1 2
int temp = a;
a = b;
b = temp;
System.out.println(a + " " + b); // 2 1
```
### Type Casting
```java
// Widening
// byte<short<int<long<float<double
int i = 10;
long l = i; // 10
// Narrowing
double d = 10.02;
long l = (long)d; // 10
String.valueOf(10); // "10"
Integer.parseInt("10"); // 10
Double.parseDouble("10"); // 10.0
```
### 条件语句 Conditionals
```java
int j = 10;
if (j == 10) {
System.out.println("I get printed");
} else if (j > 10) {
System.out.println("I don't");
} else {
System.out.println("I also don't");
}
```
查看: [Conditionals](#java-conditionals)
### 用户输入
```java
Scanner in = new Scanner(System.in);
String str = in.nextLine();
System.out.println(str);
int num = in.nextInt();
System.out.println(num);
```
Java 字符串
-------
### 基本的
```java
String str1 = "value";
String str2 = new String("value");
String str3 = String.valueOf(123);
```
### 字符串连接
```java
String s = 3 + "str" + 3; // 3str3
String s = 3 + 3 + "str"; // 6str
String s = "3" + 3 + "str"; // 33str
String s = "3" + "3" + "23"; // 3323
String s = "" + 3 + 3 + "23"; // 3323
String s = 3 + 3 + 23; // 29
```
### 字符串生成器
<!--rehype:wrap-class=row-span-3-->
```java
StringBuilder sb = new StringBuilder(10);
```
---
```java
┌───┬───┬───┬───┬───┬───┬───┬───┬───┐
| | | | | | | | | |
└───┴───┴───┴───┴───┴───┴───┴───┴───┘
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 | ! | | |
└───┴───┴───┴───┴───┴───┴───┴───┴───┘
0 1 2 3 4 5 6 7 8 9
```
### 比较
```java
String s1 = new String("QuickRef");
String s2 = new String("QuickRef");
s1 == s2 // false
s1.equals(s2) // true
"AB".equalsIgnoreCase("ab") // true
```
### 操纵
```java
String str = "Abcd";
str.toUpperCase(); // ABCD
str.toLowerCase(); // abcd
str.concat("#"); // Abcd#
str.replace("b", "-"); // A-cd
" abc ".trim(); // abc
"ab".toCharArray(); // {'a', 'b'}
```
### 信息
```java
String str = "abcd";
str.charAt(2); // c
str.indexOf("a") // 0
str.indexOf("z") // -1
str.length(); // 4
str.toString(); // abcd
str.substring(2); // cd
str.substring(2,3); // c
str.contains("c"); // true
str.endsWith("d"); // true
str.startsWith("a"); // true
str.isEmpty(); // false
```
### 不可变
```java
String str = "hello";
str.concat("world");
// 输出: hello
System.out.println(str);
```
---
```java
String str = "hello";
String concat = str.concat("world");
// 输出: helloworld
System.out.println(concat);
```
一旦创建就不能修改任何修改都会创建一个新的String
Java 数组
-------
### 申明 Declare
```java
int[] a1;
int[] a2 = {1, 2, 3};
int[] a3 = new int[]{1, 2, 3};
int[] a4 = new int[3];
a4[0] = 1;
a4[2] = 2;
a4[3] = 3;
```
### 修改 Modify
```java
int[] a = {1, 2, 3};
System.out.println(a[0]); // 1
a[0] = 9;
System.out.println(a[0]); // 9
System.out.println(a.length); // 3
```
### 循环 (读 & 写)
```java
int[] arr = {1, 2, 3};
for (int i=0; i < arr.length; i++) {
arr[i] = arr[i] * 2;
System.out.print(arr[i] + " ");
}
// 输出: 2 4 6
```
### Loop (Read)
```java
String[] arr = {"a", "b", "c"};
for (int a: arr) {
System.out.print(a + " ");
}
// 输出: a b c
```
### Multidimensional Arrays
```java
int[][] matrix = { {1, 2, 3}, {4, 5} };
int x = matrix[1][0]; // 4
// [[1, 2, 3], [4, 5]]
Arrays.deepToString(matrix)
for (int i = 0; i < a.length; ++i) {
for(int j = 0; j < a[i].length; ++j) {
System.out.println(a[i][j]);
}
}
// 输出: 1 2 3 4 5 6 7
```
### Sort
```java
char[] chars = {'b', 'a', 'c'};
Arrays.sort(chars);
// [a, b, c]
Arrays.toString(chars);
```
Java 条件语句
-----------
### 运算符
<!--rehype:wrap-class=row-span-3-->
- `+` _(加法运算符(也用于字符串连接))_
- `-` _(减法运算符)_
- `*` _(乘法运算符)_
- `/` _(分区运算符)_
- `%` _(余数运算符)_
- `=` _(简单赋值运算符)_
- `++` _(增量运算符;将值增加 1)_
- `--` _(递减运算符;将值减 1)_
- `!` _(逻辑补码运算符;反转布尔值)_
<!--rehype:className=style-round-->
----
- `==` _(等于)_
- `!=` _(不等于)_
- `>` _(比...更棒)_
- `>=` _(大于或等于)_
- `<` _(少于)_
- `<=` _(小于或等于)_
<!--rehype:className=cols-2 style-round-->
----
- `&&` _条件与_
- `||` _条件或_
- [?:](#三元运算符) _三元(if-then-else 语句的简写)_
<!--rehype:className=style-round-->
----
- `instanceof` _(将对象与指定类型进行比较)_
<!--rehype:className=style-round-->
----
- `~` _(一元按位补码)_
- `<<` _(签名左移)_
- `>>` _(有符号右移)_
- `>>>` _(无符号右移)_
- `&` _(按位与)_
- `^` _(按位异或)_
- `|` _(按位包含 OR)_
<!--rehype:className=cols-2 style-round-->
### If else
```java
int k = 15;
if (k > 20) {
System.out.println(1);
} else if (k > 10) {
System.out.println(2);
} else {
System.out.println(3);
}
```
### Switch
<!--rehype:wrap-class=row-span-2-->
```java
int month = 3;
String str;
switch (month) {
case 1:
str = "January";
break;
case 2:
str = "February";
break;
case 3:
str = "March";
break;
default:
str = "Some other month";
break;
}
// 输出: Result March
System.out.println("Result " + str);
```
### 三元运算符
```java
int a = 10;
int b = 20;
int max = (a > b) ? a : b;
// 输出: 20
System.out.println(max);
```
Java 循环
----
### For 循环
```java
for (int i = 0; i < 10; i++) {
System.out.print(i);
}
// 输出: 0123456789
```
------
```java
for (int i = 0,j = 0; i < 3; i++,j--) {
System.out.print(j + "|" + i + " ");
}
// 输出: 0|0 -1|1 -2|2
```
### 增强的 For 循环
```java
int[] numbers = {1,2,3,4,5};
for (int number: numbers) {
System.out.print(number);
}
// 输出: 12345
```
用于循环数组或列表
### While 循环
```java
int count = 0;
while (count < 5) {
System.out.print(count);
count++;
}
// 输出: 01234
```
### Do While 循环
```java
int count = 0;
do {
System.out.print(count);
count++;
} while (count < 5);
// 输出: 01234
```
### 继续声明
```java
for (int i = 0; i < 5; i++) {
if (i == 3) {
continue;
}
System.out.print(i);
}
// 输出: 01245
```
### 中断语句
```java
for (int i = 0; i < 5; i++) {
System.out.print(i);
if (i == 3) {
break;
}
}
// 输出: 0123
```
Java 框架搜集
--------------------
### Java 搜集
<!--rehype:wrap-class=col-span-2 row-span-2-->
搜集 | Interface | 有序 | 已排序 | 线程安全 | 复制 | Nullable
:-|:-|:-|:-|:-|:-|:-
[ArrayList](https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html) | List | Y | _N_ | _N_ | Y | Y
[Vector](https://docs.oracle.com/javase/8/docs/api/java/util/Vector.html) | List | Y | _N_ | Y | Y | Y
[LinkedList](https://docs.oracle.com/javase/8/docs/api/java/util/LinkedList.html) | List, Deque | Y | _N_ | _N_ | Y | Y
[CopyOnWriteArrayList](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CopyOnWriteArrayList.html) | List | Y | _N_ | Y | Y | Y
[HashSet](https://docs.oracle.com/javase/8/docs/api/java/util/HashSet.html) | Set | _N_ | _N_ | _N_ | _N_ | One `null`
[LinkedHashSet](https://docs.oracle.com/javase/8/docs/api/java/util/LinkedHashSet.html) | Set | Y | _N_ | _N_ | _N_ | One `null`
[TreeSet](https://docs.oracle.com/javase/8/docs/api/java/util/TreeSet.html) | Set | Y | Y | _N_ | _N_ | _N_
[CopyOnWriteArraySet](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CopyOnWriteArraySet.html) | Set | Y | _N_ | Y | _N_ | One `null`
[ConcurrentSkipListSet](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentSkipListSet.html) | Set | Y | Y | Y | _N_ | _N_
[HashMap](https://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html) | Map | _N_ | _N_ | _N_ | _N (key)_ | One `null` _(key)_
[HashTable](https://docs.oracle.com/javase/8/docs/api/java/util/Hashtable.html) | Map | _N_ | _N_ | Y | _N (key)_ | _N (key)_
[LinkedHashMap](https://docs.oracle.com/javase/8/docs/api/java/util/LinkedHashMap.html) | Map | Y | _N_ | _N_ | _N (key)_ | One `null` _(key)_
[TreeMap](https://docs.oracle.com/javase/8/docs/api/java/util/TreeMap.html) | Map | Y | Y | _N_ | _N (key)_ | _N (key)_
[ConcurrentHashMap](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentHashMap.html) | Map | _N_ | _N_ | Y | _N (key)_ | _N_
[ConcurrentSkipListMap](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentSkipListMap.html) | Map | Y | Y | Y | _N (key)_ | _N_
[ArrayDeque](https://docs.oracle.com/javase/8/docs/api/java/util/ArrayDeque.html) | Deque | Y | _N_ | _N_ | Y | _N_
[PriorityQueue](https://docs.oracle.com/javase/8/docs/api/java/util/PriorityQueue.html) | Queue | Y | _N_ | _N_ | Y | _N_
[ConcurrentLinkedQueue](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentLinkedQueue.html) | Queue | Y | _N_ | Y | Y | _N_
[ConcurrentLinkedDeque](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentLinkedDeque.html) | Deque | Y | _N_ | Y | Y | _N_
[ArrayBlockingQueue](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ArrayBlockingQueue.html) | Queue | Y | _N_ | Y | Y | _N_
[LinkedBlockingDeque](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/LinkedBlockingDeque.html) | Deque | Y | _N_ | Y | Y | _N_
[PriorityBlockingQueue](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/PriorityBlockingQueue.html) | Queue | Y | _N_ | Y | Y | _N_
<!--rehype:className=show-header-->
### ArrayList
```java
List<Integer> nums = new ArrayList<>();
// 添加
nums.add(2);
nums.add(5);
nums.add(8);
// 检索
System.out.println(nums.get(0));
// 为循环迭代编制索引
for (int i = 0; i < nums.size(); i++) {
System.out.println(nums.get(i));
}
nums.remove(nums.size() - 1);
nums.remove(0); // 非常慢
for (Integer value : nums) {
System.out.println(value);
}
```
### HashMap
```java
Map<Integer, String> m = new HashMap<>();
m.put(5, "Five");
m.put(8, "Eight");
m.put(6, "Six");
m.put(4, "Four");
m.put(2, "Two");
// 检索
System.out.println(m.get(6));
// Lambda forEach
m.forEach((key, value) -> {
String msg = key + ": " + value;
System.out.println(msg);
});
```
### HashSet
```java
Set<String> set = new HashSet<>();
if (set.isEmpty()) {
System.out.println("Empty!");
}
set.add("dog");
set.add("cat");
set.add("mouse");
set.add("snake");
set.add("bear");
if (set.contains("cat")) {
System.out.println("Contains cat");
}
set.remove("cat");
for (String element : set) {
System.out.println(element);
}
```
### ArrayDeque
```java
Deque<String> a = new ArrayDeque<>();
// 使用 add()
a.add("Dog");
// 使用 addFirst()
a.addFirst("Cat");
// 使用 addLast()
a.addLast("Horse");
// [Cat, Dog, Horse]
System.out.println(a);
// 访问元素
System.out.println(a.peek());
// 移除元素
System.out.println(a.pop());
```
杂项 Misc
----
### 访问修饰符
<!--rehype:wrap-class=col-span-2-->
| 修饰符 | Class | Package | Subclass | World |
|-------------|-------|---------|----------|-------|
| public | Y | Y | Y | Y |
| protected | Y | Y | Y | _N_ |
| no modifier | Y | Y | _N_ | _N_ |
| private | Y | _N_ | _N_ | _N_ |
<!--rehype:className=show-header-->
### 常用表达
```java
String text = "I am learning Java";
// 删除所有空格
text.replaceAll("\\s+", "");
// 拆分字符串
text.split("\\|");
text.split(Pattern.quote("|"));
```
查看: [Regex in java](./regex.md#java-中的正则表达式)
### 注释 Comment
```java
// 我是单行注释!
/*
而我是一个
多行注释!
*/
/**
* 这个
* 是
* 文档
* 注释
*/
```
### 关键字
<!--rehype:wrap-class=col-span-2-->
- abstract
- continue
- for
- new
- switch
- assert
- default
- goto
- package
- synchronized
- boolean
- do
- if
- private
- this
- break
- double
- implements
- protected
- throw
- byte
- else
- import
- public
- throws
- case
- enum
- instanceof
- return
- transient
- catch
- extends
- int
- short
- try
- char
- final
- interface
- static
- void
- class
- finally
- long
- strictfp
- volatile
- const
- float
- native
- super
- while
<!--rehype:className=cols-7 style-none-->
### 数学方法
方法 | 说明
:-|:-
`Math.max(a,b)` | `a``b` 的最大值
`Math.min(a,b)` | `a``b` 的最小值
`Math.abs(a)` | 绝对值
`Math.sqrt(a)` | `a` 的平方根
`Math.pow(a,b)` | `b` 的幂
`Math.round(a)` | 最接近的整数
`Math.sin(ang)` | 正弦
`Math.cos(ang)` | `ang` 的余弦
`Math.tan(ang)` | `ang` 的切线
`Math.asin(ang)` | `ang` 的反正弦
`Math.log(a)` | `a` 的自然对数
`Math.toDegrees(rad)` | 以度为单位的角度弧度
`Math.toRadians(deg)` | 以弧度为单位的角度度
### Try/Catch/Finally
```java
try {
// something
} catch (Exception e) {
e.printStackTrace();
} finally {
System.out.println("always printed");
}
```
另见
---
- [Java 官网](https://www.java.com/zh-CN/) _(java.com)_

236
docs/jq.md Normal file
View 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)_

226
docs/lsof.md Normal file
View File

@ -0,0 +1,226 @@
Lsof 备忘清单
===
这个快速参考备忘单提供了使用 lsof 命令的各种方法。
入门
----
### 介绍
**lsof** 表示 `L`i`s`t `O`pen `F`iles 用于查找哪个进程打开了哪些文件
```shell
$ lsof
$ sudo lsof -u root
```
### 特定于端口
```shell
$ lsof -i :8080
$ lsof -i :80 -i :22
$ lsof -i TCP:22
$ lsof -i TCP:1-1024
$ lsof -i UDP
$ lsof -i @192.168.1.5
```
### 特定于进程
```shell
$ lsof -c mysql
$ lsof -c java
$ lsof -c ssh
$ lsof -c nginx
$ lsof -c ssh -c httpd
```
### 特定于用户
```shell
$ lsof -u www-data
$ lsof -u www-data -u ubuntu
$ lsof -i -u ^root # 特定用户除外
```
### 特定于网络
```shell
$ lsof -i 4 # 仅 IPv4
$ lsof -i 6 # 仅 IPv6
```
### 特定的PID
```shell
$ lsof -p 1753
$ lsof -p ^3 # 除了某些pid
```
### 特定文件名
```shell
$ lsof /var/log/messages
$ lsof /etc/passwd
```
### 特定目录
```shell
$ lsof +D /var/log # 在目录内
```
### Kill
```shell
$ kill -9 `lsof -t -u apache`
$ kill -9 $(lsof -t -i :8080)
```
### 参数
<!--rehype:wrap-class=row-span-2-->
```bash
-a # 列出打开文件存在的进程;
-c<进程名> # 列出指定进程所打开的文件;
-g # 列出GID号进程详情
-d<文件号> # 列出占用该文件号的进程;
+d<目录> # 列出目录下被打开的文件;
+D<目录> # 递归列出目录下被打开的文件;
-n<目录> # 列出使用NFS的文件
-i<条件> # 列出符合条件的进程(协议,:端口,@ip)
-p<进程号> # 列出指定进程号所打开的文件;
-u # 列出UID号进程详情
-h # 显示帮助信息;
-v # 显示版本信息
```
### 列出指定进程号所打开的文件
```bash
lsof -p $pid
```
### 获取端口对应的进程 ID=>pid
```bash
lsof -i:9981 -P -t -sTCP:LISTEN
```
### 列出打开文件的进程:
```bash
lsof $filename
```
示例
---
### 示例
<!--rehype:wrap-class=col-span-2-->
```bash
$ lsof
command PID USER FD type DEVICE SIZE NODE NAME
init 1 root cwd DIR 8,2 4096 2 /
init 1 root rtd DIR 8,2 4096 2 /
init 1 root txt REG 8,2 43496 6121706 /sbin/init
init 1 root mem REG 8,2 143600 7823908 /lib64/ld-2.5.so
init 1 root mem REG 8,2 1722304 7823915 /lib64/libc-2.5.so
init 1 root mem REG 8,2 23360 7823919 /lib64/libdl-2.5.so
init 1 root mem REG 8,2 95464 7824116 /lib64/libselinux.so.1
init 1 root mem REG 8,2 247496 7823947 /lib64/libsepol.so.1
init 1 root 10u FIFO 0,17 1233 /dev/initctl
migration 2 root cwd DIR 8,2 4096 2 /
migration 2 root rtd DIR 8,2 4096 2 /
migration 2 root txt unknown /proc/2/exe
```
### 文件描述符列表(FD)
<!--rehype:wrap-class=row-span-3-->
:- | :-
:- | :-
`cwd` | 表示当前工作目录,即:应用程序的当前工作目录,这是该应用程序启动的目录,除非它本身对这个目录进行更改
`txt` | 该类型的文件是程序代码,如应用程序二进制文件本身或共享库,如上列表中显示的 /sbin/init 程序
`lnn` | 库引用 (AIX);
`er` | FD 信息错误(参见名称栏)
`jld` | jail 目录 (FreeBSD);
`ltx` | 共享库文本(代码和数据)
`mxx` | 十六进制内存映射类型编号xx
`m86` | DOS合并映射文件
`mem` | 内存映射文件
`mmap` | 内存映射设备
`pd` | 父目录
`rtd` | 根目录
`tr` | 内核跟踪文件 (OpenBSD)
`v86` | VP/ix 映射文件
`0` | 表示标准输出
`1` | 表示标准输入
`2` | 表示标准错误
<!--rehype:className=style-list-arrow-->
### 示例列信息
:- | :-
:- | :-
`COMMAND` | 进程的名称
`PID` | 进程标识符
`PPID` | 父进程标识符(需要指定-R参数
`USER` | 进程所有者
`PGID` | 进程所属组
`FD` | 文件描述符,应用程序通过它识别该文件
### 标准输出/输入/错误文件状态模式(FD)
:- | :-
:- | :-
`u` | 表示该文件被打开并处于读取/写入模式
`r` | 表示该文件被打开并处于只读模式
`w` | 表示该文件被打开并处于写入模式
`空格` | 表示该文件的状态模式为 unknow且没有锁定
`-` | 表示该文件的状态模式为 unknow且被锁定
一般在[标准输出/输入/错误](#文件描述符列表fd)后还跟着文件状态模式
### 文件状态模锁 (FD)
:- | :-
:- | :-
`N` | 对于未知类型的Solaris NFS锁
`r` | 用于部分文件的读取锁定
`R` | 对整个文件进行读取锁定
`w` | 对文件的一部分进行写锁定(文件的部分写锁)
`W` | 对整个文件进行写锁定(整个文件的写锁)
`u` | 用于任何长度的读写锁
`U` | 对于未知类型的锁
`x` | 对于文件部分的SCO OpenServer Xenix锁
`X` | 对于整个文件的SCO OpenServer Xenix锁
`space` | 如果没有锁
在[文件状态模式](#标准输出输入错误文件状态模式fd)后面,还跟着相关的锁
### 文件类型
标识 | 说明
:- | :-
`DIR` | 表示目录
`CHR` | 表示字符类型
`BLK` | 块设备类型
`UNIX` | UNIX 域套接字
`FIFO` | 先进先出 (FIFO) 队列
`IPv4` | 网际协议 (IP) 套接字
`DEVICE` | 指定磁盘的名称
`SIZE` | 文件的大小
`NODE` | 索引节点(文件在磁盘上的标识)
`NAME` | 打开文件的确切名称
`REG` | 常规文件
另见
---
- [lsof 命令帮助文档](https://jaywcjlove.github.io/linux-command/c/lsof.html) _(jaywcjlove.github.io)_

1409
docs/matlab.md Normal file

File diff suppressed because it is too large Load Diff

107
docs/mime.md Normal file
View File

@ -0,0 +1,107 @@
MIME 类型 备忘清单
===
此备忘单列出了一些常见的 Web MIME 类型。 您可以查看包含所有已注册 MIME 类型的 [IANA/MIME 媒体类型注册表](https://www.iana.org/assignments/media-types/media-types.xhtml)。
入门
----
### 介绍
<!--rehype:style=display:none;&wrap-style=padding-top:0;&wrap-class=col-span-3-->
- MIME 类型注册表关联特定的文件扩展名和文件名模式
- MIME多用途 Internet 邮件扩展)类型又名媒体类型
- MIME 类型在 IETF 的 RFC 6838 中定义和标准化
- 表示文档、文件或字节分类的性质和格式。
- 对于 Internet 上的文件格式或格式内容
<!--rehype:className=style-round-->
MIME 类型列表
--------
### 常见的 MIME媒体类型
<!--rehype:wrap-class=col-span-3-->
扩展名 | MIME 类型(内容类型) | 文件种类
:-|:-|:-
\.aac | audio/aac | AAC 音频
\.abw | application/x\-abiword | AbiWord 文档
\.arc | application/x\-freearc | 存档文档(嵌入多个文件)
\.avi | video/x\-msvideo | AVI: 音频视频交错
\.azw | application/vnd\.amazon\.ebook | 亚马逊 Kindle 电子书格式
\.bin | application/octet\-stream | 任何类型的二进制数据
\.bmp | image/bmp | Windows OS/2 位图图形
\.bz | application/x\-bzip | BZip 存档
\.bz2 | application/x\-bzip2 | BZip2 存档
\.csh | application/x\-csh | C\-Shell 脚本
\.css | text/css | 级联样式表 (CSS)
\.csv | text/csv | 逗号分隔值 (CSV)
\.doc | application/msword | 微软 Word
\.docx | application/vnd\.openxmlformats\-officedocument\.wordprocessingml\.document | 微软 Word (OpenXML)
\.eot | application/vnd\.ms\-fontobject | MS 嵌入式 OpenType 字体
\.epub | application/epub\+zip | 电子出版物 (EPUB)
\.gz | application/gzip | GZip 压缩存档
\.gif | image/gif | 图形交换格式 (GIF)
\.htm \.html | text/html | 超文本标记语言 (HTML)
\.ico | image/vnd\.microsoft\.icon | 图标格式
\.ics | text/calendar | iCalendar 格式
\.jar | application/java\-archive | Java 存档 (JAR)
\.jpeg \.jpg | image/jpeg | JPEG 图像
\.js | text/javascript | JavaScript
\.json | application/json | JSON格式
\.jsonld | application/ld\+json | JSON\-LD 格式
\.mid \.midi | audio/midi audio/x\-midi | 乐器数字接口 (MIDI)
\.mjs | text/javascript | JavaScript 模块
\.mp3 | audio/mpeg | MP3 音频
\.mpeg | video/mpeg | MPEG 视频
\.mpkg | application/vnd\.apple\.installer\+xml | Apple 安装程序包
\.odp | application/vnd\.oasis\.opendocument\.presentation | OpenDocument 演示文档
\.ods | application/vnd\.oasis\.opendocument\.spreadsheet | OpenDocument 电子表格文档
\.odt | application/vnd\.oasis\.opendocument\.text | OpenDocument 文本文档
\.oga | audio/ogg | OGG 音频
\.ogv | video/ogg | OGG 视频
\.ogx | application/ogg | OGG
\.opus | audio/opus | Opus 音频
\.otf | font/otf | OpenType 字体
\.png | image/png | 便携式网络图形
\.pdf | application/pdf | Adobe 便携式文档格式 (PDF)
\.php | application/php | 超文本预处理器(个人主页)
\.ppt | application/vnd\.ms\-powerpoint | 微软PowerPoint
\.pptx | application/vnd\.openxmlformats\-officedocument\.presentationml\.presentation | 微软 PowerPoint (OpenXML)
\.rar | application/vnd\.rar | RAR 存档
\.rtf | application/rtf | 富文本格式 (RTF)
\.sh | application/x\-sh | Bourne shell 脚本
\.svg | image/svg\+xml | 可缩放矢量图形 (SVG)
\.swf | application/x\-shockwave\-flash | 小型 Web 格式 (SWF) 或 Adobe Flash 文档
\.tar | application/x\-tar | Tape 存档 (TAR)
\.tif \.tiff | image/tiff | 标记图像文件格式 (TIFF)
\.ts | video/mp2t | MPEG 传输流
\.ttf | font/ttf | TrueType 字体
\.txt | text/plain | 文本,(通常为 ASCII 或 ISO 8859\-n
\.vsd | application/vnd\.visio | 微软 Visio
\.wav | audio/wav | Waveform 音频格式
\.weba | audio/webm | WEBM 音频
\.webm | video/webm | WEBM视频
\.webp | image/webp | WEBP图像
\.woff | font/woff | Web 开放字体格式 (WOFF)
\.woff2 | font/woff2 | Web 开放字体格式 (WOFF)
\.xhtml | application/xhtml\+xml | XHTML
\.xls | application/vnd\.ms\-excel | Microsoft Excel
\.xlsx | application/vnd\.openxmlformats\-officedocument\.spreadsheetml\.sheet | Microsoft Excel (OpenXML)
\.xml | application/xml 如果临时用户不可读(RFC 3023第 3 节) text/xml如果临时用户可读(RFC 3023第 3 节) | XML
\.xul | application/vnd\.mozilla\.xul\+xml | XUL
\.zip | application/zip | ZIP 档案
\.3gp | video/3gpp audio/3gpp 如果它不包含视频 | 3GPP 音视频容器
\.3g2 | video/3gpp2 audio/3gpp2 如果它不包含视频 | 3GPP2 音视频容器
\.7z | application/x\-7z\-compressed | 7-zip 存档
\.markdown \.md | text/markdown | Markdown 文件
<!--rehype:className=show-header-->
另见
---
- [iana mime.types](http://www.iana.org/assignments/media-types/media-types.xhtml) _(iana.org)_
- [apache mime.types](http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types) _(svn.apache.org)_
- [nginx mime.types](http://hg.nginx.org/nginx/raw-file/default/conf/mime.types) _(hg.nginx.org)_

605
docs/mysql.md Normal file
View File

@ -0,0 +1,605 @@
MySQL 备忘清单
===
本备忘单旨在快速理解 [MySQL](https://mysql.com) 所涉及的主要概念提供了最常用的SQL语句供您参考。
入门
---
### 介绍
<!--rehype:wrap-class=row-span-3-->
MySQL 为关系型数据库(Relational Database Management System),一个关系型数据库由一个或数个表格组成,如下所示的一个表格
----
```bash
name ▼ 键 ▼ 列(col)
┌┈┈┈┈┬┈┈┈┈┈┈┈┈┬┈┈┈┈┈┈┬┈┈┈┈┈┈┈┐
┆ id ┆ name ┆ uid ┆ level ┆ ◀ 表头header
├┈┈┈┈┼┈┈┈┈┈┈┈┈┤┈┈┈┈┈┈┤┈┈┈┈┈┈┈┤
1 ┆ mysql ┆ 03
├┈┈┈┈┼┈┈┈┈┈┈┈┈┤┈┈┈┈┈┈┤┈┈┈┈┈┈┈┤
2 ┆ redis ┆ 121 ┆ ◀ 行 row
└┈┈┈┈┴┈┈┈┈┈┈┈┈┴┈┈┈┈┈┈┴┈┈┈┈┈┈┈┘
redis ▲ 值
```
----
- `表头(header)` 每一列的名称
- `列(col)` 具有相同数据类型的数据的集合
- `行(row)` 每一行用来描述某个人/物的具体信息
- `值(value)` 行的具体信息,每个值与该列数据类型相同
- `键(key)` 用来识别某个特定的人/物的方法,有唯一性
### 登录MySQL
```shell
# 默认用户名<root>-p 是密码,
# ⚠️参数后面不需要空格
mysql -h 127.0.0.1 -u <用户名> -p<密码>
mysql -D 数据库名 -h 主机名 -u 用户名 -p
mysql -h <host> -P <端口号> -u <user> -p [db_name]
mysql -h <host> -u <user> -p [db_name]
```
### 常用的
<!--rehype:wrap-class=row-span-3-->
#### 数据库 Database
:-|:-
:-|:-
`CREATE DATABASE` db `;` | `创建`数据库
`SHOW DATABASES;` | `列出`数据库
`USE` db`;` | `切换`到数据库
`CONNECT` db `;` | `切换`到数据库
`DROP DATABASE` db`;` | `删除`数据库
#### 表 Table
:-|:-
:-|:-
`SHOW TABLES;` | 列出当前数据库的表
`SHOW FIELDS FROM` t`;` | 表的列表字段
`DESC` t`;` | 显示表格结构
`SHOW CREATE TABLE `t`;` | 显示创建表sql
`TRUNCATE TABLE `t`;` | 删除表中的所有数据
`DROP TABLE `t`;` | 删除表格
#### Proccess
:-|:-
:-|:-
`show processlist;` | 列出进程
`kill` pid`;` | 杀死进程
### 查看 MySQL 信息
```shell
# 显示当前mysql的version的各种信息
mysql> status;
# 显示当前mysql的version信息
mysql> select version();
# 查看 MySQL 端口号
mysql> show global variables like 'port';
```
### 退出MySQL会话
```bash
mysql> exit
```
退出 `quit;``\q;` 一样的效果
### 备份
创建备份
```sql
mysqldump -u user -p db_name > db.sql
```
导出不带架构的数据库
```shell
mysqldump -u user -p db_name --no-data=true --add-drop-table=false > db.sql
```
<!--rehype:className=wrap-text -->
恢复备份
```shell
mysql -u user -p db_name < db.sql
```
MySQL 示例
------
### 管理表格
创建一个包含三列的新表
```sql
CREATE TABLE t (
id INT,
name VARCHAR DEFAULT NOT NULL,
price INT DEFAULT 0
PRIMARY KEY(id)
);
```
从数据库中删除表
```sql
DROP TABLE t ;
```
向表中添加新列
```sql
ALTER TABLE t ADD column;
```
从表中删除列c
```sql
ALTER TABLE t DROP COLUMN c ;
```
添加约束
```sql
ALTER TABLE t ADD constraint;
```
删除约束
```sql
ALTER TABLE t DROP constraint;
```
将表从t1重命名为t2
```sql
ALTER TABLE t1 RENAME TO t2;
```
将列c1重命名为c2
```sql
ALTER TABLE t1 RENAME c1 TO c2 ;
```
删除表中的所有数据
```sql
TRUNCATE TABLE t;
```
### 从表中查询数据
从表中查询列c1、c2中的数据
```sql
SELECT c1, c2 FROM t
```
查询表中的所有行和列
```sql
SELECT * FROM t
```
查询数据并使用条件筛选行
```sql
SELECT c1, c2 FROM t
WHERE condition
```
查询表中的不同行
```sql
SELECT DISTINCT c1 FROM t
WHERE condition
```
按升序或降序对结果集排序
```sql
SELECT c1, c2 FROM t
ORDER BY c1 ASC [DESC]
```
跳过行的偏移并返回下n行
```sql
SELECT c1, c2 FROM t
ORDER BY c1
LIMIT n OFFSET offset
```
使用聚合函数对行进行分组
```sql
SELECT c1, aggregate(c2)
FROM t
GROUP BY c1
```
使用HAVING子句筛选组
```sql
SELECT c1, aggregate(c2)
FROM t
GROUP BY c1
HAVING condition
```
### 从多个表查询
<!--rehype:wrap-class=row-span-2-->
内部连接 t1 和 t2
```sql
SELECT c1, c2
FROM t1
INNER JOIN t2 ON condition
```
左连接t1和t1
```sql
SELECT c1, c2
FROM t1
LEFT JOIN t2 ON condition
```
右连接t1和t2
```sql
SELECT c1, c2
FROM t1
RIGHT JOIN t2 ON condition
```
执行完全外部连接
```sql
SELECT c1, c2
FROM t1
FULL OUTER JOIN t2 ON condition
```
生成表中行的笛卡尔积
```sql
SELECT c1, c2
FROM t1
CROSS JOIN t2
```
执行交叉连接的另一种方法
```sql
SELECT c1, c2
FROM t1, t2
```
使用INNER Join子句将t1连接到自身
```sql
SELECT c1, c2
FROM t1 A
INNER JOIN t1 B ON condition
```
使用SQL运算符合并两个查询中的行
```sql
SELECT c1, c2 FROM t1
UNION [ALL]
SELECT c1, c2 FROM t2
```
返回两个查询的交集
```sql
SELECT c1, c2 FROM t1
INTERSECT
SELECT c1, c2 FROM t2
```
从另一个结果集中减去一个结果集
```sql
SELECT c1, c2 FROM t1
MINUS
SELECT c1, c2 FROM t2
```
使用模式匹配%查询行_
```sql
SELECT c1, c2 FROM t1
WHERE c1 [NOT] LIKE pattern
```
查询列表中的行
```sql
SELECT c1, c2 FROM t
WHERE c1 [NOT] IN value_list
```
查询两个值之间的行
```sql
SELECT c1, c2 FROM t
WHERE c1 BETWEEN low AND high
```
检查表中的值是否为NULL
```sql
SELECT c1, c2 FROM t
WHERE c1 IS [NOT] NULL
```
### 使用 SQL 约束
将c1和c2设置为主键
```sql
CREATE TABLE t(
c1 INT, c2 INT, c3 VARCHAR,
PRIMARY KEY (c1,c2)
);
```
将c2列设置为外键
```sql
CREATE TABLE t1(
c1 INT PRIMARY KEY,
c2 INT,
FOREIGN KEY (c2) REFERENCES t2(c2)
);
```
使c1和c2中的值唯一
```sql
CREATE TABLE t(
c1 INT, c1 INT,
UNIQUE(c2,c3)
);
```
确保c1>0和c1>=c2中的值
```sql
CREATE TABLE t(
c1 INT, c2 INT,
CHECK(c1> 0 AND c1 >= c2)
);
```
c2列中的设置值不为NULL
```sql
CREATE TABLE t(
c1 INT PRIMARY KEY,
c2 VARCHAR NOT NULL
);
```
### 修改数据
在表格中插入一行
```sql
INSERT INTO t(column_list)
VALUES(value_list);
```
在表格中插入多行
```sql
INSERT INTO t(column_list)
VALUES (value_list),
(value_list), ;
```
将行从t2插入t1
```sql
INSERT INTO t1(column_list)
SELECT column_list
FROM t2;
```
更新列c1中所有行的新值
```sql
UPDATE t
SET c1 = new_value;
```
更新列c1、c2中与条件匹配的值
```sql
UPDATE t
SET c1 = new_value,
c2 = new_value
WHERE condition;
```
删除表中的所有数据
```sql
DELETE FROM t;
```
删除表中的行子集
```sql
DELETE FROM t
WHERE condition;
```
### 管理视图
<!--rehype:wrap-class=row-span-2-->
创建由c1和c2组成的新视图
```sql
CREATE VIEW v(c1,c2)
AS
SELECT c1, c2
FROM t;
```
使用选中选项创建新视图
```sql
CREATE VIEW v(c1,c2)
AS
SELECT c1, c2
FROM t;
WITH [CASCADED | LOCAL] CHECK OPTION;
```
创建递归视图
```sql
CREATE RECURSIVE VIEW v
AS
select-statement -- anchor part
UNION [ALL]
select-statement; -- recursive part
```
创建临时视图
```sql
CREATE TEMPORARY VIEW v
AS
SELECT c1, c2
FROM t;
```
删除视图
```sql
DROP VIEW view_name;
```
### 管理触发器
创建或修改触发器
```sql
CREATE OR MODIFY TRIGGER trigger_name
WHEN EVENT
ON table_name TRIGGER_TYPE
EXECUTE stored_procedure;
```
#### WHEN
:-|:-
:-|:-
`BEFORE` | 在事件发生前调用
`AFTER` | 事件发生后调用
#### EVENT
:-|:-
:-|:-
`INSERT` | 为INSERT调用
`UPDATE` | 调用UPDATE
`DELETE` | 调用DELETE
#### TRIGGER_TYPE
:-|:-
:-|:-
`FOR EACH ROW` | -
`FOR EACH STATEMENT` | -
### 管理索引
在t表的c1和c2上创建索引
```sql
CREATE INDEX idx_name
ON t(c1,c2);
```
在t表的c3、c4上创建唯一索引
```sql
CREATE UNIQUE INDEX idx_name
ON t(c3,c4)
```
删除索引
```sql
DROP INDEX idx_name;
```
MySQL 数据类型
---------
### Strings
| - | - |
|--------------|-----------------------------|
| `CHAR` | String (0 - 255) |
| `VARCHAR` | String (0 - 255) |
| `TINYTEXT` | String (0 - 255) |
| `TEXT` | String (0 - 65535) |
| `BLOB` | String (0 - 65535) |
| `MEDIUMTEXT` | String (0 - 16777215) |
| `MEDIUMBLOB` | String (0 - 16777215) |
| `LONGTEXT` | String (0 - 429496­7295) |
| `LONGBLOB` | String (0 - 429496­7295) |
| `ENUM` | One of preset options |
| `SET` | Selection of preset options |
### Date & time
| Data Type | Format |
|-------------|---------------------|
| `DATE ` | yyyy-MM-dd |
| `TIME ` | hh:mm:ss |
| `DATETIME ` | yyyy-MM-dd hh:mm:ss |
| `TIMESTAMP` | yyyy-MM-dd hh:mm:ss |
| `YEAR ` | yyyy |
### Numeric
| - | - |
|---------------|---------------------------------------------------------------|
| `TINYINT x` | Integer (-128 to 127) |
| `SMALLINT x` | Integer (-32768 to 32767) |
| `MEDIUMINT x` | Integer (-8388608 to 8388607) |
| `INT x` | Integer (-2147­483648 to 214748­3647) |
| `BIGINT x` | Integer (-9223­372­036­854­775808 to 922337­203­685­477­5807) |
| `FLOAT` | Decimal (precise to 23 digits) |
| `DOUBLE` | Decimal (24 to 53 digits) |
| `DECIMAL` | "­DOU­BLE­" stored as string |
另见
---
- [SQL 基础教程](http://www.w3school.com.cn/sql/index.asp) _(w3school.com.cn)_
- [SQL 语句教程](http://www.1keydata.com/cn/sql/sql-count.php) _(1keydata.com)_
- [21分钟 MySQL 基础入门](https://jaywcjlove.github.io/mysql-tutorial/21-minutes-MySQL-basic-entry.html) _(jaywcjlove.github.io)_

View File

@ -192,7 +192,7 @@ $ cat video.avi | nc -l 8000
客户端 Client
```shell {.wrap}
```shell
$ nc 192.168.1.9 8000 | mplayer -vo x11 -cache 3000 -
```

View File

@ -1,7 +1,7 @@
NGINX 备忘清单
===
这个 nginx 快速参考备忘单显示了它的常用命和配置使用清单。
这个 [nginx](https://nginx.org/en/) 快速参考备忘单显示了它的常用命和配置使用清单。
入门
----

View File

@ -1,7 +1,7 @@
npm 备忘清单
===
这个 npm 快速参考备忘单显示了它的常用命令使用清单
这个 [npm](https://www.npmjs.com/) 快速参考备忘单显示了它的常用命令使用清单
常用命令
----
@ -9,147 +9,152 @@ npm 备忘清单
### 包管理
| 命令 | 描述 |
| --- | --- |
| `npm i` | `npm install`的别名 |
| `npm install` | 安装 package.json 中的所有内容 |
| `npm install --production` | 安装 package.json 中的所有内容除了 devDependecies |
| `npm install lodash` | 安装一个包 |
| `npm install --save-dev lodash` | 安装为 devDependency |
| `npm install --save-exact lodash` | 准确安装 |
| `npm install @scope/package-name` | 安装一个作用域的公共包 |
| `npm install <package_name>@<tag>` | 使用 dist-tags 安装包 |
| `npm install -g <package_name>` | 全局安装包 |
| `npm uninstall <package_name>` | 卸载包 |
命令 | 描述
:- |:-
`npm init -y` | 创建 `package.json` 文件
`npm install` `npm i` | 安装 `package.json` 中的所有内容
`npm install --production` | 安装 `package.json` 中的所有内容 <br /> _(除了 `devDependecies`)_
`npm install lodash` | 安装一个包
`npm install --save-dev lodash` | 安装为 `devDependency`
`npm install --save-exact lodash` | 准确安装
`npm install @scope/package-name` | 安装一个作用域的公共包
`npm install <package_name>@<tag>` | 使用 `dist-tags` 安装包
`npm install -g <package_name>` | 全局安装包
`npm uninstall <package_name>` | 卸载包
<!--rehype:class=auto-wrap-->
`--save` 是 npm@5 的默认值。 以前,使用不带 `--save``npm install` 不会更新 package.json。
### 安装
<!--rehype:wrap-class=row-span-3-->
### 安装名称
| 命令 | 描述 |
| --- | --- |
| `npm i sax` | NPM 包 |
| `npm i sax@latest` | 指定标签“最新” |
| `npm i sax@3.0.0` | 指定版本 `3.0.0` |
| `npm i sax@">=1 <2.0"` | 指定版本范围 |
| `npm i @org/sax` | 范围内的 NPM 包 |
| `npm i user/repo` | GitHub |
| `npm i user/repo#master` | GitHub |
| `npm i github:user/repo` | GitHub |
| `npm i gitlab:user/repo` | GitLab |
| `npm i /path/to/repo` | 绝对路径 |
| `npm i ./archive.tgz` | 压缩包 |
| `npm i https://site.com/archive.tgz` | 通过 HTTP 压缩包 |
命令 | 描述
:- |:-
`npm i sax` | `NPM`
`npm i sax@latest` | 指定标签 `最新`
`npm i sax@3.0.0` | 指定版本 `3.0.0`
`npm i sax@">=1 <2.0"` | 指定版本范围
`npm i @org/sax` | 范围内的 `NPM`
`npm i user/repo` | GitHub
`npm i user/repo#master` | GitHub
`npm i github:user/repo` | GitHub
`npm i gitlab:user/repo` | GitLab
`npm i /path/to/repo` | 绝对路径
`npm i ./archive.tgz` | 压缩包
`npm i https://site.com/archive.tgz` | 通过 `HTTP` 压缩包
<!--rehype:class=auto-wrap-->
安装依赖的可用参数
- `-P`, `--save-prod` 包将出现在您的依赖项中,这是默认值(npm v8),除非存在 `-D``-O`
- `-D`, `--save-dev` 包会出现在你的 `devDependencies`
- `-O`, `--save-optional` 包将出现在您的 `optionalDependencies`
- `--no-save` 防止保存到依赖项
- `-E`, `--save-exact` 依赖项将使用精确的版本进行配置,而不是使用 `npm` 的默认 [`semver`](./semver.md) 范围运算符
- `-B`, `--save-bundle` 依赖项也将添加到您的 [`bundleDependencies`](./package.json.md#bundleddependencies) 列表中
<!--rehype:className=style-arrow-->
命令 `npm i``npm install` 的别名
### 清单
| 命令 | 描述 |
| --- | --- |
| `npm list` | 列出此软件中所有依赖项的已安装版本 |
| `npm list -g --depth 0` | 列出所有全局安装包的安装版本 |
| `npm view` | 列出此软件中所有依赖项的最新版本 |
| `npm outdated` | 仅列出此软件中已过时的依赖项 |
命令 | 描述
:- |:-
`npm list` | 列出此软件中所有依赖项的已安装版本
`npm list -g --depth 0` | 列出所有全局安装包的安装版本
`npm view` | 列出此软件中所有依赖项的最新版本
`npm outdated` | 仅列出此软件中已过时的依赖项
<!--rehype:class=auto-wrap-->
### 缓存 cache
```bash
$ npm cache add <package-spec> # 将指定的包添加到本地缓存
$ npm cache clean [<key>] # 删除缓存文件夹中的所有数据
$ npm cache ls [<name>@<version>]
$ npm cache verify # 验证缓存文件夹的内容,垃圾收集任何不需要的数据,
# 并验证缓存索引和所有缓存数据的完整性
```
用于添加、列出或清理 [npm](https://www.npmjs.com/) 缓存文件夹
### 更新
| 命令 | 描述 |
| --- | --- |
| `npm version <version>` | 要更改 `package.json` 中的版本号 |
| `npm update` | 更新生产包 |
| `npm update --dev` | 更新开发包 |
| `npm update -g` | 更新全局包 |
| `npm update lodash` | 更新 lodash 包 |
命令 | 描述
:- | -
`npm version <version>` | 要更改 `package.json` 中的版本号
`npm update` | 更新生产包
`npm update --dev` | 更新开发包
`npm update -g` | 更新全局包
`npm update lodash` | 更新 `lodash`
### 杂项功能
<!--rehype:wrap-class=row-span-2-->
将某人添加为所有者
```bash
npm owner add USERNAME PACKAGENAME
```
列出包
```bash
npm ls
```
向安装旧版本软件包的用户添加警告(弃用)
```bash
npm deprecate PACKAGE@"< 0.2.0" "critical bug fixed in v0.2.0"
```
更新所有包或选定的包
```bash
npm update [-g] PACKAGE
```
检查过时的包
```bash
npm outdated [PACKAGE]
```
### 更改包裹可见性
将公共包设为私有
```bash
npm access restricted <package-name>
```
公开私有包
```bash
npm access restricted <package-name>
```
授予私有包访问权限
```bash
npm owner add <user> <your-package-name>
```
### 要将包转移到 npm 用户帐户
```bash
npm owner add <their-username> <package-name>
# 新维护者接受邀请
npm owner rm <your-username> <package-name>
```
写入启用了双因素身份验证
```bash
npm owner add <their-username> <package-name> --otp=123456
# 将某人添加为所有者
$ npm owner add USERNAME PACKAGENAME
# 列出包
$ npm ls
# 向安装旧版本软件包的用户添加警告(弃用)
$ npm deprecate PACKAGE@"< 0.2.0" "critical bug fixed in v0.2.0"
# 更新所有包或选定的包
$ npm update [-g] PACKAGE
# 检查过时的包
$ npm outdated [PACKAGE]
```
### 取消发布包
```bash
npm unpublish <package-name> -f
$ npm unpublish <package-name> -f
# 取消指定版本
npm unpublish <package-name>@<version>
$ npm unpublish <package-name>@<version>
```
注意:如果您取消发布整个包,则必须在 24 小时后才能发布该包的任何新版本
注意:如果您取消发布整个包,则必须在 24 小时后才能发布该包的任何新版本
### 更改包裹可见性
```bash
# 将公共包设为私有
$ npm access restricted <package-name>
# 公开私有包
$ npm access public <package-name>
# 授予私有包访问权限
$ npm owner add <user> <your-package-name>
```
### 要将包转移到 npm 用户帐户
```bash
# 新维护者接受邀请
$ npm owner add <their-username> <package-name>
# 删除维护者
$ npm owner rm <your-username> <package-name>
# 写入启用了双因素身份验证
$ npm owner add <their-username> <package-name> --otp=123456
```
### 发布包 npmjs.org
```bash
npm publish
$ npm publish
# 第一次需要指定公开参数
npm publish --access public
$ npm publish --access public
```
发布公开包,到 npmjs.org
发布公开包,到 [npmjs.org](https://docs.npmjs.com)
### 使用 nrm 切换 registry
```bash
$ npm install -g nrm # 安装 nrm 包
# 查看 registry 列表
$ nrm ls
# 将注册表切换到 cnpm
$ nrm use cnpm
```
配置
---
@ -165,15 +170,27 @@ npm publish --access public
### 配置内容
<!--rehype:wrap-class=col-span-2-->
```ini
# last modified: 01 Jan 2016
; Set a new registry for a scoped package
@myscope:registry=https://mycustomregistry.example.org
@myscope:registry=https://registry.npmmirror.com
```
<!--rehype:className=wrap-text -->
注释使用 `#`, `;` 放置到一行的开头`.npmrc` 文件由指定此注释语法的 [`npm/ini`](https://github.com/npm/ini) 解析
注释使用 `#`, `;` 放置到一行的开头 [`.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/
### `.npmignore`
@ -193,19 +210,21 @@ npm publish --access public
`.npmignore` 文件就像 [`.gitignore`](./git.md#忽略文件) 一样工作。它不能覆盖 `package.json#files` 字段。
### 中国镜像站安装
<!--rehype:wrap-class=col-span-2-->
<!--rehype:wrap-class=col-span-2 row-span-2-->
```bash
# 临时使用
$ npm install -g <package-name> --registry=https://registry.npmmirror.com
```
将配置放置在 `.npmrc` 配置文件中。
将配置放置在 [`.npmrc`](https://docs.npmjs.com/cli/v8/configuring-npm/npmrc) 全局配置文件中,或者在项目的根目录中。
```ini
; registry=https://registry.npmjs.org/
registry=https://registry.npmmirror.com
```
或者配置到 `package.json#publishConfig` 字段上
或者配置到 [`package.json#publishConfig`](./package.json.md#publishconfig) 字段上
```json
"publishConfig":{
@ -213,4 +232,37 @@ registry=https://registry.npmmirror.com
}
```
请参阅:[npmmirror 中国镜像站](https://npmmirror.com/)
替换 npm 仓库地址为 npmmirror(淘宝) 镜像地址
```bash
$ npm config set registry https://registry.npmmirror.com
```
请参阅:[npmmirror 中国镜像站](https://npmmirror.com/)
#### electronjs 镜像和缓存
```ini
ELECTRON_MIRROR="https://npmmirror.com/mirrors/electron/"
ELECTRON_BUILDER_BINARIES_MIRROR=https://npmmirror.com/mirrors/electron-builder-binaries/
; ELECTRON_CUSTOM_DIR="{{ version }}"
```
<!--rehype:className=wrap-text -->
### 身份验证相关配置
```ini
//registry.npmjs.org/:_authToken=MYTOKEN
; 将适用于 @myorg 和 @another
//somewhere.com/:_authToken=MYTOKEN
; 将适用于 @myorg
//somewhere.com/myorg/:_authToken=MYTOKEN1
; 将适用于 @another
//somewhere.com/another/:_authToken=MYTOKEN2
```
另见
----
- [npm 仓库、网站和命令行界面的文档](https://docs.npmjs.com/) _(npmjs.com)_
- [npmmirror 中国镜像站](https://npmmirror.com/) _(npmmirror.com)_

638
docs/postgres.md Normal file
View File

@ -0,0 +1,638 @@
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
```
- &nbsp; `-a` &nbsp; 只转储数据,而不是模式(schema)
- &nbsp; `-s` &nbsp; 只转储模式,不转储数据
- &nbsp; `-c` &nbsp; 在重新创建之前删除数据库
- &nbsp; `-C` &nbsp; 还原前创建数据库
- &nbsp; `-t` &nbsp; 仅转储命名表
- &nbsp; `-F` &nbsp; 格式(`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
```
- &nbsp; `-U` &nbsp; 指定数据库用户
- &nbsp; `-c` &nbsp; 在重新创建之前删除数据库
- &nbsp; `-C` &nbsp; 还原前创建数据库
- &nbsp; `-e` &nbsp; 如果遇到错误退出
- &nbsp; `-F` &nbsp; 格式(`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)
Also see
--------
- [Posgres-cheatsheet](https://gist.github.com/apolloclark/ea5466d5929e63043dcf#posgres-cheatsheet) _(gist.github.com)_

1225
docs/python.md Normal file

File diff suppressed because it is too large Load Diff

View File

@ -29,7 +29,7 @@ HTML 存放在仓库根目录下的 `dist` 目录中,将 `dist/index.html` 静
### 介绍
在备忘清单采用 `HTML 注释语法`,标识网站布局和一些样式,目的是为了在 `GitHub` 中也是正常毫无瑕疵的预览 `Markdown`
在备忘清单采用 `HTML 注释语法`,标识网站布局和一些样式,目的是为了在 `GitHub` 中也是正常毫无瑕疵的预览 [`Markdown`](./markdown.md)
```markdown
### 卡片标题
@ -45,7 +45,7 @@ HTML 存放在仓库根目录下的 `dist` 目录中,将 `dist/index.html` 静
### 注释语法介绍
<!--rehype:wrap-class=row-span-3&style=color:black;background-color: #d7a100;-->
- 在某个 Markdown 语法下方或者后面,添加 HTML注释
- 在某个 [`Markdown`](./markdown.md) 语法下方或者后面,添加 HTML注释
-`<!--rehype:` 开始,`-->` 结束,包裹参数内容
- 内容采用 URL 参数的字符拼接方式
@ -78,7 +78,7 @@ HTML 存放在仓库根目录下的 `dist` 目录中,将 `dist/index.html` 静
---- | ----
`body-style` | 包裹所有卡片`外壳`的样式
`body-class` | 用于卡片栏布局,添加`类`
`wrap-style` | 卡片栏添加 CSS 样式
`wrap-style` | 卡片栏添加 [CSS](./css.md) 样式
`wrap-class` | 用于卡片占位,添加`类`
### 文字颜色
@ -109,7 +109,7 @@ function () {}
<!--rehype:className=wrap-text -->
```
如果代码块内容太长,使用强制换行类解决
如果代码块内容太长,使用强制换行类(`wrap-text`)解决
### 展示表格表头
@ -135,7 +135,7 @@ export const Student = (
);
```
上面 `{1,4-5}` 行代码高亮,下面是 `Markdown` 代码示例
上面 `{1,4-5}` 行代码高亮,下面是 [`Markdown`](./markdown.md) 代码示例
```markdown
```jsx {1,4-5}
@ -214,6 +214,22 @@ const school = <div>学校</div>;
`<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;-->
@ -222,7 +238,7 @@ const school = <div>学校</div>;
隐藏卡片标题,在 H3 标题下面添加注释样式
```
```markdown
```markdown {2}
### 隐藏卡片标题
<!--rehype:style=display:none;&wrap-style=padding-top: 0;-->
```
@ -232,12 +248,34 @@ const school = <div>学校</div>;
```
```html preview
这里是你的 HTML 代码
<b>这里是你的 HTML 代码</b>
\```
```
上面的 `markdown` 代码在 `meta` 位置添加 `preview` 标识HTML 代码将被执行预览
---
```html preview
<b>这里是你的 HTML 代码</b>
```
上面的 [`markdown`](./markdown.md) 代码在 `meta` 位置添加 `preview` 标识,[HTML](./html.md) 代码将被执行预览
### KaTeX 数学渲染
```KaTeX
c = \pm\sqrt{a^2 + b^2}
L = \frac{1}{2} \rho v^2 S C_L
```
上面示例 [`Markdown`](./markdown.md) 代码源码
```markdown {1}
```KaTeX
c = \pm\sqrt{a^2 + b^2}
L = \frac{1}{2} \rho v^2 S C_L
```
还可以单行展示 `KaTeX:c = \pm\sqrt{a^2 + b^2}`,需要标记 <code>\`KaTeX:数学公式\`</code> 将被显示成数学公式,这是基于 [KaTeX](https://katex.org/) 生成
布局
---
@ -256,7 +294,7 @@ H2 部分
上面实例 `H2 部分` 标题下面有三个`卡片`,默认 `3` 栏布局。
```markdown
```markdown {3}
H2 部分
---
<!--rehype:body-class=cols-2-->
@ -279,7 +317,7 @@ H2 部分
### 占位布局 style 写法
```markdown
```markdown {2}
### H3 部分
<!--rehype:wrap-style=grid-row: span 2/span 2;-->
```
@ -289,7 +327,7 @@ H2 部分
### 卡片栏布局 style 写法
```markdown
```markdown {2}
## H2 部分
<!--rehype:body-style=grid-template-columns: repeat(2,minmax(0,1fr));-->
```
@ -299,7 +337,7 @@ H2 部分
### H3 部分
```markdown
```markdown {2,4}
### 卡片 1 (H3 部分)
<!--rehype:wrap-class=row-span-2-->
### 卡片 2 (H3 部分)
@ -330,7 +368,7 @@ H2 部分
╰┈┈┈╯ ╰┈┈┈╯ ╰┈┈┈╯
```
上面布局效果 Markdown 源码:
上面布局效果 [Markdown](./markdown.md) 源码:
```markdown
### H3 Title 1
@ -355,7 +393,7 @@ H2 部分
╰┈┈┈╯ ╰┈┈┈╯ ╰┈┈┈╯
```
上面布局效果 Markdown 源码:
上面布局效果 [Markdown](./markdown.md) 源码:
```markdown
### Title 1
@ -403,7 +441,7 @@ H2 部分
╰┈┈┈╯ ╰┈┈┈╯ ╰┈┈┈╯
```
上面布局效果 Markdown 源码:
上面布局效果 [Markdown](./markdown.md) 源码:
```markdown
### Title 1
@ -427,7 +465,7 @@ H2 部分
╰┈┈┈╯ ╰┈┈┈┈┈┈┈┈┈╯
```
上面布局效果 Markdown 源码:
上面布局效果 [Markdown](./markdown.md) 源码:
```markdown
### Title 1
@ -451,7 +489,7 @@ H2 部分
╰┈┈┈╯ ╰┈┈┈╯ ╰┈┈┈╯
```
上面布局效果 Markdown 源码:
上面布局效果 [Markdown](./markdown.md) 源码:
```markdown
### Title 1
@ -475,7 +513,7 @@ H2 部分
╰┈┈┈┈┈┈┈┈┈╯ ╰┈┈┈╯
```
上面布局效果 Markdown 源码:
上面布局效果 [Markdown](./markdown.md) 源码:
```markdown
### Title 1
@ -499,7 +537,7 @@ H2 部分
╰┈┈┈╯ ╰┈┈┈╯ ╰┈┈┈╯ ╰┈┈┈╯
```
上面布局效果 Markdown 源码:
上面布局效果 [Markdown](./markdown.md) 源码:
```markdown
H2 部分
@ -530,7 +568,7 @@ H2 部分
╰┈┈┈╯ ╰┈┈┈╯ ╰┈┈┈╯
```
上面布局效果 Markdown 源码:
上面布局效果 [Markdown](./markdown.md) 源码:
```markdown
### Title 1
@ -623,6 +661,17 @@ H2 部分
`<!--rehype:className=auto-wrap-->`
### 表格末尾列左对齐
<!--rehype:wrap-class=col-span-2-->
| Prefix | What |
| ---- | ---- |
`//` | Anywhere
`./` | Relative
<!--rehype:className=show-header left-align-->
默认表格末尾列`右对齐`,添加 `<!--rehype:className=left-align-->` 类让其`左对齐`
列表
---

View File

@ -855,7 +855,7 @@ console.log(array[1]);
### replace()
```javascript {.wrap}
```javascript
let text = 'Do you like aPPles?';
let regex = /apples/i
@ -1091,7 +1091,7 @@ MySQL中的正则表达式
### REGEXP
```sql {.wrap}
```sql
expr REGEXP pat
```
@ -1164,7 +1164,7 @@ mysql> SELECT regexp_like('a\nb\nc', '^b$', 'm');
### REGEXP_INSTR
``` {.wrap}
```
REGEXP_INSTR(expr, pat[, pos[, occurrence[, return_option[, match_type]]]])
```

807
docs/rust.md Normal file
View File

@ -0,0 +1,807 @@
Rust 备忘清单
====
Rust 快速参考备忘单,旨在为编写基本语法和方法提供帮助。
入门
---
### Hello_World.rs
```rust
fn main() {
println!("Hello, World!");
}
```
#### 编译运行
```shell
$ rustc Hello_World.rs
$ ./Hello_World
Hello, World!
```
### 原始类型
:-| :-
:-| :-
`bool` | 布尔值 (`true` _/_ `false`)
`char` | 字符
`f32`, `f64` | 32 位、64 位浮点数
`i64`, `i32`, `i16`, `i8` | 有符号 16- ... 整数
`u64`, `u32`, `u16`, `u8` | 无符号 16 位,... 整数
`isize` | 指针大小的有符号整数
`usize` | 指针大小的无符号整数
查看: [Rust 类型](#rust-类型)
### 格式化
<!--rehype:wrap-class=row-span-2-->
```rust
// 单个占位符
println!("{}", 1);
// 多个占位符
println!("{} {}", 1, 3);
// 位置参数
println!("{0}{1} {2}{0} 也是 {3} 编程语言", "Rust", "cool", "language", "safe");
// 命名参数
println!("{country} 是一个团结的国家", country = "China");
// 占位符特征 :b 表示二进制, :0x 表示十六进制, :o 表示八进制
println!("让我们打印 76 是二进制的 {:b} ,十六进制等价物是 {:0x} 八进制等价物是 {:o}", 76, 76, 76);
// 调试特征
println!("使用调试特征 {:?} 在此处打印我们想要的任何内容", (76, 'A', 90));
// 1.58 中的新格式字符串
let x = "world";
println!("Hello {x}!");
```
<!--rehype:className=wrap-text -->
### 打印风格
```rust
// 打印输出
print!("Hello World\n");
// 打印后追加新行
println!("追加新行");
// 打印为错误
eprint!("这是一个错误\n");
// 打印为新行错误
eprintln!("这是新行的错误");
```
### 变量
```rust
// 初始化和声明变量
let some_variable = "This_is_a_variable";
// 使变量可变
let mut mutable_variable = "Mutable";
// 分配多个变量
let (name, age) = ("ElementalX", 20);
// (全局)常量
const SCREAMING_SNAKE_CASE:i64 = 9;
```
### 注释
```rust
// 行注释
/*.............块注释 */
/// 外部文档注释
//! 内部文档评论
```
另见: [注释](https://doc.rust-lang.org/reference/comments.html) _(doc.rust-lang.org)_
### 函数
```rust
fn test(){
println!("这是一个函数!");
}
fn main(){
test();
}
```
查看: [Functions](#rust-函数)
### 声明宏
```rust
macro_rules! foo {
($l:tt) => { bar!($l); }
}
macro_rules! bar {
(3) => {}
}
foo!(3);
```
### 元变量
<!--rehype:wrap-class=row-span-2-->
:- | :-
:- | :-
`item` | 程序项
`block` | 块表达式
`stmt` | 语句<br/> _(注意此选择器不匹配句尾的分号)_
`pat` | 模式
`expr` | 表达式
`ty` | 类型
`ident` | 标识符或关键字
`path` | 类型表达式 形式的路径
`tt` | `token`<br/> _(单个 `token` 或宏匹配定界符 `()`、`[]` 或 `{}` 中的标记)_
`meta` | 属性,属性中的内容
`lifetime` | 生存期 `token`
`vis` | 可能为空的可见性限定符
`literal` | 匹配 `-?` 字面量表达式
### 结构体
```rust
struct Point { x: i32, y: i32 }
let p = Point { x: 10, y: 11 };
let px: i32 = p.x;
```
结构体是一个使用关键字 `struct` 定义的标称型(nominal)结构体类型
### 枚举
```rust
enum Foo {
Bar, // 0
Baz = 123, // 123
Quux, // 124
}
let baz_discriminant = Foo::Baz as u32;
assert_eq!(baz_discriminant, 123);
```
Rust 类型
--------
### 类型别名
```rust
type Point = (u8, u8);
let p: Point = (41, 68);
```
### 整数
```rust
let mut a: u32 = 8;
let b: u64 = 877;
let c: i64 = 8999;
let d = -90;
```
### 浮点数
```rust
let mut sixty_bit_float: f64 = 89.90;
let thirty_two_bit_float: f32 = 7.90;
let just_a_float = 69.69;
```
### 布尔值
```rust
let true_val: bool = true;
let false_val: bool = false;
let just_a_bool = true;
let is_true = 8 < 5; // => false
```
### 字符
```rust
let first_letter_of_alphabet = 'a';
let explicit_char: char = 'F';
let implicit_char = '8';
let emoji = "\u{1f600}"; // => 😀
```
### 字符串字面量
```rust
let community_name = "AXIAL";
let no_of_members: &str = "ten";
println!("社区的名称是 {community_name},它有 {no_of_members} 个成员");
```
<!--rehype:className=wrap-text -->
查看: [字符串](#rust-字符串)
### 数组
```rust
┌─────┬─────┬─────┬─────┬─────┬─────┐
| 92 | 97 | 98 | 99 | 98 | 94 |
└─────┴─────┴─────┴─────┴─────┴─────┘
0 1 2 3 4 5
```
----
```rust
let array: [i64; 6] = [92,97,98,99,98,94];
```
### 多维数组
<!--rehype:wrap-class=row-span-2-->
```rust
j0 j1 j2 j3 j4 j5
┌────┬────┬────┬────┬────┬────┐
i0 | 1 | 2 | 3 | 4 | 5 | 6 |
├────┼────┼────┼────┼────┼────┤
i1 | 6 | 5 | 4 | 3 | 2 | 1 |
└────┴────┴────┴────┴────┴────┘
```
----
```rust
let array: [[i64; 6] ;2] = [
[1,2,3,4,5,6],
[6,5,4,3,2,1]];
```
### 可变数组
```rust
let mut array: [i32 ; 3] = [2,6,10];
array[1] = 4;
array[2] = 6;
```
使用 `mut` 关键字使其可变
### 切片
```rust
let mut array: [ i64; 4] = [1,2,3,4];
// 下限包括在内,上限不包括在内
let mut slices: &[i64] = &array[0..3]
println!("切片的元素是:{slices:?}");
```
### 向量
```rust
let some_vector = vec![1,2,3,4,5];
```
使用 `vec!` 宏声明向量
### 元组
```rust
let tuple = (1, 'A' , "Cool", 78, true);
```
Rust 字符串
--------------
### 字符串字面量
```rust
let cs:&str = "备忘清单";
// => 为开发者分享备忘单
println!("为开发者分享 {cs}");
```
### 字符串对象
```rust
// 创建一个空字符串对象
let my_string = String::new;
// 转换为字符串对象
let S_string = a_string.to_string()
// 创建一个初始化的字符串对象
let lang = String::from("Rust");
println!("First language is {lang}");
```
### .capacity()
```rust
let rand = String::from("Random String");
rand.capacity() // => 13
```
以字节为单位计算字符串的容量
### .contains()
```rust
let name = String::from("ElementalX");
name.contains("Element") // => true
```
检查子字符串是否包含在原始字符串中
### 添加单个字符
```rust
let mut half_text = String::from("Hal");
half_text.push('f'); // => Half
```
### 添加整个字符串
```rust
let mut hi = String::from("Hey there...");
hi.push_str("How are you doing??");
// => Hey there...How are you doing??
println!("{hi}");
```
Rust 运算符
-----------
### 比较运算符
:-|:-
:-|:-
`e == f` | `e` 等于 `f`
`e != f` | `e` 不等于 `f`
`e < f` | `e` 小于 `f`
`e > f` | `e` 大于 `f`
`e <= f` | `e` 小于或等于 `f`
`e >= f` | `e` 大于或等于 `f`
---------
```rust
let (e, f) = (1, 100);
let greater = f > e; // => true
let less = f < e; // => false
let greater_equal = f >= e; // => true
let less_equal = e <= f; // => true
let equal_to = e == f; // => false
let not_equal_to = e != f; // => true
```
### 算术运算符
:-|:-
:-|:-
`a + b` | `a` 被添加到 `b`
`a - b` | 从 `a` 中减去`b`
`a / b` | `a` 除以 `b`
`a % b` | 通过与 `b` 相除得到 `a` 的余数
`a * b` | `a``b` 相乘
------
```rust
let (a, b) = (4, 5);
let sum: i32 = a + b; // => 9
let subtractions: i32 = a - b; // => -1
let multiplication: i32 = a * b; // => 20
let division: i32 = a / b; // => 0
let modulus: i32 = a % b; // => 4
```
### 位运算符
运算符 | 描述
:- | :-
`g & h` | 二进制与
`g | h` | 二进制或
`g ^ h` | 二进制异或
`g ~ h` | 二进制补码
`g << h` | 二进制左移
`g >> h` | 二进制右移
-----
```rust
let (g, h) = (0x1, 0x2);
let bitwise_and = g & h; // => 0
let bitwise_or = g | h; // => 3
let bitwise_xor = g ^ h; // => 3
let right_shift = g >> 2; // => 0
let left_shift = h << 4; // => 32
```
### 逻辑运算符
示例 | 意义
:- | :-
`c && d` | 两者都是真的_(AND)_
`c || d` | 要么是真的_(OR)_
`!c` | `c` 为假 _(NOT)_
------
```rust
let (c, d) = (true, false);
let and = c && d; // => false
let or = c || d; // => true
let not = !c; // => false
```
### 复合赋值运算符
```rust
let mut k = 9;
let mut l = k;
```
----
运算符 | 描述
:- | :-
`k += l` | 添加一个值并赋值,然后 `k=9`
`k -= l` | `Substrate` 一个值并赋值,然后 `k=18`
`k /= l` | 除以一个值并赋值,然后 `k=9`
`k *= l` | 乘一个值并赋值,然后 `k=81`
`k \|= l` | 按位或并赋值,则 `k=89`
Rust 流程控制
------------
### If表达式
```rust
let case1: i32 = 81;
let case2: i32 = 82;
if case1 < case2 {
println!("case1 大于 case2");
}
```
### If...Else 表达式
```rust
let case3 = 8;
let case4 = 9;
if case3 >= case4 {
println!("case3 优于 case4");
} else {
println!("case4 大于 case3");
}
```
### If...Else...if...Else 表达式
```rust
let foo = 12;
let bar = 13;
if foo == bar {
println!("foo 等于 bar");
} else if foo < bar {
println!("foo 小于 bar");
} else if foo != bar {
println!("foo 不等于 bar");
} else {
println!("Nothing");
}
```
### If...let 表达式
<!--rehype:wrap-class=row-span-3-->
```rust
let mut arr1:[i64 ; 3] = [1,2,3];
if let[1,2,_] = arr1{
println!("与数组一起使用");
}
let mut arr2:[&str; 2] = ["one", "two"];
if let["Apple", _] = arr2{
println!("也适用于 str 数组");
}
```
----
```rust
let tuple_1 = ("India", 7, 90, 90.432);
if let(_, 7, 9, 78.99) = tuple_1{
println!("也适用于元组");
}
let tuple_2 = ( 9, 7, 89, 12, "Okay");
if let(9, 7,89, 12, blank) = tuple_2 {
println!("一切{blank}伴侣?");
}
let tuple_3 = (89, 90, "Yes");
if let(9, 89, "Yes") = tuple_3{
println!("模式确实匹配");
}
else {
println!("模式不匹配");
}
```
### 匹配表达式
<!--rehype:wrap-class=row-span-3-->
```rust
let day_of_week = 2;
match day_of_week {
1 => {
println!("兄弟们今天是星期一");
},
2 => {
println!("兄弟们今天是星期二");
},
3 => {
println!("兄弟们今天是星期三");
},
4 => {
println!("兄弟们今天是星期四");
},
5 => {
println!("兄弟们今天是星期五");
},
6 => {
println!("兄弟们今天是星期六");
},
7 => {
println!("兄弟们今天是星期天");
},
_ => {
println!("默认!")
}
};
}
```
### 嵌套...If 表达式
```rust
let nested_conditions = 89;
if nested_conditions == 89 {
let just_a_value = 98;
if just_a_value >= 97 {
println!("大于 97");
}
}
```
### For 循环
```rust
for mut i in 0..15 {
i-=1;
println!("i 的值为:{i}");
}
```
### While 循环
```rust
let mut check = 0;
while check < 11{
println!("check 是:{check}");
check+=1;
println!("递增后:{check}");
if check == 10{
break; // 停止 while
}
}
```
### Loop 关键字
```rust
loop {
println!("你好,世界永远!");
}
```
无限循环表示
### Break 中断语句
```rust
let mut i = 1;
loop {
println!("i 是 {i}");
if i > 100 {
break;
}
i *= 2;
}
```
### Continue 继续声明
```rust
for (v, c) in (0..10+1).enumerate(){
println!("{c} 数字循环");
if v == 9{
println!("我们继续?");
continue;
}
println!{"v 的值为:{v}"};
}
```
Rust 函数
--------
### 基本函数
```rust
fn print_message(){
println!("Hello, Quick Reference!");
}
fn main(){
// 在 Rust 中调用函数
print_message();
}
```
### 按值传递
```rust
fn main()
{
let x:u32 = 10;
let y:u32 = 20;
// => 200
println!("计算: {}", cal_rect(x, y));
}
fn cal_rect(x:u32, y:u32) -> u32
{
x * y
}
```
### 通过引用传递
```rust
fn main(){
let mut by_ref = 3; // => 3
power_of_three(&mut by_ref);
println!("{by_ref}"); // => 9
}
fn power_of_three(by_ref: &mut i32){
// 取消引用很重要
*by_ref = *by_ref * *by_ref;
println!("{by_ref}"); // => 9
}
```
### 返回
```rust
fn main(){
let (mut radius, mut pi) = (3.0, 3.14);
let(area, _perimeter) = calculate (
&mut radius,
&mut pi
);
println!("圆的面积和周长为:{area} & {_perimeter}");
}
fn calculate(radius : &mut f64, pi: &mut f64) -> (f64, f64){
let perimeter = 2.0 * *pi * *radius;
let area = *pi * *radius * *radius;
return (area, perimeter);
}
```
<!--rehype:className=wrap-text -->
### 数组作为参数
```rust
fn main(){
let mut array: [i32 ; 5] = [1,2,3,4,6];
print_arrays(array);
println!("元素:{array:?}");
}
fn print_arrays(mut array:[i32; 5]) {
array[0] = 89;
array[1] = 90;
array[2] = 91;
array[3] = 92;
array[4] = 93;
println!("元素:{array:?}");
}
```
### 返回数组
```rust
fn main(){
let mut arr:[i32; 5] = [2,4,6,8,10];
multiply(arr);
println!("数组是:{:?}", multiply(arr));
}
fn multiply (mut arr: [i32 ; 5]) -> [i32 ; 5]{
arr[2] = 90;
for mut i in 0..5 {
arr[i] = arr[i] * arr[2];
}
return arr;
}
```
<!--rehype:className=wrap-text -->
### 泛型函数
```rust
use std::fmt::Debug;
fn foo<T>(x: &[T]) where T: Debug {
// 省略细节
}
foo(&[1, 2]);
```
杂项
-----
### 类型断言 type-casting
```rust
let a_int = 90; // int
// int 到 float
let mut type_cast = (a_int as f64);
```
------
```rust
let orginal: char = 'I';
// char 到 int => 73
let type_casted: i64 = orginal as i64;
```
要在 `Rust` 中执行类型转换,必须使用 `as` 关键字
### 借用
```rust
let mut foo = 4;
let mut borrowed_foo = &foo;
println!("{borrowed_foo}");
```
------
```rust
let mut bar = 3;
let mut mutable_borrowed_bar = &mut bar;
println!("{mutable_borrowed_bar}");
```
这里借用的值使用 `&` 运算符从值一中借用值
### 取消引用
```rust
let mut borrow = 10;
let deref = &mut borrow;
println!("{}", *deref);
```
可以使用 `*` 操作符在 rust 中取消引用
### 变量范围
```rust
{
// 范围仅限于此大括号
let a_number = 1;
}
println!("{a_number}");
```
这将产生错误,因为变量 `a_number` 的范围在大括号处结束
另见
--------
- [Cargo 备忘清单](./cargo.md) _(jaywcjlove.github.io)_
- [The Rust Document](https://doc.rust-lang.org/book/ch00-00-introduction.html) _(doc.rust-lang.org)_
- [The Rust Reference](https://doc.rust-lang.org/reference/introduction.html) _(doc.rust-lang.org)_
- [Rust Cheatsheet](https://phaiax.github.io/rust-cheatsheet/) _(phaiax.github.io)_
- [Rust 标准库文档中文版](https://jaywcjlove.github.io/rust-cn-document-for-docker/std/std/) _(jaywcjlove.github.io)_
- [Rust 程序设计语言 中文版](https://jaywcjlove.github.io/rust-cn-document-for-docker/book/) _(jaywcjlove.github.io)_
- [Rust By Example 中文版](https://jaywcjlove.github.io/rust-cn-document-for-docker/rust-by-example-cn/) _(jaywcjlove.github.io)_
- [Rust 参考手册中文版](https://jaywcjlove.github.io/rust-cn-document-for-docker/reference/) _(jaywcjlove.github.io)_
- [RustDoc 手册中文版](https://jaywcjlove.github.io/rust-cn-document-for-docker/rustdoc/) _(jaywcjlove.github.io)_
- [Rust Cookbook 中文版](https://jaywcjlove.github.io/rust-cn-document-for-docker/rust-cookbook/) _(jaywcjlove.github.io)_

View File

@ -71,26 +71,26 @@ Sed 命令
### 命令
<!--rehype:wrap-class=col-span-2-->
| Command | Example | Description |
|---------|----------------------------------------|-----------------------------|
| `p` | sed -n '1,4 p' input.txt | Print lines 1-4 |
| `p` | sed -n -e '1,4 p' -e '6,7 p' input.txt | Print lines 1-4 and 6-7 |
| `d` | sed '1,4 d' input.txt | Print lines except 1-4 |
| `w` | sed -n '1,4 w output.txt' input.txt | Write pattern space to file |
| `a` | sed '2 a new-line' input.txt | Append line after |
| `i` | sed '2 i new-line' input.txt | Insert line before |
命令 | 示例 | 描述
:- | :- |:-
`p` | sed -n '1,4 p' input.txt | 打印第 1-4 行
`p` | sed -n -e '1,4 p' -e '6,7 p' input.txt | 打印第 1-4 行和第 6-7
`d` | sed '1,4 d' input.txt | 打印除 1-4 之外的行
`w` | sed -n '1,4 w output.txt' input.txt | 将模式空间写入文件
`a` | sed '2 a new-line' input.txt | 在后面追加一行
`i` | sed '2 i new-line' input.txt | 在前面插入行
<!--rehype:className=show-header-->
### 空间命令
| Command | Description |
|---------|--------------------------------------------------------------|
| `n` | 打印模式空间,空模式空间,读取下一行 |
| `x` | 用保持空间交换模式空间 |
| `h` | 复制模式空间以保持空间 |
| `H` | 追加模式空间以保持空间 |
| `g` | 将保持空间复制到模式空间 |
| `G` | 将保持空间附加到模式空间 |
命令 | 描述
:- | :-
`n` | 打印模式空间,空模式空间,读取下一行
`x` | 用保持空间交换模式空间
`h` | 复制模式空间以保持空间
`H` | 追加模式空间以保持空间
`g` | 将保持空间复制到模式空间
`G` | 将保持空间附加到模式空间
### Flags

644
docs/vue.md Normal file
View File

@ -0,0 +1,644 @@
Vue 3 备忘清单
===
渐进式 JavaScript 框架 [Vue 3](https://cn.vuejs.org/) 备忘清单的快速参考列表,包含常用 API 和示例。
入门
---
### 介绍
Vue 是一套用于构建用户界面的渐进式框架
- [Vue 3.x 官方文档](https://cn.vuejs.org/) _(cn.vuejs.org)_
- [Vue Router 4.x 官方文档](https://router.vuejs.org/zh/) _(router.vuejs.org)_
- [Vue 2 备忘清单](./vue2.md)
<!--rehype:className=style-round-->
注意Vue 3.x 版本对应 Vue Router 4.x 路由版本
### 创建应用
<!--rehype:wrap-class=row-span-3-->
已安装 `16.0` 或更高版本的 Node.js
```bash
$ npm init vue@latest
```
指令将会安装并执行 [create-vue](https://www.npmjs.com/package/create-vue),它是 Vue 官方的项目脚手架工具
```bash
✔ Project name: … <your-project-name>
✔ Add TypeScript? … No/Yes
✔ Add JSX Support? … No/Yes
✔ Add Vue Router for Single Page Application development? … No/Yes
✔ Add Pinia for state management? … No/Yes
✔ Add Vitest for Unit testing? … No/Yes
✔ Add Cypress for both Unit and End-to-End testing? … No/Yes
✔ Add ESLint for code quality? … No/Yes
✔ Add Prettier for code formatting? … No/Yes
Scaffolding project in ./<your-project-name>...
Done.
```
<!--rehype:className=wrap-text -->
安装依赖并启动开发服务器
```bash
$ cd <your-project-name>
$ npm install
$ npm run dev
```
当你准备将应用发布到生产环境时,请运行:
```bash
$ npm run build
```
此命令会在 `./dist` 文件夹中为你的应用创建一个生产环境的构建版本
### 应用实例
<!--rehype:wrap-class=row-span-2-->
```js
import { createApp } from 'vue'
const app = createApp({
data() {
return { count: 0 }
}
})
app.mount('#app')
```
挂载应用
```html
<div id="app">
<button @click="count++">
{{ count }}
</button>
</div>
```
### 通过 CDN 使用 Vue
```html
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<div id="app">{{ message }}</div>
<script>
const { createApp } = Vue
createApp({
data() {
return {
message: 'Hello Vue!'
}
}
}).mount('#app')
</script>
```
<!--rehype:className=wrap-text -->
### 使用 ES 模块构建版本
```html
<div id="app">{{ message }}</div>
<script type="module">
import { createApp } from 'https://unpkg.com/vue@3/dist/vue.esm-browser.js'
createApp({
data() {
return {
message: 'Hello Vue!'
}
}
}).mount('#app')
</script>
```
<!--rehype:className=wrap-text -->
模板语法
---
### 文本插值
```html
<span>Message: {{ msg }}</span>
```
使用的是 `Mustache` 语法 (即双大括号),每次 `msg` 属性更改时它也会同步更新
### 原始 HTML
<!--rehype:wrap-class=col-span-2-->
```html
<p>Using text interpolation: {{ rawHtml }}</p>
<p>Using v-html directive: <span v-html="rawHtml"></span></p>
```
双大括号`{{}}`会将数据解释为纯文本,使用 `v-html` 指令,将插入 HTML
### Attribute 绑定
```html
<div v-bind:id="dynamicId"></div>
```
简写
```html
<div :id="dynamicId"></div>
```
### 布尔型 Attribute
```html
<button :disabled="isButtonDisabled">
Button
</button>
```
<!--rehype:className=wrap-text -->
### 动态绑定多个值
<!--rehype:wrap-class=row-span-2-->
```js
data() {
return {
objectOfAttrs: {
id: 'container',
class: 'wrapper'
}
}
}
```
通过不带参数的 `v-bind`,你可以将它们绑定到单个元素上
```html
<div v-bind="objectOfAttrs"></div>
```
### 使用 JavaScript 表达式
```html
{{ number + 1 }}
{{ ok ? 'YES' : 'NO' }}
{{ message.split('').reverse().join('') }}
<div :id="`list-${id}`"></div>
```
### 仅支持表达式(例子都是无效)
```html
<!-- 这是一个语句,而非表达式 -->
{{ var a = 1 }}
<!-- 条件控制也不支持,请使用三元表达式 -->
{{ if (ok) { return message } }}
```
### 调用函数
```html
<span :title="toTitleDate(date)">
{{ formatDate(date) }}
</span>
```
### 指令 Directives
```html
<p v-if="seen">Now you see me</p>
```
### 参数 Arguments
```html
<a v-bind:href="url"> ... </a>
<!-- 简写 -->
<a :href="url"> ... </a>
```
### 绑定事件
```html
<a v-on:click="doSomething"> ... </a>
<!-- 简写 -->
<a @click="doSomething"> ... </a>
```
### 动态参数
```html
<a v-bind:[attributeName]="url"> ... </a>
<!-- 简写 -->
<a :[attributeName]="url"> ... </a>
```
这里的 `attributeName` 会作为一个 JS 表达式被动态执行
### 动态的事件名称
```html
<a v-on:[eventName]="doSomething"> ... </a>
<!-- 简写 -->
<a @[eventName]="doSomething">
```
### 修饰符 Modifiers
```html
<form @submit.prevent="onSubmit">
...
</form>
```
`.prevent` 修饰符会告知 `v-on` 指令对触发的事件调用 `event.preventDefault()`
### 指令语法
```bash
v-on:submit.prevent="onSubmit"
──┬─ ─┬──── ─┬───── ─┬──────
┆ ┆ ┆ ╰─ Value 解释为JS表达式
┆ ┆ ╰─ Modifiers 由前导点表示
┆ ╰─ Argument 跟随冒号或速记符号
╰─ Name 以 v- 开头使用速记时可以省略
```
响应式基础
---
### 声明状态
```html
<div>{{ count }}</div>
```
---
```js {2,4}
export default {
data() {
return {
count: 0
}
},
}
```
### 声明方法
```html
<button @click="increment">
{{ count }}
</button>
```
---
```js {8-10}
export default {
data() {
return {
count: 0
}
},
methods: {
increment() {
this.count++
}
}
}
```
### 有状态方法
```js
import { debounce } from 'lodash-es'
export default {
created() {
// 每个实例都有了自己的预置防抖的处理函数
this.debouncedClick = debounce(this.click, 500)
},
unmounted() {
// 最好是在组件卸载时
// 清除掉防抖计时器
this.debouncedClick.cancel()
},
methods: {
click() {
// ... 对点击的响应 ...
}
}
}
```
<!--rehype:className=wrap-text -->
API 参考
---
### 全局 API - 应用实例
<!--rehype:wrap-class=row-span-3-->
:- | :-
:- | :-
`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)
### 全局 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)
`defineCustomElement()` | [#](https://cn.vuejs.org/api/general.html#definecustomelement)
### 组合式 API - setup()
:- | :-
:- | :-
`基本使用` | [#](https://cn.vuejs.org/api/composition-api-setup.html#basic-usage)
`访问 Props` | [#](https://cn.vuejs.org/api/composition-api-setup.html#accessing-props)
`Setup 上下文` | [#](https://cn.vuejs.org/api/composition-api-setup.html#setup-context)
`与渲染函数一起使用` | [#](https://cn.vuejs.org/api/composition-api-setup.html#usage-with-render-functions)
### 组合式 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)
### 组合式 API - 生命周期钩子
<!--rehype:wrap-class=row-span-3-->
:- | :-
:- | :-
`onMounted()` | 组件挂载完成后执行 [#](https://cn.vuejs.org/api/composition-api-lifecycle.html#onmounted)
`onUpdated()` | 状态变更而更新其 DOM 树之后调用 [#](https://cn.vuejs.org/api/composition-api-lifecycle.html#onupdated)
`onUnmounted()` | 组件实例被卸载之后调用 [#](https://cn.vuejs.org/api/composition-api-lifecycle.html#onunmounted)
`onBeforeMount()` | 组件被挂载之前被调用 [#](https://cn.vuejs.org/api/composition-api-lifecycle.html#onbeforemount)
`onBeforeUpdate()` | 状态变更而更新其 DOM 树之前调用 [#](https://cn.vuejs.org/api/composition-api-lifecycle.html#onbeforeupdate)
`onBeforeUnmount()` | 组件实例被卸载之前调用 [#](https://cn.vuejs.org/api/composition-api-lifecycle.html#onbeforeunmount)
`onErrorCaptured()` | 捕获了后代组件传递的错误时调用 [#](https://cn.vuejs.org/api/composition-api-lifecycle.html#onerrorcaptured)
`onRenderTracked()` | 组件渲染过程中追踪到响应式依赖时调用 [#](https://cn.vuejs.org/api/composition-api-lifecycle.html#onrendertracked)
`onRenderTriggered()` | 响应式依赖的变更触发了组件渲染时调用 [#](https://cn.vuejs.org/api/composition-api-lifecycle.html#onrendertriggered)
`onActivated()` | 若组件实例是 \<KeepAlive> 缓存树的一部分,当组件被插入到 DOM 中时调用 [#](https://cn.vuejs.org/api/composition-api-lifecycle.html#onactivated)
`onDeactivated()` | 若组件实例是 \<KeepAlive> 缓存树的一部分,当组件从 DOM 中被移除时调用 [#](https://cn.vuejs.org/api/composition-api-lifecycle.html#ondeactivated)
`onServerPrefetch()` | 组件实例在服务器上被渲染之前调用 [#](https://cn.vuejs.org/api/composition-api-lifecycle.html#onserverprefetch)
<!--rehype:className=style-list-->
### 组合式 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)
### 组合式 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)
### 选项式 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)
### 选项式 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)
### 选项式 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)
### 选项式 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)
### 选项式 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)
### 选项式 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)
### 内置内容 - 指令
<!--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-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)
### 内置内容 - 组件
:- | :-
:- | :-
`<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)
### 内置内容 - 特殊 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)
### 内置内容 - 特殊元素
:- | :-
:- | :-
`<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-->
:- | :-
:- | :-
`总览` | [#](https://cn.vuejs.org/api/sfc-spec.html#overview)
`相应语言块` | [#](https://cn.vuejs.org/api/sfc-spec.html#language-blocks)
`自动名称推导` | [#](https://cn.vuejs.org/api/sfc-spec.html#automatic-name-inference)
`预处理器` | [#](https://cn.vuejs.org/api/sfc-spec.html#pre-processors)
`Src 导入` | [#](https://cn.vuejs.org/api/sfc-spec.html#src-imports)
`注释` | [#](https://cn.vuejs.org/api/sfc-spec.html#comments)
### 单文件组件 - \<script setup>
<!--rehype:wrap-class=row-span-2-->
:- | :-
:- | :-
`基本语法` | [#](https://cn.vuejs.org/api/sfc-script-setup.html#basic-syntax)
`响应式` | [#](https://cn.vuejs.org/api/sfc-script-setup.html#reactivity)
`使用组件` | [#](https://cn.vuejs.org/api/sfc-script-setup.html#using-components)
`使用自定义指令` | [#](https://cn.vuejs.org/api/sfc-script-setup.html#using-custom-directives)
`defineProps() 和 defineEmits()` | [#](https://cn.vuejs.org/api/sfc-script-setup.html#defineprops-defineemits)
`defineExpose` | [#](https://cn.vuejs.org/api/sfc-script-setup.html#defineexpose)
`useSlots() 和 useAttrs()` | [#](https://cn.vuejs.org/api/sfc-script-setup.html#useslots-useattrs)
`与普通的 &lt;script&gt; 一起使用` | [#](https://cn.vuejs.org/api/sfc-script-setup.html#usage-alongside-normal-script)
`顶层 await` | [#](https://cn.vuejs.org/api/sfc-script-setup.html#top-level-await)
`针对 TypeScript 的功能` | [#](https://cn.vuejs.org/api/sfc-script-setup.html#typescript-only-features)
`限制` | [#](https://cn.vuejs.org/api/sfc-script-setup.html#restrictions)
### 单文件组件 - CSS 功能
:- | :-
:- | :-
`组件作用域 CSS` | [#](https://cn.vuejs.org/api/sfc-css-features.html#scoped-css)
`CSS Modules` | [#](https://cn.vuejs.org/api/sfc-css-features.html#css-modules)
`CSS 中的 v-bind()` | [#](https://cn.vuejs.org/api/sfc-css-features.html#v-bind-in-css)
### 进阶 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)
### 进阶 API - 服务端渲染
:- | :-
:- | :-
`renderToString()` | [#](https://cn.vuejs.org/api/ssr.html#rendertostring)
`renderToNodeStream()` | [#](https://cn.vuejs.org/api/ssr.html#rendertonodestream)
`pipeToNodeWritable()` | [#](https://cn.vuejs.org/api/ssr.html#pipetonodewritable)
`renderToWebStream()` | [#](https://cn.vuejs.org/api/ssr.html#rendertowebstream)
`pipeToWebWritable()` | [#](https://cn.vuejs.org/api/ssr.html#pipetowebwritable)
`renderToSimpleStream()` | [#](https://cn.vuejs.org/api/ssr.html#rendertosimplestream)
`useSSRContext()` | [#](https://cn.vuejs.org/api/ssr.html#usessrcontext)
### 进阶 API - TypeScript 工具类型
:- | :-
:- | :-
`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)
### 进阶 API - 自定义渲染
:- | :-
:- | :-
`createRenderer()` | [#](https://cn.vuejs.org/api/custom-renderer.html#create-renderer)
另见
---
- [Vue 3.x 官方文档](https://cn.vuejs.org/)
- [Vue Router 4.x 官方文档](https://router.vuejs.org/zh/)

View File

@ -1,7 +1,7 @@
Vue2 备忘清单
Vue 2 备忘清单
===
渐进式 JavaScript 框架 Vue 2 备忘清单的快速参考列表,包含常用 API 和示例。
渐进式 JavaScript 框架 [Vue 2](https://v2.cn.vuejs.org/) 备忘清单的快速参考列表,包含常用 API 和示例。
入门
---
@ -10,10 +10,13 @@ Vue2 备忘清单
Vue 是一套用于构建用户界面的渐进式框架
- [Vue 2.x 官方文档](https://v2.cn.vuejs.org/)
- [Vue Router 3.x 官方文档](https://v3.router.vuejs.org/)
- [Vue 2.x 官方文档](https://v2.cn.vuejs.org/) _(v2.cn.vuejs.org)_
- [Vue Router 3.x 官方文档](https://v3.router.vuejs.org/) _(v3.router.vuejs.org)_
- [Vue 3 备忘清单](./vue.md)
<!--rehype:className=style-round-->
注意Vue 2.x 版本对应 Vue Router 3.x 路由版本
#### 快速创建 **Vue** 项目 ([Vue CLI](https://cli.vuejs.org/zh/guide/creating-a-project.html))
```bash

107
docs/xcode.md Normal file
View File

@ -0,0 +1,107 @@
Xcode 备忘清单
====
这个 Xcode 快速参考备忘单显示了它的键盘快捷键和命令。
Xcode
---
### 搜索
快捷键 | 描述
:---- | ----
`Cmd + F` | 在文件中查找
`Cmd + Option + F` | 在文件中查找和替换
`Cmd + Shift + F` | 在项目中查找
`Cmd + Option + Shift + F` | 在项目中查找和替换
<!--rehype:className=shortcuts-->
### 选项卡
快捷键 | 描述
:---- | ----
`Cmd + T` | 新选项卡
`Cmd + }` | 上一个选项卡
`Cmd + {` | 下一个选项卡
<!--rehype:className=shortcuts-->
### 导航
<!--rehype:wrap-class=row-span-2-->
快捷键 | 描述
:---- | ----
`Cmd + Shift + O` | 快速打开
`Cmd + J` | 专注于编辑
`Cmd + Ctrl + UP` | 下一个对手
`Cmd + Ctrl + DOWN` | 上一个对手
`Cmd + Ctrl + RIGHT` | 下一个最近的文件
`Cmd + Ctrl + LEFT` | 上一个 最近的文件
`Cmd + click` | 符号的定义
`Cmd + L` | 去线
`Cmd + Option + LEFT` | 折叠部分
`Cmd + Option + RIGHT` | 展开部分
<!--rehype:className=shortcuts-->
### 调试
快捷键 | 描述
:---- | ----
`Cmd + Shift + Y` | 切换调试区域
`Cmd + '` | 下一期
`Cmd + "` | 上一期
`Cmd + \` | 添加/删除断点
`Cmd + Y` | 活动/非活动断点
`Cmd + K` | 清除控制台
<!--rehype:className=shortcuts-->
### 导航器(左侧面板)
快捷键 | 描述
:---- | ----
`Cmd + 0` | 显示隐藏
`Cmd + 1-8` | 切换标签
`Option + click` | 打开助理编辑器
`Shift + Option + click` | 决定在哪里打开
`double click` | 在新窗口中打开
<!--rehype:className=shortcuts-->
### 编辑
快捷键 | 描述
:---- | ----
`Cmd + Option + ENTER` | 显示助理编辑器
`Cmd + ENTER` | 隐藏助理编辑器
`Ctrl + SPACE or ESC` | 切换完成
`Cmd + ]` | 缩进部分
`Cmd + [` | 突出部分
`Ctrl + i` | 修复缩进
`Cmd + /` | 评论/取消评论
`Cmd + Option + [` | 向上移动队列
`Cmd + Option + ]` | 下移线
<!--rehype:className=shortcuts-->
### 实用程序(右面板)
快捷键 | 描述
:---- | ----
`Cmd + Option + 0` | 显示隐藏
`Cmd + Option + 1-9` | 转到选项卡
<!--rehype:className=shortcuts-->
### 调试和运行
快捷键 | 描述
:---- | ----
`Cmd + B` | 建造
`Cmd + R` | 运行
`Cmd + .` | 停止
`Cmd + Shift + B` | 分析
`Cmd + U` | 测试
`Cmd + Shift + K` | 清理
<!--rehype:className=shortcuts-->

View File

@ -57,7 +57,7 @@ other_thing: *VAR_NAME
#### ↓ 等效的 JSON
```json {.wrap}
```json
{
"some_thing": "foobar",
"other_thing": "foobar"
@ -84,7 +84,7 @@ description: |
#### ↓ 等效的 JSON
```json {.wrap}
```json
{"description": "hello\nworld\n"}
```
@ -102,7 +102,7 @@ child:
#### ↓ 等效的 JSON
```json {.wrap}
```json
{
"parent": {
"a": 2,
@ -129,7 +129,7 @@ other_values:
#### ↓ 等效的 JSON
```json {.wrap}
```json
{
"values": [
"Will be",
@ -154,7 +154,7 @@ description: >
#### ↓ 等效的 JSON
```json {.wrap}
```json
{"description": "hello world\n"}
```

193
docs/yarn.md Normal file
View File

@ -0,0 +1,193 @@
Yarn 备忘清单
===
这是一份 [`Yarn`](https://yarnpkg.com/) 软件包管理器备忘单,其中列出了 `Yarn` 常用命令使用清单
入门
---
### Yarn 与 npm 命令比较
<!--rehype:wrap-class=col-span-2-->
npm(v5) | yarn | 说明
:- | :- | :-
`npm install` | `yarn add`, `yarn`| 安装依赖
`npm init` | `yarn init` | 创建 `package.json` 文件
`npm install gulp --save` | `yarn add gulp` | 安装 `gulp`
`npm install gulp --save-dev --save-exact` | `yarn add gulp --dev --exact`
`npm install -g gulp` | `yarn global add gulp`
`npm update` | `yarn upgrade`
`npm cache clean` | `yarn cache clean` | 清理缓存目录
`./node_modules/.bin/gulp` | `yarn run gulp`
<!--rehype:className=show-header left-align-->
npm _([备忘清单](./npm.md))_ 和 Yarn 有很多相似之处
### yarn install
```shell
--no-lockfile # 不要读取或生成 yarn.lock 锁定文件
--pure-lockfile
--frozen-lockfile
--silent
--offline
--update-checksums
--check-files
--flat
--force
--ignore-scripts
--modules-folder <path>
--production[=true|false]
```
这些选项可用于 `yarn install`
### yarn add
<!--rehype:wrap-class=row-span-2-->
在 [devDependencies](./package.json.md#devdependencies) 中安装一个或多个包
```shell
--dev, -D
```
在 [peerDependencies](./package.json.md#peerdependencies) 中安装一个或多个包
```shell
--peer, -P
```
在 [optionalDependencies](./package.json.md#optionaldependencies) 中安装一个或多个包
```shell
--optional, -O
```
更改包版本
```shell
--exact, -E # 将包安装为精确版本
--tilde, -T # 安装有相同次要版本的包的最新版本
```
这些选项可用于 `yarn add`.
### Workspaces
<!--rehype:wrap-class=row-span-2-->
`package.json` 中 [workspaces](./package.json.md#workspaces) 配置:
```json
"workspaces": [
"packages/*"
]
```
----
```bash
jest/
├─ package.json
└─ packages/
├─ jest-matcher-utils/
│ └─ package.json
└─ jest-diff/
└─ package.json
```
(1.0 新增)允许 monoreso 相互共享包。另见:[介绍工作空间](https://yarnpkg.com/blog/2017/08/02/introducing-workspaces/)
### 选择性版本解析
`package.json` 中 [`resolutions`](./package.json.md#resolutions) 配置:
```json
"resolutions": {
"**/sass-brunch/node-sass": "4.5.2"
}
```
另见:[选择性版本解析](https://github.com/yarnpkg/yarn/pull/4105)。(1.0 新增)允许您指定子依赖项的版本
### Create
```bash
yarn create react-app hello
```
安装 `create react app` 并运行它 See: [yarn create](https://github.com/yarnpkg/rfcs/blob/master/implemented/0000-yarn-create.md)
示例
---
### 安装包
<!--rehype:wrap-class=row-span-2-->
```bash
# 将包添加到“dependencies”
$ yarn add <package>
# 将包添加到“devDependencies”
$ yarn add -D <package>
# 将软件包添加为确切版本
$ yarn add -E <package>
# 在您的操作系统上全局安装软件包
$ yarn global add <package>
```
### 移除包
```bash
$ yarn remove <package>
```
从所有类型的依赖项中删除包
### 查看包
<!--rehype:wrap-class=row-span-2-->
```bash
# 列出已安装的软件包
$ yarn list
# 列出顶级安装包
$ yarn list --depth=0
# 列出已安装的顶级全局包
$ yarn global list --depth=0
# 列出带有过滤字符串和深度级别的包
$ yarn list --pattern "gulp|grunt" --depth=1
```
### 清除
```bash
# 从包依赖项中清理并删除不必要的文件
$ yarn autoclean
# 检查过时的包依赖项
$ yarn outdated
```
### 信息
```bash
$ yarn why <query>
$ yarn why jest
```
显示有关安装软件包的原因的信息
### 清理缓存
运行此命令将清除全局缓存。 下次运行 `yarn``yarn install` 时,它将再次填充
```bash
$ yarn cache clean
```
此外,您可以指定一个或多个要清理的包
另见
---
- [npm 备忘清单](./npm.md)
- [Yarn 官方文档网站](https://yarnpkg.com/)
- [Yarn 2 中文文档网站](https://www.yarnpkg.cn/)
- [Yarn 1 中文文档网站](https://yarn.bootcss.com/) _(bootcss.com)_

423
docs/yum.md Normal file
View File

@ -0,0 +1,423 @@
YUM 备忘清单
===
这个 YUM 快速参考备忘单显示了它的常用命令使用清单。
YUM 清单查询
---
### 介绍
yum`Y`ellow dog `U`pdater, `M`odified是一个在 `Fedora``RedHat` 以及 SUSE 中的 `Shell` 前端软件包管理器
```bash
$ yum [options] [command] [package ...]
```
----
- [YUM 官方网站](http://yum.baseurl.org/) _(yum.baseurl.org)_
- [Fedora 中的 Yum 文档](https://docs.fedoraproject.org/en-US/Fedora/15/html/Deployment_Guide/ch-yum.html) _(fedoraproject.org)_
- [CentOS 中的 Yum 文档](http://wiki.centos.org/PackageManagement/Yum/) _(wiki.centos.org)_
- [Scientific Linux 中的 Yum 文档](https://www.scientificlinux.org/documentation/faq/yum.apt.repo) _(scientificlinux.org)_
### YUM 查询
子命令描述和任务
#### help
显示 yum 命令和选项
```bash
yum help
```
显示 yum 子命令和选项
### 单独的包
<!--rehype:wrap-class=row-span-3-->
#### list
列出存储库中的包名称
```bash
# 列出存储库中的包名称
yum list available
# 列出所有可用的包
yum list installed
# 列出所有已安装的包
yum list all
# 列出已安装和可用的软件包
yum list kernel
```
#### info
列出已安装和可用的内核包
```bash
# 列出有关 `vsftpd` 软件包的信息
$ yum info vsftpd
```
#### deplist
显示包的依赖项
```bash
$ yum deplist nfs-utils
```
列出依赖项和提供它们的包
#### provides
```bash
# 查找提供查询文件的包
$ yum provides “*bin/top”
# 显示包含 README.top 文件的包
$ yum provides “*/README.top”
```
#### search
```bash
# 查找名称或描述中带有 samba 的软件包
$ yum search samba
```
#### updateinfo
```bash
# 获取有关可用软件包更新的信息
$ yum updateinfo security
```
获取有关可用 security 更新的信息
### 包组
#### grouplist
列出已安装和可用软件包组的名称
#### groupinfo
```bash
# 查看 Web 服务器组中的包
$ yum groupinfo "Web Server"
```
#### check-update
查询存储库以获取可用的软件包更新
### 管理 YUM 存储库
<!--rehype:wrap-class=row-span-2-->
#### repolist
显示启用的软件存储库
#### repoinfo
显示有关启用的 `yum` 存储库的信息 *
```bash
$ yum repoinfo rhel-7-server-rpms
```
请参阅有关 rhel-7-server-rpms 存储库的信息
#### repo-pkgs
使用特定存储库中的包 *
```bash
# 列出来自 my-rpms 存储库的软件包
$ yum repo-pkgs my-rpms list
# 从 my-rpms repo 安装所有软件包
$ yum repo-pkgs my-rpms install
# 从 my-rpms 存储库中删除所有软件包
$ yum repo-pkgs my-rpms remove
```
#### makecache
下载 `yum` 存储库数据到缓存
### 故障排除和维护 YUM
<!--rehype:wrap-class=row-span-2-->
#### check
检查本地 RPM 数据库是否有问题(运行了很长时间)
#### history
```bash
# 列出所有 yum 安装、更新和清理操作
$ yum history list
# 显示 yum info 3 的详细信息
$ yum history info 3
# 撤消事务 3 中的 yum 操作
$ yum history undo 3
# 重做事务 3 中撤消的 yum 操作
$ yum history redo 3
```
#### clean
```bash
# 删除缓存中保存的包
$ yum clean packages
# 从缓存中清除所有包和元数据
$ yum clean all
```
清除缓存的包数据
#### fssnapshot
列出 LVM 快照(帮助在包更新后回滚)
#### fs
```bash
# 列出启用的文件系统过滤器
$ yum fs filters
# 过滤所有正在安装的文档(小心!)
$ yum fs documentation
```
对文件系统采取行动(防止在最小系统上安装 doc 或语言文件)非常有用!
### 使用 YUM 管理语言包
#### langavailable
列出已安装的语言 *
#### langinfo
```bash
# 列出与西班牙语相关的软件包
$ yum langinfo es
```
#### langinstall
```bash
# 安装与西班牙语相关的软件包
$ yum langinstall es
```
#### langlist
列出已安装的语言 *
#### langremove
```bash
# 删除与西班牙语相关的软件包
$ yum langremove es
```
### 使用 YUM 安装、删除和升级软件包
<!--rehype:wrap-class=row-span-2-->
#### install
```bash
# 安装 vsftpd 包
$ yum install vsftpd
```
#### update
```bash
# 使用可用更新更新所有软件包
$ yum update
# 更新 httpd 包(如果可用)
$ yum update httpd
# 应用与安全相关的包更新
$ yum update --security
```
#### update-to
将一个或所有软件包更新到特定版本
#### upgrade
```bash
$ yum -y upgrade
```
更新包考虑过时,只升级所有包,不升级软件和系统内核
#### localinstall
```bash
# 从本地文件、http 或 ftp 安装包
$ yum localinstall abc-1-1.i686.rpm
# 从本地目录安装 abc 包
$ yum localinstall http://myrepo/abc-1-1.i686.rpm
```
<!--rehype:className=wrap-text-->
从 FTP 站点安装 abc
#### downgrade
将软件包降级到早期版本
```bash
$ yum downgrade abc
```
将 abc 包降级到早期版本
#### reinstall
```bash
# 重新安装 util-linux以替换任何已删除的文件
$ yum reinstall util-linux
```
#### swap
```bash
# 删除 ftp 包并安装 lftp 包
$ yum swap ftp lftp
```
#### erase/remove
```bash
# 删除 vsftpd 包和依赖
$ yum remove vsftpd
```
#### autoremove
```bash
# 删除 httpd 和其他不需要的包
$ yum autoremove httpd
```
#### groupinstall
```bash
# 安装 Web 服务器包
$ yum groupinstall "Web server"
```
### 更多 YUM 相关命令(安装 yum-utils 软件包)
#### find-repos-of-install
查找包来自哪个存储库
#### needs-restarting
查找已更新且需要重启的进程
#### repoclosure
从存储库中获取未满足的依赖项列表
#### repoquery
查询远程仓库和本地 `RPM` 数据库
```bash
# 显示依赖包
$ repoquery --requires --resolve bash
```
#### reposync
`yum` 存储库同步到本地目录
```bash
# 从 repo 获取包
$ reposync -r rhel-atomic-host-beta-rpms
```
#### repotrack
下载一个包及其所有依赖项
#### show-installed
列出已安装的 RPM 包和统计信息
#### verifytree
检查本地 yum 存储库的一致性
#### yum-complete-transaction
尝试完成未完成的 yum 交易
#### yumdb
检查或更改 yum 数据库
#### yumdownloader
```bash
# 使用本地源离线安装 net-tools 工具包
$ yumdownloader net-tools.x86_64
# 使用 destdir 参数设置下载的目标目录
$ yumdownloader net-tools.x86_64 --destdir=/usr/local/bin/
# 使用 resolve 参数解决依赖关系并下载所需的安装包
$ yumdownloader net-tools.x86_64 --resolve --destdir=/usr/local/bin/
```
<!--rehype:className=wrap-text-->
从 repo 下载一个包到当前目录
### 不同 YUM 命令的常用选项
```bash
yum --disableplugin=langpacks info vsftpd
# 显示与正在运行的进程相关的包
yum --enableplugin=ps ps
yum install docker \
--enablerepo=rhel-7-server-extras-rpm
yum list available --disablerepo=epel
# 下载 vsftpd 包到缓存
yum install --downloadonly vsftpd
```
---
:- | -
:- | -
`-y` | 如果出现提示,假设是
`--assumeno` | 如果提示,则假设否
`-q` | 不产生任何输出
`-v` | 产生额外的调试输出
`--noplugins` | 运行命令而不加载任何 yum 插件
`--disableplugin=` | 禁用单个命令的特定插件
`--enableplugin=` | 启用已安装但当前已禁用的插件
`--enablerepo=` | 为单个命令启用当前禁用的 repo通配符可以
`--disablerepo=` | 为单个命令禁用当前启用的 repo通配符可以
`--downloadonly` | 下载到 `/var/cache/yum/arch/prod/repo/packages/`,但不要安装
`--filter-???=` | 代替???与vendors, rpm-groups, arches 和其他人一起过滤输出
`--changelog` | 显示包的变更日志信息
<!--rehype:className=style-list-->
另见
---
- [YUM 官方网站](http://yum.baseurl.org/) _(yum.baseurl.org)_
- [YUM 备忘清单(适用于红帽 RedHad 企业 Linux)](https://access.redhat.com/sites/default/files/attachments/rh_yum_cheatsheet_1214_jcs_print-1.pdf) _(access.redhat.com)_
- [用 yum 管理软件包](http://prefetch.net/articles/yum.html) _(prefetch.net)_
- [Fedora 中的 Yum 文档](https://docs.fedoraproject.org/en-US/Fedora/15/html/Deployment_Guide/ch-yum.html) _(fedoraproject.org)_
- [CentOS 中的 Yum 文档](http://wiki.centos.org/PackageManagement/Yum/) _(wiki.centos.org)_
- [Scientific Linux 中的 Yum 文档](https://www.scientificlinux.org/documentation/faq/yum.apt.repo) _(scientificlinux.org)_

View File

@ -1,14 +1,16 @@
{
"name": "@wcj/reference",
"version": "1.11.0",
"version": "1.18.0",
"description": "为开发人员分享快速参考备忘单(主要是方便自己)。",
"author": "jaywcjlove",
"license": "MIT",
"homepage": "https://jaywcjlove.github.io/reference",
"private": false,
"scripts": {
"prepare": "husky install",
"build": "node scripts/build.mjs",
"start": "node scripts/watch.mjs"
"start": "node scripts/watch.mjs",
"prettier": "prettier --write '**/*.{mjs,css,json,prettierrc,lintstagedrc}'"
},
"repository": {
"type": "git",
@ -19,13 +21,19 @@
},
"keywords": [],
"devDependencies": {
"@wcj/markdown-to-html": "^2.1.1",
"@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",
"prettier": "^2.7.1",
"recursive-readdir-files": "^2.3.0",
"rehype-autolink-headings": "^6.1.1",
"rehype-document": "^6.1.0",
"rehype-slug": "^5.0.1",
"remark-gemoji": "^7.0.1"
},
"engines": {
"node": ">=16.0.0"
}
}

View File

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" height="1em" width="1em" viewBox="0 0 65 65">
<path fill="currentColor" d="M32,0 C49.672,0 64,14.328 64,32 C64,49.674 49.674,64 32,64 C14.326,64 0,49.674 0,32 C0,14.326 14.328,0 32,0 Z M32.539,12.688 C31.666,12.688 30.875,13.156 30.511,14.04 L16.52,47.664 L21.303,47.664 L26.837,33.801 L43.352,47.144 C44.016,47.681 44.496,47.924 45.119,47.924 C46.367,47.924 47.457,46.988 47.457,45.638 C47.457,45.418 47.379,45.068 47.239,44.694 L34.512,14.04 C34.148,13.156 33.412,12.688 32.539,12.688 Z M32.54,19.548 L40.82,39.986 L28.312,30.133 L32.54,19.548 Z" transform="translate(.38 .76)"/>
</svg>

After

Width:  |  Height:  |  Size: 648 B

3
scripts/assets/cargo.svg Normal file
View File

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" width="1em" height="1em" viewBox="0 0 32 32">
<path d="M15 3.77a.951.951 0 1 1 1.902 0 .951.951 0 0 1-1.902 0M3.654 12.38a.951.951 0 1 1 1.902 0 .951.951 0 0 1-1.902 0m22.692.044a.951.951 0 0 1 1.902 0 .951.951 0 0 1-1.902 0M6.406 13.73a.87.87 0 0 0 .441-1.146l-.422-.954h1.66v7.48H4.736a11.71 11.71 0 0 1-.379-4.47zm6.942.184v-2.205H17.3c.204 0 1.44.236 1.44 1.16 0 .768-.95 1.044-1.73 1.044zM7.952 25.785a.951.951 0 1 1 1.902 0 .951.951 0 0 1-1.902 0m14.093.044a.951.951 0 0 1 1.902 0 .951.951 0 0 1-1.902 0m.294-2.157a.867.867 0 0 0-1.03.667l-.477 2.228a11.71 11.71 0 0 1-9.765-.047l-.477-2.228a.865.865 0 0 0-1.03-.667l-1.967.422a11.71 11.71 0 0 1-1.017-1.199h9.57c.108 0 .18-.02.18-.118v-3.385c0-.1-.072-.118-.18-.118h-2.8v-2.146h3.027c.276 0 1.477.08 1.862 1.614l.565 2.5c.18.55.913 1.653 1.693 1.653h4.94a11.71 11.71 0 0 1-1.085 1.255zm5.314-8.938a11.71 11.71 0 0 1 .025 2.033h-1.2c-.12 0-.17.08-.17.197v.552c0 1.3-.732 1.58-1.374 1.653-.61.07-1.29-.256-1.372-.63-.36-2.028-.96-2.46-1.9-3.21 1.177-.748 2.402-1.85 2.402-3.327 0-1.594-1.093-2.598-1.838-3.09-1.045-.69-2.202-.827-2.514-.827H7.277a11.71 11.71 0 0 1 6.551-3.697l1.465 1.537c.33.347.88.36 1.226.028l1.64-1.567a11.71 11.71 0 0 1 8.017 5.709l-1.122 2.534a.87.87 0 0 0 .441 1.146zm2.798.04-.038-.392 1.156-1.078c.235-.22.147-.66-.153-.772l-1.477-.552-.116-.38.92-1.28c.188-.26.015-.675-.3-.727l-1.558-.253-.187-.35.655-1.437c.134-.293-.115-.667-.437-.655l-1.58.055-.25-.303.363-1.54c.073-.313-.244-.63-.557-.557l-1.54.363-.304-.25.055-1.58c.012-.32-.362-.57-.654-.437l-1.436.655-.35-.188-.254-1.558c-.05-.316-.467-.488-.727-.3l-1.28.92-.38-.115L19.47.586c-.112-.3-.553-.388-.772-.154L17.62 1.588l-.392-.038-.832-1.345c-.168-.272-.62-.272-.787 0l-.832 1.345-.392.038L13.305.43c-.22-.234-.66-.147-.772.154l-.552 1.477-.38.115-1.28-.92c-.26-.188-.676-.015-.727.3L9.34 3.114l-.35.188-1.436-.655c-.292-.133-.667.117-.654.437l.055 1.58-.304.25-1.54-.363c-.313-.073-.63.244-.557.557l.363 1.54-.25.303-1.58-.055c-.32-.01-.57.362-.437.655l.655 1.437-.188.35-1.558.253c-.316.05-.488.467-.3.727l.92 1.28-.116.38-1.477.552c-.3.112-.388.553-.153.772l1.156 1.078-.038.392-1.345.832c-.272.168-.272.62 0 .787l1.345.832.038.392L.43 18.697c-.234.22-.147.66.153.772l1.477.552.116.38-.92 1.28c-.187.26-.015.676.3.727l1.557.253.188.35-.655 1.436c-.133.292.118.667.437.655l1.58-.055.25.304-.363 1.54c-.073.312.244.63.557.556l1.54-.363.304.25-.055 1.58c-.012.32.362.57.654.437l1.436-.655.35.188.254 1.557c.05.317.467.488.727.302l1.28-.922.38.116.552 1.477c.112.3.553.388.772.153l1.078-1.156.392.04.832 1.345c.168.27.618.272.787 0l.832-1.345.392-.04 1.078 1.156c.22.235.66.147.772-.153l.552-1.477.38-.116 1.28.922c.26.187.676.015.727-.302l.254-1.557.35-.188 1.436.655c.292.133.666-.116.654-.437l-.055-1.58.303-.25 1.54.363c.313.073.63-.244.557-.556l-.363-1.54.25-.304 1.58.055c.32.013.57-.363.437-.655l-.655-1.436.187-.35 1.558-.253c.317-.05.49-.466.3-.727l-.92-1.28.116-.38 1.477-.552c.3-.113.388-.553.153-.772l-1.156-1.078.038-.392 1.345-.832c.272-.168.273-.618 0-.787z"/>
</svg>

After

Width:  |  Height:  |  Size: 3.0 KiB

3
scripts/assets/cmake.svg Normal file
View File

@ -0,0 +1,3 @@
<svg viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg" height="1em" width="1em">
<path d="M11.769.066.067 23.206l12.76-10.843zm11.438 23.868L7.471 17.587 0 23.934zm.793-.198L12.298.463l1.719 19.24zM12.893 12.959l-5.025 4.298 5.62 2.248z"/>
</svg>

After

Width:  |  Height:  |  Size: 274 B

View File

@ -1,3 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" height="1em" width="1em" viewBox="0 0 24 24">
<path d="M19.54 5.08A10.61 10.61 0 0 0 11.91 2a10 10 0 0 0-.05 20 2.58 2.58 0 0 0 2.53-1.89 2.52 2.52 0 0 0-.57-2.28.5.5 0 0 1 .37-.83h1.65A6.15 6.15 0 0 0 22 11.33a8.48 8.48 0 0 0-2.46-6.25Zm-12.7 9.66a1.5 1.5 0 1 1 .4-2.08 1.49 1.49 0 0 1-.4 2.08ZM8.3 9.25a1.5 1.5 0 1 1-.55-2 1.5 1.5 0 0 1 .55 2ZM11 7a1.5 1.5 0 1 1 1.5-1.5A1.5 1.5 0 0 1 11 7Zm5.75.8a1.5 1.5 0 1 1 .55-2 1.5 1.5 0 0 1-.55 2Z" style="fill:#231f20" id="color-palette-2"/>
<path d="M19.54 5.08A10.61 10.61 0 0 0 11.91 2a10 10 0 0 0-.05 20 2.58 2.58 0 0 0 2.53-1.89 2.52 2.52 0 0 0-.57-2.28.5.5 0 0 1 .37-.83h1.65A6.15 6.15 0 0 0 22 11.33a8.48 8.48 0 0 0-2.46-6.25Zm-12.7 9.66a1.5 1.5 0 1 1 .4-2.08 1.49 1.49 0 0 1-.4 2.08ZM8.3 9.25a1.5 1.5 0 1 1-.55-2 1.5 1.5 0 0 1 .55 2ZM11 7a1.5 1.5 0 1 1 1.5-1.5A1.5 1.5 0 0 1 11 7Zm5.75.8a1.5 1.5 0 1 1 .55-2 1.5 1.5 0 0 1-.55 2Z" />
</svg>

Before

Width:  |  Height:  |  Size: 555 B

After

Width:  |  Height:  |  Size: 514 B

3
scripts/assets/conan.svg Normal file
View File

@ -0,0 +1,3 @@
<svg viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg" height="1em" width="1em">
<path d="M11.709 0 0 5.534V16.76L11.984 24l4.857-2.706V9.998c.13-.084.275-.196.399-.27l.032-.017c.197-.11.329-.102.23.33v10.884l6.466-3.603V6.11L24 6.093Zm.915 2.83c.932.02 1.855.191 2.706.552a9.106 9.106 0 0 1 3.45 2.429 62.814 62.814 0 0 1-3.044 1.616c.56-.853.14-2.009-.76-2.455-.93-.648-2.093-.73-3.205-.674-1.064.175-2.258.51-2.893 1.474-.722.862-.084 2.11.914 2.408 1.2.509 2.543.38 3.806.413-.975.457-1.931.97-2.927 1.358-1.701-.176-3.585-.917-4.374-2.51-.574-1.178.215-2.572 1.319-3.14a11.426 11.426 0 0 1 3.336-1.348 9.212 9.212 0 0 1 1.672-.123Z"/>
</svg>

After

Width:  |  Height:  |  Size: 674 B

View File

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" width="1em" height="1em" viewBox="0 0 230 230">
<path fill="currentColor" d="M200,0 C216.568542,-3.04359188e-15 230,13.4314575 230,30 L230,200 C230,216.568542 216.568542,230 200,230 L30,230 C13.4314575,230 9.13448861e-15,216.568542 0,200 L0,30 C-2.02906125e-15,13.4314575 13.4314575,1.01490192e-14 30,0 L200,0 Z M167.109375,83.5546875 L141.953125,83.5546875 L141.953125,132.96875 C141.953125,154.980469 140.605469,163.066406 137.011719,170.253906 C133.867188,176.992188 128.476562,181.933594 117.246094,186.875 L140.605469,198.105469 C151.835938,192.265625 157.226562,187.324219 161.269531,179.238281 C165.761719,171.152344 167.109375,161.71875 167.109375,141.503906 L167.109375,83.5546875 Z M127.128906,45.3710938 L101.972656,45.3710938 L101.972656,83.1054688 C97.9296875,82.2070312 94.7851562,82.2070312 90.7421875,82.2070312 C64.2382812,82.2070312 47.6171875,98.3789062 47.6171875,123.984375 C47.6171875,150.488281 63.3398438,164.414062 94.3359375,164.414062 C104.667969,164.414062 114.101562,163.066406 127.128906,160.820312 L127.128906,45.3710938 Z M93.4375,101.972656 C96.5820312,101.972656 98.828125,102.421875 101.972656,103.320312 L101.972656,143.300781 C97.9296875,144.199219 95.6835938,144.199219 92.9882812,144.199219 C79.9609375,144.199219 73.2226562,137.011719 73.2226562,123.535156 C73.2226562,110.058594 80.4101562,101.972656 93.4375,101.972656 Z M167.109375,45.3710938 L141.953125,45.3710938 L141.953125,70.9765625 L167.109375,70.9765625 L167.109375,45.3710938 Z"/>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

3
scripts/assets/emacs.svg Normal file
View File

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 32 32" height="1em" width="1em">
<path d="M15.995.016c-2.385.02-4.599.525-6.625 1.457l.011-.004c4.849 2.703 9.271 7.509 11.907 10.989.531.713 1.005 1.339 1.437 1.911l.005-.025c.552-2.317-.417-6.984-2.021-9.776-.156-.271-.271-.505-.249-.521h.005l.005-.005c.129.032 1.375 1.323 1.828 1.912.801 1.02 1.109 1.615 1.552 2.968 1.14 3.532 1.896 6.401 2.531 9.667.323 1.641.901 4.609.98 5.177.004.079-.016.172-.016.193-.125-.12-.256-.24-.385-.355-.86-.755-2.568-1.885-4.245-2.817-2.093-1.156-4.156-2.151-8.765-4.213-4.208-1.885-6.145-2.781-7.667-3.547l-1.369-.683.536 1.339s2.573 1.443 2.896 1.88c0 0 3.093 5.823 4.468 9.271 1.027 2.599 2.183 5.688 2.876 6.541l.077.089C14.403 31.131 8.111 28 8.111 28c-.693-5.864-2.625-12.812-5.14-19.917-.057-.119-.115-.239-.167-.364 0-.021.187.161.411.407 2.536 2.713 7.943 5.181 13.688 6.239 1.552.272 3.135.371 4.708.297-.407-.521-.855-1.093-1.344-1.735C15.71 6.99 11.236 4.495 7.226 2.97c-.104-.037-.203-.084-.307-.115A15.865 15.865 0 0 0 .892 10.76a16.037 16.037 0 0 0-.891 5.355L.006 16c.041 6.688 4.172 12.817 10.735 15.104 1.781.62 3.593.907 5.375.896l-.12-.005c6.693-.041 12.823-4.172 15.109-10.735.62-1.781.907-3.599.891-5.38V16C31.949 9.307 27.824 3.177 21.256.896A15.96 15.96 0 0 0 15.881 0l.12.005zm8.177 8.145c.708.683 1.839 2.005 3.115 2.751 1.052 1.317 1.625 2.615 2.333 3.504-.292-.249-1.484-1.296-1.484-1.296s-1.833-1.74-2.855-2.869c-.391-.439-.427-.505-.636-.839-.083-.131-.364-1.1-.473-1.245l.005-.011z"/>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -0,0 +1,3 @@
<svg viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg" height="1em" width="1em">
<path d="M21.72 17.91V6.5l-.53-.49L9.05 18.52l-1.29-.06L24 1.53l-.33-.95-11.93 1-5.75 6.6v-.23l4.7-5.39-1.38-.77-9.11.77v2.85l1.91.46v.01l.19-.01-.56.66v10.6c.609-.126 1.22-.241 1.83-.36L14.12 5.22l.83-.04L0 21.44l9.67.82 1.35-.77 6.82-6.74v2.15l-5.72 5.57 11.26.95.35-.94v-3.16l-3.29-.18a64.66 64.66 0 0 0 1.28-1.23z"/>
</svg>

After

Width:  |  Height:  |  Size: 436 B

3
scripts/assets/gmail.svg Normal file
View File

@ -0,0 +1,3 @@
<svg viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg" height="1em" width="1em">
<path d="M24 5.457v13.909c0 .904-.732 1.636-1.636 1.636h-3.819V11.73L12 16.64l-6.545-4.91v9.273H1.636A1.636 1.636 0 0 1 0 19.366V5.457c0-2.023 2.309-3.178 3.927-1.964L5.455 4.64 12 9.548l6.545-4.91 1.528-1.145C21.69 2.28 24 3.434 24 5.457z"/>
</svg>

After

Width:  |  Height:  |  Size: 358 B

3
scripts/assets/java.svg Normal file
View File

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 384 512" height="1em" width="1em">
<path d="M277.74 312.9c9.8-6.7 23.4-12.5 23.4-12.5s-38.7 7-77.2 10.2c-47.1 3.9-97.7 4.7-123.1 1.3-60.1-8 33-30.1 33-30.1s-36.1-2.4-80.6 19c-52.5 25.4 130 37 224.5 12.1zm-85.4-32.1c-19-42.7-83.1-80.2 0-145.8C296 53.2 242.84 0 242.84 0c21.5 84.5-75.6 110.1-110.7 162.6-23.9 35.9 11.7 74.4 60.2 118.2zm114.6-176.2c.1 0-175.2 43.8-91.5 140.2 24.7 28.4-6.5 54-6.5 54s62.7-32.4 33.9-72.9c-26.9-37.8-47.5-56.6 64.1-121.3zm-6.1 270.5a12.19 12.19 0 0 1-2 2.6c128.3-33.7 81.1-118.9 19.8-97.3a17.33 17.33 0 0 0-8.2 6.3 70.45 70.45 0 0 1 11-3c31-6.5 75.5 41.5-20.6 91.4zM348 437.4s14.5 11.9-15.9 21.2c-57.9 17.5-240.8 22.8-291.6.7-18.3-7.9 16-19 26.8-21.3 11.2-2.4 17.7-2 17.7-2-20.3-14.3-131.3 28.1-56.4 40.2C232.84 509.4 401 461.3 348 437.4zM124.44 396c-78.7 22 47.9 67.4 148.1 24.5a185.89 185.89 0 0 1-28.2-13.8c-44.7 8.5-65.4 9.1-106 4.5-33.5-3.8-13.9-15.2-13.9-15.2zm179.8 97.2c-78.7 14.8-175.8 13.1-233.3 3.6 0-.1 11.8 9.7 72.4 13.6 92.2 5.9 233.8-3.3 237.1-46.9 0 0-6.4 16.5-76.2 29.7zM260.64 353c-59.2 11.4-93.5 11.1-136.8 6.6-33.5-3.5-11.6-19.7-11.6-19.7-86.8 28.8 48.2 61.4 169.5 25.9a60.37 60.37 0 0 1-21.1-12.8z"/>
</svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" height="1em" width="1em" viewBox="0 0 170 155">
<path fill="currentColor" d="M114.011719,0 C114.031753,0 114.051781,9.66838127e-05 114.071803,0.00028991369 L113.950625,0 C114.100589,0 114.249952,0.00491257692 114.398738,0.0147015257 C114.496091,0.0180986001 114.59346,0.0264563127 114.690679,0.0370869506 C114.763187,0.0481571338 114.835494,0.0572318789 114.907669,0.067464417 C114.971991,0.0739091229 115.036007,0.0841522806 115.099959,0.0953775501 C115.24595,0.122450074 115.39156,0.152173631 115.536656,0.18662408 C115.540798,0.188498498 115.544794,0.189486731 115.54879,0.190478791 C119.122197,1.04453486 122.383831,4.76737051 125.66002,10.8263087 C134.504866,26.8199813 143.233527,58.3720491 155.079417,90.6337197 C159.654754,102.628081 164.55935,114.497108 169.788199,126.226944 L169.804687,126.261915 C169.561883,126.036533 169.320725,125.810778 169.080287,125.584766 C157.868517,115.075569 148.22195,104.663526 137.239023,104.2475 C132.658523,104.354002 127.856902,106.798464 122.838279,110.852094 C115.884496,116.808357 108.801576,125.883622 101.371385,134.204547 C98.5874924,137.56095 95.5963582,140.611013 92.6231575,143.258032 C88.7439115,146.854737 84.755953,149.885794 80.6318234,151.86198 C77.8565289,153.320564 75.5138817,154.09239 73.9252344,154.03711 C73.9252344,154.03711 73.6050703,153.13142 73.0221211,151.57669 C72.3047411,149.730047 71.5034539,147.651723 70.6255994,145.430214 C66.7152626,135.747112 59.8767348,120.415838 53.1632895,113.088875 C51.6852935,111.572994 50.1641478,110.359882 48.6081822,109.545946 C44.005418,107.866712 38.8723879,108.38614 34.6886719,110.979493 L0.055,86.396 L48.3332422,66.8904688 L48.6560848,66.4654629 C53.451559,60.1199079 58.8698811,54.2694715 64.8303516,49.0016797 L64.5185432,49.2785154 C64.6217228,49.1857698 64.7250601,49.0931917 64.8285547,49.0007813 C68.8310937,46.8777734 76.3510156,48.0304688 90.1177734,30.9287109 C90.3414762,30.6490748 90.5626216,30.370121 90.781262,30.0919051 C92.8016022,27.5154524 94.6118072,25.0027302 96.2508432,22.5981511 L96.5028669,22.2275882 C105.052639,9.58238289 108.828956,0 113.950625,0 L113.994,0.001 Z"/>
</svg>

After

Width:  |  Height:  |  Size: 2.1 KiB

2
scripts/assets/mysql.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 5.8 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 6.0 KiB

View File

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 448 512" height="1em" width="1em">
<path d="M439.8 200.5c-7.7-30.9-22.3-54.2-53.4-54.2h-40.1v47.4c0 36.8-31.2 67.8-66.8 67.8H172.7c-29.2 0-53.4 25-53.4 54.3v101.8c0 29 25.2 46 53.4 54.3 33.8 9.9 66.3 11.7 106.8 0 26.9-7.8 53.4-23.5 53.4-54.3v-40.7H226.2v-13.6h160.2c31.1 0 42.6-21.7 53.4-54.2 11.2-33.5 10.7-65.7 0-108.6zM286.2 404c11.1 0 20.1 9.1 20.1 20.3 0 11.3-9 20.4-20.1 20.4-11 0-20.1-9.2-20.1-20.4.1-11.3 9.1-20.3 20.1-20.3zM167.8 248.1h106.8c29.7 0 53.4-24.5 53.4-54.3V91.9c0-29-24.4-50.7-53.4-55.6-35.8-5.9-74.7-5.6-106.8.1-45.2 8-53.4 24.7-53.4 55.6v40.7h106.9v13.6h-147c-31.1 0-58.3 18.7-66.8 54.2-9.8 40.7-10.2 66.1 0 108.6 7.6 31.6 25.7 54.2 56.8 54.2H101v-48.8c0-35.3 30.5-66.4 66.8-66.4zm-6.7-142.6c-11.1 0-20.1-9.1-20.1-20.3.1-11.3 9-20.4 20.1-20.4 11 0 20.1 9.2 20.1 20.4s-9 20.3-20.1 20.3z"/>
</svg>

After

Width:  |  Height:  |  Size: 894 B

3
scripts/assets/rust.svg Normal file
View File

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" width="1em" height="1em" viewBox="0 0 32 32">
<path d="M15 3.77a.951.951 0 1 1 1.902 0 .951.951 0 0 1-1.902 0M3.654 12.38a.951.951 0 1 1 1.902 0 .951.951 0 0 1-1.902 0m22.692.044a.951.951 0 0 1 1.902 0 .951.951 0 0 1-1.902 0M6.406 13.73a.87.87 0 0 0 .441-1.146l-.422-.954h1.66v7.48H4.736a11.71 11.71 0 0 1-.379-4.47zm6.942.184v-2.205H17.3c.204 0 1.44.236 1.44 1.16 0 .768-.95 1.044-1.73 1.044zM7.952 25.785a.951.951 0 1 1 1.902 0 .951.951 0 0 1-1.902 0m14.093.044a.951.951 0 0 1 1.902 0 .951.951 0 0 1-1.902 0m.294-2.157a.867.867 0 0 0-1.03.667l-.477 2.228a11.71 11.71 0 0 1-9.765-.047l-.477-2.228a.865.865 0 0 0-1.03-.667l-1.967.422a11.71 11.71 0 0 1-1.017-1.199h9.57c.108 0 .18-.02.18-.118v-3.385c0-.1-.072-.118-.18-.118h-2.8v-2.146h3.027c.276 0 1.477.08 1.862 1.614l.565 2.5c.18.55.913 1.653 1.693 1.653h4.94a11.71 11.71 0 0 1-1.085 1.255zm5.314-8.938a11.71 11.71 0 0 1 .025 2.033h-1.2c-.12 0-.17.08-.17.197v.552c0 1.3-.732 1.58-1.374 1.653-.61.07-1.29-.256-1.372-.63-.36-2.028-.96-2.46-1.9-3.21 1.177-.748 2.402-1.85 2.402-3.327 0-1.594-1.093-2.598-1.838-3.09-1.045-.69-2.202-.827-2.514-.827H7.277a11.71 11.71 0 0 1 6.551-3.697l1.465 1.537c.33.347.88.36 1.226.028l1.64-1.567a11.71 11.71 0 0 1 8.017 5.709l-1.122 2.534a.87.87 0 0 0 .441 1.146zm2.798.04-.038-.392 1.156-1.078c.235-.22.147-.66-.153-.772l-1.477-.552-.116-.38.92-1.28c.188-.26.015-.675-.3-.727l-1.558-.253-.187-.35.655-1.437c.134-.293-.115-.667-.437-.655l-1.58.055-.25-.303.363-1.54c.073-.313-.244-.63-.557-.557l-1.54.363-.304-.25.055-1.58c.012-.32-.362-.57-.654-.437l-1.436.655-.35-.188-.254-1.558c-.05-.316-.467-.488-.727-.3l-1.28.92-.38-.115L19.47.586c-.112-.3-.553-.388-.772-.154L17.62 1.588l-.392-.038-.832-1.345c-.168-.272-.62-.272-.787 0l-.832 1.345-.392.038L13.305.43c-.22-.234-.66-.147-.772.154l-.552 1.477-.38.115-1.28-.92c-.26-.188-.676-.015-.727.3L9.34 3.114l-.35.188-1.436-.655c-.292-.133-.667.117-.654.437l.055 1.58-.304.25-1.54-.363c-.313-.073-.63.244-.557.557l.363 1.54-.25.303-1.58-.055c-.32-.01-.57.362-.437.655l.655 1.437-.188.35-1.558.253c-.316.05-.488.467-.3.727l.92 1.28-.116.38-1.477.552c-.3.112-.388.553-.153.772l1.156 1.078-.038.392-1.345.832c-.272.168-.272.62 0 .787l1.345.832.038.392L.43 18.697c-.234.22-.147.66.153.772l1.477.552.116.38-.92 1.28c-.187.26-.015.676.3.727l1.557.253.188.35-.655 1.436c-.133.292.118.667.437.655l1.58-.055.25.304-.363 1.54c-.073.312.244.63.557.556l1.54-.363.304.25-.055 1.58c-.012.32.362.57.654.437l1.436-.655.35.188.254 1.557c.05.317.467.488.727.302l1.28-.922.38.116.552 1.477c.112.3.553.388.772.153l1.078-1.156.392.04.832 1.345c.168.27.618.272.787 0l.832-1.345.392-.04 1.078 1.156c.22.235.66.147.772-.153l.552-1.477.38-.116 1.28.922c.26.187.676.015.727-.302l.254-1.557.35-.188 1.436.655c.292.133.666-.116.654-.437l-.055-1.58.303-.25 1.54.363c.313.073.63-.244.557-.556l-.363-1.54.25-.304 1.58.055c.32.013.57-.363.437-.655l-.655-1.436.187-.35 1.558-.253c.317-.05.49-.466.3-.727l-.92-1.28.116-.38 1.477-.552c.3-.113.388-.553.153-.772l-1.156-1.078.038-.392 1.345-.832c.272-.168.273-.618 0-.787z"/>
</svg>

After

Width:  |  Height:  |  Size: 3.0 KiB

4
scripts/assets/vue.svg Normal file
View File

@ -0,0 +1,4 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24" height="1em" width="1em">
<path d="m12 12.765 5.592-9.437h-3.276L12 7.33v.002L9.688 3.328h-3.28z"/>
<path d="M18.461 3.332 12 14.235 5.539 3.332H1.992L12 20.672l10.008-17.34z"/>
</svg>

After

Width:  |  Height:  |  Size: 269 B

3
scripts/assets/xcode.svg Normal file
View 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="M19.06 5.333c.452-.194.774-.258 1.097-.194.516.13.774.516.968.71.194.387.903.774 1.226.839.258.064.71-.645 1.033-1.29.322-.582.516-1.356.451-1.55-.064-.193-.968-.58-1.161-.58-.13 0-.388.129-.84.064-.45-.064-.903-.58-1.16-.968-.453-.645-1.098-1.032-1.679-1.355C18.35.686 17.64.493 16.93.364 15.898.105 14.865-.088 13.833.04c-.58.064-1.29.129-1.807.323-.065 0-.194.193-.065.193s.581.065.581.065-.58.129-.58.258c0 .13.064.13.129.13.064 0 1.484-.065 2.065 0 .645.128 1.355.45 1.807 1.225.774 1.42.451 2.775.258 3.227-.968 2.13-8.648 15.23-9.035 16.133-.387.903-.516 1.484.581 2.065s1.678.322 2-.065c.388-.516 7.034-17.165 9.293-18.262zm-3.614 8.711h1.549c1.032 0 1.226.517 1.226.71.065.516-.194 1.162-1.226 1.162h-.968l.774 1.29c.452.775.258 1.162 0 1.42-.387.387-1.226.387-1.677-.452l-.904-1.548c-.645 1.42-1.29 2.968-2.065 4.775h4.001c1.936 0 3.55-1.613 3.55-3.55V6.56c-.065-.13-.194-.065-.259 0-.387.451-1.484 2-4 7.485zm-9.809 8.002h-.322a4.186 4.186 0 0 1-4.195-4.194V7.01a4.186 4.186 0 0 1 4.195-4.195h9.357c-.194-.194-.968-.516-1.742-.452-.323 0-.968.13-1.356-.129-.387-.322-.322-.516-.903-.516H4.928A4.764 4.764 0 0 0 .152 6.494V18.24c0 2.646 2.13 4.775 4.453 4.71.645 0 .839-.516 1.032-.903zm14.778-15.1v10.906a4.186 4.186 0 0 1-4.194 4.194h-4.324s-.387 1.033.839 1.033h3.872a4.764 4.764 0 0 0 4.775-4.776V8.817c.065-.903-.71-1.484-.968-1.871zM1.83 7.01v10.84c0 1.937 1.613 3.55 3.55 3.55h.58c0-.065.774-1.42 2.452-4.26.194-.386.452-.773.71-1.225h-4.71c-.581 0-.904-.387-.969-.71-.129-.516.194-1.162.904-1.162h2.387l3.034-5.291s-.71-1.29-.904-1.613c-.258-.452-.129-.904.13-1.162.386-.387 1.032-.58 1.677.452l.258.387.258-.387c.58-.84.968-.775 1.29-.71.517.129.84.71.388 1.613l-4.001 6.711h1.355c.452-.774.904-1.548 1.355-2.387-.064-.323-.129-.71-.064-1.033.064-.516.323-.968.645-1.355l.387.645c1.227-2.13 2.13-3.936 2.388-4.646.13-.387.323-1.162.13-1.807H5.38a3.54 3.54 0 0 0-3.55 3.55zm2.775 10.776c0-.064.774-1.42.774-1.42 1.227-.322 1.807.452 1.872.517 0 0-.84 1.484-1.097 1.742s-.581.323-.904.258c-.516-.129-.839-.645-.645-1.097z"/>
</svg>

After

Width:  |  Height:  |  Size: 2.1 KiB

3
scripts/assets/yarn.svg Normal file
View 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="M12 0C5.375 0 0 5.375 0 12s5.375 12 12 12 12-5.375 12-12S18.625 0 12 0zm.768 4.105c.183 0 .363.053.525.157.125.083.287.185.755 1.154.31-.088.468-.042.551-.019.204.056.366.19.463.375.477.917.542 2.553.334 3.605-.241 1.232-.755 2.029-1.131 2.576.324.329.778.899 1.117 1.825.278.774.31 1.478.273 2.015a5.51 5.51 0 0 0 .602-.329c.593-.366 1.487-.917 2.553-.931.714-.009 1.269.445 1.353 1.103a1.23 1.23 0 0 1-.945 1.362c-.649.158-.95.278-1.821.843-1.232.797-2.539 1.242-3.012 1.39a1.686 1.686 0 0 1-.704.343c-.737.181-3.266.315-3.466.315h-.046c-.783 0-1.214-.241-1.45-.491-.658.329-1.51.19-2.122-.134a1.078 1.078 0 0 1-.58-1.153 1.243 1.243 0 0 1-.153-.195c-.162-.25-.528-.936-.454-1.946.056-.723.556-1.367.88-1.71a5.522 5.522 0 0 1 .408-2.256c.306-.727.885-1.348 1.32-1.737-.32-.537-.644-1.367-.329-2.21.227-.602.412-.936.82-1.08h-.005c.199-.074.389-.153.486-.259a3.418 3.418 0 0 1 2.298-1.103c.037-.093.079-.185.125-.283.31-.658.639-1.029 1.024-1.168a.94.94 0 0 1 .328-.06zm.006.7c-.507.016-1.001 1.519-1.001 1.519s-1.27-.204-2.266.871c-.199.218-.468.334-.746.44-.079.028-.176.023-.417.672-.371.991.625 2.094.625 2.094s-1.186.839-1.626 1.881c-.486 1.144-.338 2.261-.338 2.261s-.843.732-.899 1.487c-.051.663.139 1.2.343 1.515.227.343.51.176.51.176s-.561.653-.037.931c.477.25 1.283.394 1.71-.037.31-.31.371-1.001.486-1.283.028-.065.12.111.209.199.097.093.264.195.264.195s-.755.324-.445 1.066c.102.246.468.403 1.066.398.222-.005 2.664-.139 3.313-.296.375-.088.505-.283.505-.283s1.566-.431 2.998-1.357c.917-.598 1.293-.76 2.034-.936.612-.148.57-1.098-.241-1.084-.839.009-1.575.44-2.196.825-1.163.718-1.742.672-1.742.672l-.018-.032c-.079-.13.371-1.293-.134-2.678-.547-1.515-1.413-1.881-1.344-1.997.297-.5 1.038-1.297 1.334-2.78.176-.899.13-2.377-.269-3.151-.074-.144-.732.241-.732.241s-.616-1.371-.788-1.483a.271.271 0 0 0-.157-.046z"/>
</svg>

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -1,3 +1,3 @@
import { run } from './index.mjs';
run()
run();

View File

@ -2,8 +2,6 @@ import markdown from '@wcj/markdown-to-html';
import rehypeDocument from 'rehype-document';
import remarkGemoji from 'remark-gemoji';
import rehypeRaw from 'rehype-raw';
import rehypeAttrs from 'rehype-attr';
import rehypeKatex from 'rehype-katex';
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
import rehypeSlug from 'rehype-slug';
import { htmlTagAddAttri } from './nodes/htmlTagAddAttri.mjs';
@ -23,8 +21,11 @@ export function create(str = '', options = {}) {
let title = str.match(/[^===]+(?=[===])/g) || [];
let description = str.match(/\n==={1,}\n+([\s\S]*?)\n/g) || [];
title = title[0] || '';
description = (description[0] || '').replace(/^\n[=\n]+/, '').replace(/\[([\s\S]*?)?\]\(([\s\S]*?)?\)/g, '$1').replace(/\n/, '');
const subTitle = options.filename && !options.isHome ? `${options.filename} cheatsheet & `: ''
description = (description[0] || '')
.replace(/^\n[=\n]+/, '')
.replace(/\[([\s\S]*?)?\]\(([\s\S]*?)?\)/g, '$1')
.replace(/\n/, '');
const subTitle = options.filename && !options.isHome ? `${options.filename} cheatsheet & ` : '';
const mdOptions = {
showLineNumbers: false,
hastNode: false,
@ -32,31 +33,39 @@ export function create(str = '', options = {}) {
rehypePlugins: [
rehypeSlug,
rehypeAutolinkHeadings,
[rehypeDocument, {
[
rehypeDocument,
{
title: `${title ? `${title} & ` : ''} ${subTitle} Quick Reference`,
css: [ ...options.css ],
link: [
{rel: 'icon', href: favicon, type: 'image/svg+xml'}
],
css: [...options.css],
link: [{ rel: 'icon', href: favicon, type: 'image/svg+xml' }],
meta: [
{ description: `${description}为开发人员分享快速参考备忘单。` },
{ keywords: `Quick,Reference,cheatsheet,${!options.isHome && options.filename || ''}` }
]
}]
{ keywords: `Quick,Reference,cheatsheet,${(!options.isHome && options.filename) || ''}` },
],
},
],
],
filterPlugins: (type, plugins = []) => {
if (type === 'rehype') {
const dt = plugins.filter(plug => {
return /(rehypeRaw)/.test(plug.name) ? false : true;
let rehypePrism = null;
const dt = plugins.filter((plug) => {
if (Array.isArray(plug) && /(rehypePrism)/.test(plug[0].name)) {
rehypePrism = plug;
}
return /(rehypeRaw|rehypePrism)/.test(plug.name) ? false : true;
});
// 放在 rehypeDocument 前面
dt.unshift(rehypeRaw)
dt.unshift(rehypeRaw);
if (rehypePrism) {
dt.unshift(rehypePrism);
}
dt.unshift(rehypePreviewHTML);
return dt;
}
return plugins
return plugins;
},
rewrite: (node, index, parent) => {
rehypePreviewHTML(node, parent);
rehypeTitle(node, options.filename);
homeCardIcons(node, parent, options.isHome);
tooltips(node, index, parent);
@ -64,10 +73,10 @@ export function create(str = '', options = {}) {
rehypeUrls(node);
if (node.children) {
if (node.type === 'element' && node.tagName === 'body') {
const tocsData = getTocsTree([ ...node.children ]);
const tocsData = getTocsTree([...node.children]);
if (!options.isHome) {
const tocsMenus = getTocsTitleNode([...tocsData]);
node.children = addTocsInWarp([...tocsData], getTocsTitleNodeWarpper(tocsMenus))
node.children = addTocsInWarp([...tocsData], getTocsTitleNodeWarpper(tocsMenus));
} else {
node.children = tocsData;
}
@ -76,9 +85,8 @@ export function create(str = '', options = {}) {
node.children.push(anchorPoint());
}
}
}
}
},
};
return markdown(str, mdOptions);
}
}

View File

@ -5,21 +5,24 @@ import { create } from './create.mjs';
export const OUTOUT = path.resolve(process.cwd(), 'dist');
export const DOCS = path.resolve(process.cwd(), 'docs');
export const CSSPATH = path.resolve(process.cwd(), 'scripts/style.css');
export const CSS_OUTPUT_PATH = path.resolve(OUTOUT, 'style/style.css');
export async function createHTML(files = [], num = 0) {
const dataFile = files[num];
if (!dataFile) {
console.log(' \n done!\n')
console.log(' \n done!\n');
return;
}
++num;
const githubURL = `https://github.com/jaywcjlove/reference/blob/main/${path.relative(process.cwd(), dataFile.path).replace(path.sep, '/')}`;
const githubURL = `https://github.com/jaywcjlove/reference/blob/main/${path
.relative(process.cwd(), dataFile.path)
.replace(path.sep, '/')}`;
const mdstr = await fs.readFile(dataFile.path);
const htmlPath = path.relative(DOCS, dataFile.path);
const outputHTMLPath = path.resolve(OUTOUT, 'docs', htmlPath).replace(/README.md$/i, 'index.html').replace(/.md$/, '.html');
const outputHTMLPath = path
.resolve(OUTOUT, 'docs', htmlPath)
.replace(/README.md$/i, 'index.html')
.replace(/.md$/, '.html');
await fs.ensureDir(path.dirname(outputHTMLPath));
@ -28,18 +31,21 @@ export async function createHTML(files = [], num = 0) {
isHome: /README.md$/.test(path.relative(process.cwd(), dataFile.path)),
githubURL,
homePath: path.relative(path.dirname(outputHTMLPath), path.resolve(OUTOUT, 'index.html')),
css: [path.relative(path.dirname(outputHTMLPath), CSS_OUTPUT_PATH)]
css: [
path.relative(path.dirname(outputHTMLPath), path.resolve(OUTOUT, 'style/style.css')),
path.relative(path.dirname(outputHTMLPath), path.resolve(OUTOUT, 'style/katex.css')),
],
});
await fs.writeFile(outputHTMLPath, html);
console.log(`♻️ \x1b[32;1m ${path.relative(OUTOUT, outputHTMLPath)} \x1b[0m`)
createHTML(files, num)
console.log(`♻️ \x1b[32;1m ${path.relative(OUTOUT, outputHTMLPath)} \x1b[0m`);
createHTML(files, num);
}
export async function run() {
await fs.ensureDir(OUTOUT);
await fs.emptyDir(OUTOUT);
await fs.ensureDir(path.dirname(CSS_OUTPUT_PATH));
await fs.copyFile(CSSPATH, CSS_OUTPUT_PATH)
await fs.ensureDir(path.resolve(OUTOUT, 'style'));
await fs.copy(path.resolve(process.cwd(), 'scripts/style'), path.resolve(OUTOUT, 'style'));
const files = await recursiveReaddirFiles(process.cwd(), {
ignored: /\/(node_modules|\.git)/,
exclude: /(\.json|\.mjs|CONTRIBUTING\.md)$/,

View File

@ -3,25 +3,25 @@ import { github, editor } from './logo.mjs';
import { getSVGNode } from '../utils/getSVGNode.mjs';
import { darkMode } from '../utils/darkMode.mjs';
const ICONS_PATH = path.resolve(process.cwd(), 'scripts/assets/quickreference.svg')
const ICONS_PATH = path.resolve(process.cwd(), 'scripts/assets/quickreference.svg');
export function header({ homePath, githubURL = '' }) {
const svgNode = getSVGNode(ICONS_PATH)
const svgNode = getSVGNode(ICONS_PATH);
const data = [
{
menu: true,
href: githubURL,
target: '__blank',
label: '编辑',
children: [editor]
children: [editor],
},
...darkMode(),
{
menu: true,
href: 'https://github.com/jaywcjlove/reference',
target: '__blank',
children: [github]
}
]
children: [github],
},
];
return {
type: 'element',
tagName: 'nav',
@ -51,10 +51,8 @@ export function header({ homePath, githubURL = '' }) {
properties: {
class: ['title'],
},
children: [
{ type: 'text', value: 'Quick Reference' }
]
}
children: [{ type: 'text', value: 'Quick Reference' }],
},
],
},
{
@ -75,29 +73,28 @@ export function header({ homePath, githubURL = '' }) {
type: 'element',
tagName: 'span',
properties: {},
children: label ? [
{ type: 'text', value: label }
] : []
}
]
}
children: label ? [{ type: 'text', value: label }] : [],
},
],
};
if (label) {
childs.children = [...children, {
type: 'element',
tagName: 'span',
properties: {},
children: [
{ type: 'text', value: label }
]
}];
childs.children = [
...children,
{
type: 'element',
tagName: 'span',
properties: {},
children: [{ type: 'text', value: label }],
},
];
} else {
childs.children = children;
}
return childs
return childs;
}),
},
],
}
},
],
};
}
}

View File

@ -5,4 +5,4 @@ export function htmlTagAddAttri(node, { isHome }) {
if (node && node.tagName === 'body' && isHome) {
node.properties.class = ['home'];
}
}
}

View File

@ -3,38 +3,38 @@ export const logo = [
type: 'element',
tagName: 'svg',
properties: {
viewBox: "0 0 24 24",
fill: "none",
xmlns: "http://www.w3.org/2000/svg",
height: "1em",
width: "1em"
viewBox: '0 0 24 24',
fill: 'none',
xmlns: 'http://www.w3.org/2000/svg',
height: '1em',
width: '1em',
},
children: [
{
type: 'element',
tagName: 'path',
properties: {
opacity: ".5",
d: "m21.66 10.44-.98 4.18c-.84 3.61-2.5 5.07-5.62 4.77-.5-.04-1.04-.13-1.62-.27l-1.68-.4c-4.17-.99-5.46-3.05-4.48-7.23l.98-4.19c.2-.85.44-1.59.74-2.2 1.17-2.42 3.16-3.07 6.5-2.28l1.67.39c4.19.98 5.47 3.05 4.49 7.23Z",
fill: "white"
opacity: '.5',
d: 'm21.66 10.44-.98 4.18c-.84 3.61-2.5 5.07-5.62 4.77-.5-.04-1.04-.13-1.62-.27l-1.68-.4c-4.17-.99-5.46-3.05-4.48-7.23l.98-4.19c.2-.85.44-1.59.74-2.2 1.17-2.42 3.16-3.07 6.5-2.28l1.67.39c4.19.98 5.47 3.05 4.49 7.23Z',
fill: 'white',
},
},
{
type: 'element',
tagName: 'path',
properties: {
d: "M15.06 19.39c-.62.42-1.4.77-2.35 1.08l-1.58.52c-3.97 1.28-6.06.21-7.35-3.76L2.5 13.28c-1.28-3.97-.22-6.07 3.75-7.35l1.58-.52c.41-.13.8-.24 1.17-.31-.3.61-.54 1.35-.74 2.2l-.98 4.19c-.98 4.18.31 6.24 4.48 7.23l1.68.4c.58.14 1.12.23 1.62.27Zm2.43-8.88c-.06 0-.12-.01-.19-.02l-4.85-1.23a.75.75 0 0 1 .37-1.45l4.85 1.23a.748.748 0 0 1-.18 1.47Z" ,
fill: "#cbd5e1"
d: 'M15.06 19.39c-.62.42-1.4.77-2.35 1.08l-1.58.52c-3.97 1.28-6.06.21-7.35-3.76L2.5 13.28c-1.28-3.97-.22-6.07 3.75-7.35l1.58-.52c.41-.13.8-.24 1.17-.31-.3.61-.54 1.35-.74 2.2l-.98 4.19c-.98 4.18.31 6.24 4.48 7.23l1.68.4c.58.14 1.12.23 1.62.27Zm2.43-8.88c-.06 0-.12-.01-.19-.02l-4.85-1.23a.75.75 0 0 1 .37-1.45l4.85 1.23a.748.748 0 0 1-.18 1.47Z',
fill: '#cbd5e1',
},
},
{
type: 'element',
tagName: 'path',
properties: {
d: "M14.56 13.89c-.06 0-.12-.01-.19-.02l-2.91-.74a.75.75 0 0 1 .37-1.45l2.91.74c.4.1.64.51.54.91-.08.34-.38.56-.72.56Z",
fill: "#292D32"
d: 'M14.56 13.89c-.06 0-.12-.01-.19-.02l-2.91-.74a.75.75 0 0 1 .37-1.45l2.91.74c.4.1.64.51.54.91-.08.34-.38.56-.72.56Z',
fill: '#292D32',
},
}
},
],
},
{
@ -43,48 +43,45 @@ export const logo = [
properties: {
class: ['title'],
},
children: [
{ type: 'text', value: 'Quick Reference' }
]
}
children: [{ type: 'text', value: 'Quick Reference' }],
},
];
export const github = {
type: 'element',
tagName: 'svg',
properties: {
viewBox: "0 0 16 16",
fill: "currentColor",
height: "1em",
width: "1em"
viewBox: '0 0 16 16',
fill: 'currentColor',
height: '1em',
width: '1em',
},
children: [
{
type: 'element',
tagName: 'path',
properties: {
d: "M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.012 8.012 0 0 0 16 8c0-4.42-3.58-8-8-8z",
d: 'M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.012 8.012 0 0 0 16 8c0-4.42-3.58-8-8-8z',
},
},
],
}
};
export const editor = {
type: 'element',
tagName: 'svg',
properties: {
viewBox: "0 0 36 36",
fill: "currentColor",
height: "1em",
width: "1em"
viewBox: '0 0 36 36',
fill: 'currentColor',
height: '1em',
width: '1em',
},
children: [
{
type: 'element',
tagName: 'path',
properties: {
d: "m33 6.4-3.7-3.7a1.71 1.71 0 0 0-2.36 0L23.65 6H6a2 2 0 0 0-2 2v22a2 2 0 0 0 2 2h22a2 2 0 0 0 2-2V11.76l3-3a1.67 1.67 0 0 0 0-2.36ZM18.83 20.13l-4.19.93 1-4.15 9.55-9.57 3.23 3.23ZM29.5 9.43 26.27 6.2l1.85-1.85 3.23 3.23Z",
d: 'm33 6.4-3.7-3.7a1.71 1.71 0 0 0-2.36 0L23.65 6H6a2 2 0 0 0-2 2v22a2 2 0 0 0 2 2h22a2 2 0 0 0 2-2V11.76l3-3a1.67 1.67 0 0 0 0-2.36ZM18.83 20.13l-4.19.93 1-4.15 9.55-9.57 3.23 3.23ZM29.5 9.43 26.27 6.2l1.85-1.85 3.23 3.23Z',
},
},
{
@ -92,8 +89,8 @@ export const editor = {
tagName: 'path',
properties: {
fill: 'none',
d: "M0 0h36v36H0z",
d: 'M0 0h36v36H0z',
},
},
],
}
};

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More