Compare commits

...

23 Commits

Author SHA1 Message Date
63739bff97 chore: update workflows config. 2022-11-13 23:26:22 +08:00
a4650ba20b released v1.20.0 2022-11-13 23:25:29 +08:00
304fca65aa feat: add latex.md #47 2022-11-13 23:20:45 +08:00
7dab4bc821 feat: add dart.md #58 2022-11-13 16:19:51 +08:00
a3a03dc5cf doc: add strcut and enum in the rust (#53)
* content: add strcut and enum in the rust

* update

* update
2022-11-13 14:20:13 +08:00
c4027826df doc: modify README.md. 2022-11-13 06:19:40 +00:00
ec5de21ad8 doc: modify CONTRIBUTING.md. 2022-11-13 06:19:39 +00:00
2d29bce40d feat: add php.md #57 2022-11-13 14:18:33 +08:00
45916503c1 doc: update ffmpeg.md #56 2022-11-13 03:53:34 +08:00
7dab833cb5 doc: update quickreference.md. 2022-11-13 03:46:04 +08:00
2787e80dd2 doc: modify README.md. 2022-11-12 18:48:34 +00:00
51377308ab doc: modify CONTRIBUTING.md. 2022-11-12 18:48:34 +00:00
5660ad20dd chore: update contributors. 2022-11-13 02:47:29 +08:00
0917f70be8 doc: add fliter in the ffmpeg (#56) 2022-11-13 00:09:24 +08:00
dcbdaea754 typo: fix typo content in the vim (#52) 2022-11-12 18:01:57 +08:00
144f263ad0 doc: update typescript.md. 2022-11-12 14:28:27 +08:00
ef5a27f5a1 doc: update typescript.md. 2022-11-12 14:26:09 +08:00
82457e896e fix: 修正选择器的真正含义 update css.md (#51) 2022-11-12 12:38:48 +08:00
d796def71c website: update style. 2022-11-12 09:18:22 +08:00
8cb9a8eaa4 doc: update regex.md 2022-11-12 09:17:56 +08:00
739697937d doc: fix error in regex.md 2022-11-12 01:22:29 +08:00
4ce6660ca8 doc: update rust.md #50 #49 2022-11-12 00:53:33 +08:00
5677612d9d doc: add some content in the rust.md (#50) 2022-11-12 00:40:56 +08:00
22 changed files with 2877 additions and 401 deletions

View File

@ -18,11 +18,26 @@ jobs:
- name: Generate Contributors Images
uses: jaywcjlove/github-action-contributors@main
id: contributors
with:
filter-author: (renovate\[bot\]|renovate-bot|dependabot\[bot\])
output: dist/CONTRIBUTORS.svg
avatarSize: 42
- name: Modify CONTRIBUTING.md
uses: jaywcjlove/github-action-modify-file-content@main
with:
path: CONTRIBUTING.md
body: |
${{steps.contributors.outputs.htmlTable}}
- name: Modify README.md
uses: jaywcjlove/github-action-modify-file-content@main
with:
path: README.md
body: |
${{steps.contributors.outputs.htmlList}}
- name: Create Tag
id: create_tag
uses: jaywcjlove/create-tag-action@main

View File

@ -83,4 +83,49 @@ npm run build # 编译输出 HTML
npm run start # 监听 md 文件编译输出 HTML
```
- 或者你也可以使用 `pnpm` 或者 `yarn` 做为包管理器
或者你也可以使用 `pnpm` 或者 `yarn` 做为包管理器
## 贡献
请参阅[贡献指南](./CONTRIBUTING.md)了解如何开始。一如既往,感谢我们出色的贡献者!
<!--GAMFC--><a href="https://github.com/jaywcjlove" title="小弟调调™">
<img src="https://avatars.githubusercontent.com/u/1680273?v=4" width="42;" alt="小弟调调™"/>
</a>
<a href="https://github.com/Jack-Zhang-1314" title="fw_qaq">
<img src="https://avatars.githubusercontent.com/u/82551626?v=4" width="42;" alt="fw_qaq"/>
</a>
<a href="https://github.com/catcto" title="喵仙人">
<img src="https://avatars.githubusercontent.com/u/5467932?v=4" width="42;" alt="喵仙人"/>
</a>
<a href="https://github.com/demigodliu" title="DemigodLiu">
<img src="https://avatars.githubusercontent.com/u/30372735?v=4" width="42;" alt="DemigodLiu"/>
</a>
<a href="https://github.com/JetSquirrel" title="JetSquirrel">
<img src="https://avatars.githubusercontent.com/u/20291255?v=4" width="42;" alt="JetSquirrel"/>
</a>
<a href="https://github.com/gaoxiaoduan" title="coderduan">
<img src="https://avatars.githubusercontent.com/u/69953511?v=4" width="42;" alt="coderduan"/>
</a>
<a href="https://github.com/hweining" title="hweining">
<img src="https://avatars.githubusercontent.com/u/8973985?v=4" width="42;" alt="hweining"/>
</a>
<a href="https://github.com/liliangrong777" title="liliangrong777">
<img src="https://avatars.githubusercontent.com/u/58727146?v=4" width="42;" alt="liliangrong777"/>
</a>
<a href="https://github.com/onewesong" title="onewesong">
<img src="https://avatars.githubusercontent.com/u/17920822?v=4" width="42;" alt="onewesong"/>
</a>
<a href="https://github.com/ryanhex53" title="ryanhex53">
<img src="https://avatars.githubusercontent.com/u/360426?v=4" width="42;" alt="ryanhex53"/>
</a>
<a href="https://github.com/zxx-457" title="zxx-457">
<img src="https://avatars.githubusercontent.com/u/114141362?v=4" width="42;" alt="zxx-457"/>
</a><!--GAMFC-END-->
上图贡献者列表,由 [contributors](https://github.com/jaywcjlove/github-action-contributors) 自动生成贡献者图片。
## License
MIT © [Kenny Wong](https://github.com/jaywcjlove)

View File

@ -23,6 +23,7 @@ Quick Reference
[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-->
[LaTeX](./docs/latex.md)<!--rehype:style=background: rgb(0 128 128/var(\-\-bg\-opacity));&class=contributing-->
[MATLAB](./docs/matlab.md)<!--rehype:style=background: rgb(0 118 168/var(\-\-bg\-opacity));&class=contributing-->
[Vue 3 ](./docs/vue.md)<!--rehype:style=background: rgb(64 184 131/var(\-\-bg\-opacity));&class=contributing-->
<!--rehype:class=home-card-->
@ -31,6 +32,7 @@ Quick Reference
[Bash](./docs/bash.md)<!--rehype:style=background: rgb(72 143 223/var(\-\-bg\-opacity));-->
[C](./docs/c.md)<!--rehype:style=background: rgb(92 107 192/var(\-\-bg\-opacity));-->
[Dart](./docs/dart.md)<!--rehype:style=background: rgb(64 196 255/var(\-\-bg\-opacity));-->
[Docker](./docs/docker.md)<!--rehype:style=background: rgb(72 143 223/var(\-\-bg\-opacity));-->
[Dockerfile](./docs/dockerfile.md)<!--rehype:style=background: rgb(0 72 153/var(\-\-bg\-opacity));&class=tag&data-lang=Docker-->
[Django](./docs/djiango.md)<!--rehype:style=background: rgb(12 75 51/var(\-\-bg\-opacity));&class=contributing tag&data-lang=Python-->
@ -39,12 +41,14 @@ Quick Reference
[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=👆看看还缺点儿什么?-->
[LaTeX](./docs/latex.md)<!--rehype:style=background: rgb(0 128 128/var(\-\-bg\-opacity));&class=contributing-->
[Markdown](./docs/markdown.md)<!--rehype:style=background: rgb(103 61 156/var(\-\-bg\-opacity));-->
[MySQL](./docs/mysql.md)<!--rehype:style=background: rgb(103 61 156/var(\-\-bg\-opacity));&class=tag&data-lang=SQL-->
[MySQL](./docs/mysql.md)<!--rehype:style=background: rgb(1 117 143/var(\-\-bg\-opacity));&class=tag&data-lang=SQL-->
[MATLAB](./docs/matlab.md)<!--rehype:style=background: rgb(0 118 168/var(\-\-bg\-opacity));&class=contributing-->
[Python](./docs/python.md)<!--rehype:style=background: rgb(240 81 57/var(\-\-bg\-opacity));-->
[PHP](./docs/php.md)<!--rehype:style=background: rgb(79 91 147/var(\-\-bg\-opacity));-->
[Python](./docs/python.md)<!--rehype:style=background: rgb(43 91 132/var(\-\-bg\-opacity));-->
[PostgreSQL](./docs/postgres.md)<!--rehype:style=background: rgb(43 109 163/var(\-\-bg\-opacity));&class=tag&data-lang=SQL-->
[Ruby](./docs/ruby.md)<!--rehype:style=background: rgb(71 71 71/var(\-\-bg\-opacity));-->
[Ruby](./docs/ruby.md)<!--rehype:style=background: rgb(204 52 45/var(\-\-bg\-opacity));-->
[Rust](./docs/rust.md)<!--rehype:style=background: rgb(71 71 71/var(\-\-bg\-opacity));-->
[Swift](./docs/swift.md)<!--rehype:style=background: rgb(240 81 57/var(\-\-bg\-opacity));-->
[SwiftUI](./docs/swiftui.md)<!--rehype:style=background: rgb(10 127 247/var(\-\-bg\-opacity));&class=tag&data-lang=swift-->
@ -147,17 +151,50 @@ Quick Reference
[`我有一张备忘单(速查表)`](https://github.com/jaywcjlove/reference/blob/main/CONTRIBUTING.md)<!--rehype:class=home-button text-grey&target=__blank-->
<!--rehype:style=margin-top:3rem-->
<!--rehype:ignore:start-->
## 贡献
## 感谢所有贡献者
<!--rehype:wrap-style=text-align: center;max-width: 650px;margin: 0 auto;&class=home-title-reset-->
请参阅[贡献指南](./CONTRIBUTING.md)了解如何开始。一如既往,感谢我们出色的贡献者!
请参阅 [Quick Reference](./docs/quickreference.md) 了解如何开始。一如既往,感谢我们出色的贡献者!
<!--rehype:style=padding-bottom:1rem;-->
<a href="https://github.com/jaywcjlove/reference/graphs/contributors">
<img src="https://jaywcjlove.github.io/reference/CONTRIBUTORS.svg" />
<!--GAMFC--><a href="https://github.com/jaywcjlove" title="小弟调调™">
<img src="https://avatars.githubusercontent.com/u/1680273?v=4" width="42;" alt="小弟调调™"/>
</a>
<a href="https://github.com/Jack-Zhang-1314" title="fw_qaq">
<img src="https://avatars.githubusercontent.com/u/82551626?v=4" width="42;" alt="fw_qaq"/>
</a>
<a href="https://github.com/catcto" title="喵仙人">
<img src="https://avatars.githubusercontent.com/u/5467932?v=4" width="42;" alt="喵仙人"/>
</a>
<a href="https://github.com/demigodliu" title="DemigodLiu">
<img src="https://avatars.githubusercontent.com/u/30372735?v=4" width="42;" alt="DemigodLiu"/>
</a>
<a href="https://github.com/JetSquirrel" title="JetSquirrel">
<img src="https://avatars.githubusercontent.com/u/20291255?v=4" width="42;" alt="JetSquirrel"/>
</a>
<a href="https://github.com/gaoxiaoduan" title="coderduan">
<img src="https://avatars.githubusercontent.com/u/69953511?v=4" width="42;" alt="coderduan"/>
</a>
<a href="https://github.com/hweining" title="hweining">
<img src="https://avatars.githubusercontent.com/u/8973985?v=4" width="42;" alt="hweining"/>
</a>
<a href="https://github.com/liliangrong777" title="liliangrong777">
<img src="https://avatars.githubusercontent.com/u/58727146?v=4" width="42;" alt="liliangrong777"/>
</a>
<a href="https://github.com/onewesong" title="onewesong">
<img src="https://avatars.githubusercontent.com/u/17920822?v=4" width="42;" alt="onewesong"/>
</a>
<a href="https://github.com/ryanhex53" title="ryanhex53">
<img src="https://avatars.githubusercontent.com/u/360426?v=4" width="42;" alt="ryanhex53"/>
</a>
<a href="https://github.com/zxx-457" title="zxx-457">
<img src="https://avatars.githubusercontent.com/u/114141362?v=4" width="42;" alt="zxx-457"/>
</a><!--GAMFC-END-->
上图贡献者列表,由 [contributors](https://github.com/jaywcjlove/github-action-contributors) 自动生成贡献者图片。
贡献者列表,由 [contributors](https://github.com/jaywcjlove/github-action-contributors) 自动生成
<!--rehype:style=padding-top:1rem;-->
<!--rehype:ignore:start-->
## License
MIT © [Kenny Wong](https://github.com/jaywcjlove)

View File

@ -92,8 +92,9 @@ Min Hour Day Mon Weekday
`问号(?)` | 可以代替“*”并允许用于月份和星期几。使用仅限于 cron 表达式中的 `月份中的某天``星期几`
<!--rehype:className=show-header auto-wrap-->
## Also see
另见
----
* [Devhints](https://devhints.io/cron) _(devhints.io)_
* [Crontab Generator](https://crontab-generator.org/) _(crontab-generator.org)_
* [Crontab guru](https://crontab.guru/) _(crontab.guru)_
- [Devhints](https://devhints.io/cron) _(devhints.io)_
- [Crontab Generator](https://crontab-generator.org/) _(crontab-generator.org)_
- [Crontab guru](https://crontab.guru/) _(crontab.guru)_

View File

@ -250,10 +250,10 @@ p:first-child {
:- | :-
`div.classname` | 具有特定类名的 div
`div#idname` | 具有特定 ID 的 div
`div p` | div 中的段落
`div > p` | div 子节点中的所有 `P` 标签
`div + p` | div 之后的 `P` 标签
`div ~ p` | div 前面的 `P` 标签
`div p` | div 中的所有段落
`div > p` | 父元素是 div 的 `P` 标签
`div + p` | div 之后的第一个同级 `P` 标签
`div ~ p` | div 之后所有的同级 `P` 标签
另见: [相邻兄弟](https://developer.mozilla.org/zh-CN/docs/Web/CSS/Adjacent_sibling_combinator) / [通用兄弟](https://developer.mozilla.org/zh-CN/docs/Web/CSS/General_sibling_combinator) / [](https://developer.mozilla.org/zh-CN/docs/Web/CSS/Child_combinator) 选择器

598
docs/dart.md Normal file
View File

@ -0,0 +1,598 @@
Dart 备忘清单
===
包含最重要概念、功能、方法等的 [Dart](https://dart.dev/) 备忘单。初学者的完整快速参考
入门
-----
### 安装 Dart
<!--rehype:wrap-class=row-span-2-->
#### Windows
```bash
C:\> choco install dart-sdk # Windows
```
#### Linux
执行以下一次性设置
```bash
$ sudo apt-get update
$ sudo apt-get install apt-transport-https
$ wget -qO- https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmor -o /usr/share/keyrings/dart.gpg
$ echo 'deb [signed-by=/usr/share/keyrings/dart.gpg arch=amd64] https://storage.googleapis.com/download.dartlang.org/linux/debian stable main' | sudo tee /etc/apt/sources.list.d/dart_stable.list
```
安装 Dart SDK
```bash
$ sudo apt-get update
$ sudo apt-get install dart
```
#### Mac
```bash
$ brew tap dart-lang/dart
$ brew install dart
```
### hello.dart
```dart
// 应用执行开始的顶级函数
void main() {
print("Hello World!"); // 打印到控制台
}
```
每个应用程序都有一个 `main()` 函数
#### Windows
```bash
$ dart compile exe hellow.dart
$ time ./hello.exe
Hello World!
```
### 变量
```dart
int x = 2; // 显式键入
var p = 5; // 类型推断 - 具有类型推断的通用var
dynamic z = 8; // 变量可以采用任何类型
z = "cool"; // cool
// 如果您从不打算更改变量,请使用 final 或 const
// 像这样的东西:
final email = "temid@gmail.com";
// 与 var 相同,但不能重新分配
final String email = "temid@gmail.com";
// 你不能改变价值
const qty = 5; // 编译时常数
```
### 数据类型
<!--rehype:wrap-class=row-span-2-->
```dart
// 整数,范围 -2^63 到 2^63 - 1
int age = 20;
// 浮点数字
double height = 1.85;
// 您还可以将变量声明为 num
// x 可以同时具有 int 和 double 值
num x = 1;
num += 2.5;
print(num); // 打印: 3.5
String name = "Nicola";
bool isFavourite = true;
bool isLoaded = false;
```
### 注释
```dart
// 这是一条正常的单行注释
/// 这是一个文档注释,用于文档库,
/// 类及其成员。 IDE 和 dartdoc 等工具
/// doc 特别注释。
/* 也支持此类注释 */
```
### 字符串插值
```dart
// 可以对字符串类型使用单引号或双引号
var firstName = 'Nicola';
var lastName = "Tesla";
// 可以用 $ 将变量嵌入到字符串中
String fullName = "$firstName $lastName";
// 与 + 连接
var name = "Albert " + "Einstein";
String upperCase = '${firstName.toUpperCase()}';
print(upperCase); // 打印: NICOLA
```
<!--rehype:className=wrap-text -->
### 导入 Imports
```dart
// 导入核心库
import 'dart:math';
// 从外部包导入库
import 'package:test/test.dart';
// 导入文件
import 'path/to/my_other_file.dart';
```
操作符
-------
### 算术运算符
<!--rehype:wrap-class=row-span-2-->
```dart
print(2 + 3); // 打印: 5
print(2 - 3); // 打印: -1
print(2 * 3); // 打印: 6
print(5 / 2); // 打印: 2.5 - 结果是 double
print(5 ~/ 2); // 打印: 2 - 结果是n int
print(5 % 2); // 打印: 1 - 余
int a = 1, b;
```
----
```dart
// 增
b = ++a; // 前增量 - 在 b 获得其值之前增加 a
b = a++; // 后增量 - 在 b 获得它的值之后增加 a
// 递
b = --a; // 前减量 - 在 b 获得它的值之前减少 a
b = a--; // 后减量 - 在 b 获得它的值之后递减 a
```
### 逻辑运算符
<!--rehype:wrap-class=col-span-2-->
```dart
// !expr 反转表达式(将 false 更改为 true反之亦然
// || 逻辑或
// && 逻辑与
bool isOutOfStock = false;
int quantity = 3;
if (!isOutOfStock && (quantity == 2 || quantity == 3)) {
// ...Order the product...
}
```
### 等式和关系运算符
```dart
print(2 == 2); // 打印: true - 平等的
print(2 != 3); // 打印: true - 不相等
print(3 > 2); // 打印: true - 比...更棒
print(2 < 3); // 打印: true - 少于
print(3 >= 3); // 打印: true - 大于或等于
print(2 <= 3); // 打印: true - 小于或等于
```
控制流:条件
------
### if 和 else if
```dart
if(age < 18){
print("Teen");
} else if( age > 18 && age <60){
print("Adult");
} else {
print("Old");
}
```
### switch case
```dart
enum Pet {dog, cat}
Pet myPet = Pet.dog;
switch(myPet){
case Pet.dog:
print('My Pet is Dog.');
break;
case Pet.cat:
print('My Pet is Cat.');
break;
default:
print('I don\'t have a Pet');
}
// 打印: My Pet is Dog.
```
控制流:循环
-----
### while 循环
```dart
while (!dreamsAchieved) {
workHard();
}
```
循环迭代之前的 `while` 循环检查条件
### do-while 循环
```dart
do {
workHard();
} while (!dreamsAchieved);
```
`do-while` 循环在执行循环内的语句后验证条件
### for 循环
```dart
for(int i=0; i< 10; i++){
print(i);
}
var numbers = [1,2,3];
// 列表的 for-in 循环
for(var number in numbers){
print(number);
}
```
Collections
------------
### Lists
<!--rehype:wrap-class=col-span-2-->
```dart
// 有序的对象组
var list = [1, 2, 3];
print(list.length); //Print: 3
print(list[1]); //Print: 2
// 列表声明和初始化的其他方式
List<String> cities = <String>["New York", "Mumbai", "Tokyo"];
// 创建一个编译时常量的列表
const constantCities = const ["New York", "Mumbai", "Tokyo"];
```
### Maps
<!--rehype:wrap-class=row-span-2-->
```dart
// 映射是关联键和值的对象
var person = Map<String, String>();
// 要初始化地图,请执行以下操作:
person['firstName'] = 'Nicola';
person['lastName'] = 'Tesla';
print(person);
// 打印: {firstName:Nicola, lastName:Tesla}
print(person['lastName']);
// 打印: Tesla
var nobleGases = {
// Key: Value
2: 'helium',
10: 'neon',
18: 'argon',
};
```
### Sets
<!--rehype:wrap-class=col-span-2-->
```dart
// Dart 中的集合是唯一项的无序集合
var halogens = {'fluorine', 'chlorine', 'bromine', 'iodine', 'astatine'};
// 创建一个空集
var names = <String>{};
Set<String> names = {}; // 这也有效
//var names = {}; // 创建地图,而不是集合
```
函数
------
### 函数示例
```dart
// dart 中的函数是对象并且有一个类型
int add(int a, int b){
return a+b;
}
// 函数可以分配给变量
int sum = add(2,3); // 回报5
// 可以作为参数传递给其他函数
int totalSum = add(2, add(2,3)); // 返回7
```
### 箭头语法 (=>)
```dart
// 只包含一个表达式的函数,您可以使用简写语法
bool isFav(Product product) => favProductsList.contains(product);
```
<!--rehype:className=wrap-text-->
### Anonymous (lambda) functions
```dart
// 没有名字的小单行函数
int add(a,b) => a+b;
// lambda 函数大多作为参数传递给其他函数
const list = [
'apples', 'bananas', 'oranges'
];
list.forEach(
(item) =>
print('${list.indexOf(item)}: $item')
);
// 打印: 0: apples 1: bananas 2: oranges
```
<!--rehype:className=wrap-text-->
类和对象
----------
### 类 Class
```dart
class Cat {
String name;
// 方法
void voice(){
print("Meow");
}
}
```
### 对象 Object
```dart
// 类的实例
// 在 myCat 下面是 Cat 类的对象
void main(){
Cat myCat = Cat();
myCat.name = "Kitty";
myCat.voice(); // 打印: Meow
}
```
### 构造函数
```dart
class Cat {
String name;
Cat(this.name);
}
void main(){
Cat myCat = Cat("Kitty");
print(myCat.name); // 打印: Kitty
}
```
### 抽象类
```dart
// 抽象类——不能实例化的类
// 这个类被声明为抽象的,因此不能被实例化
abstract class AbstractContainer {
// 定义构造函数、字段、方法...
void updateChildren(); // 抽象方法
}
```
### Getters Setters
```dart
// 提供对对象属性的读写访问
class Cat {
String name;
// getter
String get catName {
return name;
}
// setter
void set catName(String name){
this.name = name;
}
}
```
隐式接口
------------
### 一个基本的界面
<!--rehype:wrap-class=col-span-2-->
```dart
// 一个人。隐式接口包含 greet()。
class Person {
// 在接口中,但仅在此库中可见。
final String _name;
// 不在接口中,因为这是一个构造函数。
Person(this._name);
// 在接口中
String greet(String who) => 'Hello, $who. I am $_name.';
}
// Person 接口的实现。
class Impostor implements Person {
String get _name => '';
String greet(String who) => 'Hi $who. Do you know who I am?';
}
String greetBob(Person person) => person.greet('Bob');
void main() {
print(greetBob(Person('Kathy')));
// 打印: Hello, Bob. I am Kathy.
print(greetBob(Impostor()));
// 打印: Hi Bob. Do you know who I am?
}
```
### 扩展类
```dart
class Phone {
void use(){
_call();
_sendMessage();
}
}
// 使用 extends 创建子类
class SmartPhone extends Phone {
void use(){
// 使用 super 来引用超类
super.use();
_takePhotos();
_playGames();
}
}
```
异常
-----
### Throw
```dart
// 抛出 throws 或引发 raises 和异常 exception
throw IntegerDivisionByZeroException();
// 你也可以抛出任意对象
throw "Product out of stock!";
```
### Catch
```dart
try {
int c = 3/0;
print(c);
} on IntegerDivisionByZeroException {
// 一个特定的异常
print('Can not divide integer by 0.')
} on Exception catch (e) {
// 任何其他异常情况
print('Unknown exception: $e');
} catch (e) {
// 没有指定类型,处理所有
print('Something really unknown: $e');
}
```
### Finally
```dart
// 确保某些代码无论是否抛出异常都能运行
try {
cookFood();
} catch (e) {
print('Error: $e'); // 先处理异常
} finally {
cleanKitchen(); // 然后清理
}
```
Futures
------------
### Async Await
```dart
// 异步函数:它们在设置可能耗时的操作后返回
// async 和 await 关键字支持异步编程
Future<String> login() {
String userName="Temidjoy";
return
Future.delayed(
Duration(seconds: 4), () => userName
);
}
// 异步
main() async {
print('Authenticating please wait...');
print(await userName());
}
```
各种各样的
------------
### Null 和 Null 感知
<!--rehype:wrap-class=col-span-2-->
```dart
int x; // 任何对象的初始值为 null
// ?? 空感知运算符
x ??=6; // ??= 赋值运算符,仅当变量当前为 null 时才为其赋值
print(x); // 打印: 6
x ??=3;
print(x); // 打印: 6 - 结果仍然是 6
print(null ?? 10); // 打印: 10。如果不为空则显示左侧的值否则返回右侧的值
```
### 三元运算符
```dart
// 条件 ? 条件如果为真 : 条件如果为假
bool isAvailable;
isAvailable ? orderproduct() : addToFavourite();
```
<!--rehype:className=wrap-text-->
### 条件属性访问
<!--rehype:wrap-class=col-span-2-->
```dart
userObject?.userName
// 上面的代码片段等效于以下代码:
(userObject != null) ? userObject.userName : null
// 您可以将 ? 的多种用途链接起来。一起在一个表达式中
userObject?.userName?.toString()
// 如果 userObject 或 userObject.userName 为 null则前面的代码返回 null 并且从不调用 toString()
```
### 级联符号 (..)
<!--rehype:wrap-class=row-span-2-->
```dart
// 允许您对同一对象进行一系列操作
// 而不是这样做
var user = User();
user.name = "Nicola";
user.email = "nicola@g.c";
user.age = 24;
// 你可以这样做
var user = User()
..name = "Nicola"
..email = "nicola@g.c"
..age = 24;
```
### 扩展运算符 (...)
```dart
// 将多个值插入到集合中
var list = [1, 2, 3];
var list2 = [0, ...list];
print(list2.length); // 打印: 4
```
另见
----
- [Dart 官方文档](https://dart.dev/) _(dart.dev)_

View File

@ -121,33 +121,17 @@ $ ffmpeg -i movie.webm movie.mp4
---
<!--rehype:body-class=cols-2-->
###
<!--rehype:wrap-class=row-span-2-->
### 剪切视频部分
<!--rehype:wrap-class=col-span-2-->
```bash
$ ffmpeg -i <input> -filter:v "crop=640:480:100:25" <output>
```
<!--rehype:className=wrap-text -->
通过从输入视频中复制偏移 `x=100px` `y=25px` 的相应窗口来创建 `640x480` 大小的输出视频
```bash
# 裁剪到宽度 360高度 640
$ ffmpeg -i input.mov -filter:v 'crop=360:640:0:0' -codec:a copy output.mov
```
<!--rehype:className=wrap-text -->
裁剪到宽度 360高度 640从坐标 (10, 20) 开始
```bash
$ ffmpeg -i input.mov -filter:v 'crop=360:640:10:20' -codec:a copy output.mov
```
<!--rehype:className=wrap-text -->
### 缩放
```bash
$ ffmpeg -i <输入> -vf scale=640:480 <输出>
# 从1分45秒开始剪切2分35秒
$ ffmpeg -i <input> -ss 00:01:45 -t 00:02:35 -vcodec copy -acodec copy <output>
# 从1分45秒开始剪切到第4分20秒与上一行等效
$ ffmpeg -i <input> -ss 00:01:45 -to 00:04:20 -codec copy <output>
$ ffmpeg -ss 00:00:30 -i orginalfile.mpg -t 00:00:05 -vcodec copy -acodec copy newfile.mpg
# 从 4.5 秒开始的 5 秒长的视频
$ ffmpeg -i in.mp4 -ss 4.5 -t 5 out.mp4
```
<!--rehype:className=wrap-text -->
@ -165,20 +149,6 @@ $ ffmpeg -r 1 -i input.m2v -r 24 output.avi
将输入文件的帧速率(仅对原始格式有效)强制为 1 fps将输出文件的帧速率强制为 24 fps
### 剪切视频部分
<!--rehype:wrap-class=col-span-2-->
```bash
# 从1分45秒开始剪切2分35秒
$ ffmpeg -i <input> -ss 00:01:45 -t 00:02:35 -vcodec copy -acodec copy <output>
# 从1分45秒开始剪切到第4分20秒与上一行等效
$ ffmpeg -i <input> -ss 00:01:45 -to 00:04:20 -codec copy <output>
$ ffmpeg -ss 00:00:30 -i orginalfile.mpg -t 00:00:05 -vcodec copy -acodec copy newfile.mpg
# 从 4.5 秒开始的 5 秒长的视频
$ ffmpeg -i in.mp4 -ss 4.5 -t 5 out.mp4
```
<!--rehype:className=wrap-text -->
### H265 2-pass 编码
<!--rehype:wrap-class=row-span-2-->
@ -212,14 +182,6 @@ $ ffmpeg -i <input> -c copy -metadata:s:v:0 rotate=90 <output>
不要为旋转重新编码,而是简单地为旋转角度添加一个视频元数据字段
### 放慢视频速度
```bash
$ ffmpeg -i in.mp4 -filter:v "setpts=4.0*PTS" out.mp4
```
使用过滤器减慢视频。 此示例将视频减慢四倍
### 缩放到特定宽度
```bash
@ -240,23 +202,6 @@ $ ffmpeg -i file.mp4 -vn -c copy output.aac
`-vn` (过滤视频),使用 `-c 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 -->
### 提取视频流
```bash
@ -289,6 +234,13 @@ $ ffmpeg -i file.aac -acodec mp3 -ar 44100 -ab 128000 output.mp3
```
<!--rehype:className=wrap-text -->
### 将输入文件转码为 DVD PAL 格式
```bash
$ ffmpeg -y -threads 8 -i inFile -target pal-dvd -ac 2 -aspect 16:9 -acodec mp2 -ab 224000 -vf pad=0:­0:0:0 outFile
```
<!--rehype:className=wrap-text -->
### -map 命令
<!--rehype:wrap-class=col-span-2 row-span-2-->
@ -399,10 +351,19 @@ $ ffmpeg -hide_banner -loglevel error -stats -f gdigrab -framerate 60 \
$ ffmpeg -f avfoundation -i 1:0 -preset ultrafast out.mkv
```
### 将输入文件转码为 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
# 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 -->
@ -569,7 +530,7 @@ $ ffmpeg -i audioS.mp4 -i videoS.mp4 -c copy -map 0:a -map 1:v outFil­e.mp4
### 合并视频
<!--rehype:wrap-class=col-span-2 row-span-3-->
<!--rehype:wrap-class=col-span-3 row-span-3-->
合并相同规格(解码/分辨率/帧率)视频
@ -618,29 +579,44 @@ $ ffmpeg -f concat -i mylist.txt -c:v copy -c:a flac -strict -2 output.mp4
```
<!--rehype:className=wrap-text -->
### 合并音频与图片
视频过滤器
---
合并多个音频,自定义背景图片,生成视频音乐
### 格式
如果一个 fliter 有多个参数,需要使用 `,` 分隔
```bash
# mylist.txt >>>
file '1.mp3'
file '2.mp3'
file '3.mp3'
$ ffmpeg -i test.avi -c:v libx264 -vf "scale=1024:-1,transpose=1,crop=iw/3:ih/3" output.mp4
```
# 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:wrap-class=row-span-2-->
```bash
$ ffmpeg -i input.mp4 -vf "scale=640:480" out.mp4
# -1 → 指根据另一个参数帮我们推断
$ ffmpeg -i input.mp4 -vf "scale=720:-1" out.mp4
# 宽度和高度
ffmpeg -i input.mp4 -vf "scale=w=800:h=600" output.mp4
# in_w\in_h 输入尺寸
ffmpeg -i input.mkv -vf "scale=w=1/2*in_w:h=1/2*in_h" output.mkv
```
<!--rehype:className=wrap-text -->
### 添加水印
### 裁剪
<!--rehype:wrap-class=row-span-2-->
在视频左上方 20,20 的位置插入 logo.png 图片
从左上角开始,复制 `x=0px` `y=0px` 的相应窗口来创建 `1280x720` 大小的输出视频
```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
ffmpeg -i input.mp4 -vf "crop=w=1280:h=720:x=0:y=0" output.mp4
```
裁剪到宽度 360高度 640从坐标 (10, 20) 开始
```bash
$ ffmpeg -i input.mov -vf 'crop=360:640:10:20' output.mov
```
<!--rehype:className=wrap-text -->
@ -654,6 +630,94 @@ ffmpeg -i 1.mp4 -b:v 548k -vf delogo=x=10:y=10:w=120:h=45:show=1 output.mp4
```
<!--rehype:className=wrap-text -->
### 创建缩略图
<!--rehype:wrap-class=row-span-2-->
在 10 秒时创建一个缩略图
```bash
$ ffmpeg -ss 10 -i <input file> -vframes 1 -vcodec png -an thumb.png
```
<!--rehype:className=wrap-text -->
例如,要每 `n` 秒创建一次缩略图,请使用 `-vf fps=1/n`
```bash
$ ffmpeg -i <input file> -vf fps=1/60 thumbnails/thumb%03d.png
```
<!--rehype:className=wrap-text -->
### 添加水印
在视频左上方 20,20 的位置插入 logo.png 图片
```bash
# -b:v 548k 可选参数,设置视频比特率,默认 200k 最好设置与原视频一致
ffmpeg -i 1.mp4 -acodec copy -b:v 548k -vf "movie=logo.png[watermark];[in][watermark]overlay=20:20" output.mp4
```
<!--rehype:className=wrap-text -->
### 视频旋转
```bash
# 顺时针旋转 90
$ ffmpeg -i input.avi -vf "rotate=90*PI/180" out.mp4
# 顺时针旋转 180翻转 90
$ ffmpeg -i input.mp4 -vf "rotate=PI" out.mp4
```
### 更改视频播放速度
```bash
# 加速 2 倍
$ ffmpeg -i input.mkv -vf "setpts=0.5*PTS" output.mkv
# 减速 2 倍
$ ffmpeg -i input.mp4 -vf "setpts=2*PTS" output.mp4
```
### 添加背景音乐
```bash
# -t 10 文件时长,单位为秒,建议取值原始视频总时长
$ ffmpeg -i 1.mp4 -i test.mp3 \
-filter_complex "[1:a]aloop=loop=-1:size=2e+09[out];[out][0:a]amix" \
-t 10 out.mp4
```
音频过滤器
---
### 调节音量
```bash
# 增大音量
$ ffmpeg -i test.mp4 -af "volumn=1.5" out.mp4
```
### 更改音频速度
<!--rehype:wrap-class=row-span-2-->
```bash
$ ffmpeg -i input.wav -af "atempo=0.75" output.wav
# 加速 4 倍
$ ffmpeg -i input.mp3 -af "atempo=2.0,atempo=2.0" ouutput.mp3
```
`atempo` 它只接受 `0.5`(半速) 到 `2` (倍速)之间的值。为了越过这个限制,你可以链式使用这个过滤器
### 统一视频的音量
```bash
$ ffmpeg -i test.mp4 -af "loudnorm=I=-5:LRA=1" out.mp4
```
### 重新映射通道数
```bash
# 使左右耳的声音同时出现
$ ffmpeg -i input.mp3 -af "channelmap=1-0|1-1" output.mp3
```
另见
---

421
docs/latex.md Normal file
View File

@ -0,0 +1,421 @@
LaTeX 备忘清单
===
本备忘单总结了 [LaTeX](https://www.latex-project.org/) 常用显示数学符号的参考列表和一些 [KaTeX](https://katex.org/) 的应用示例。
入门
---
### 介绍
[LaTeX](https://www.latex-project.org/) 基于 TEX 的排版系统,适用于生成高印刷质量的科技和数学、物理文档。
- [LaTeX 官网](https://www.latex-project.org/) _(latex-project.org)_
- [KaTeX 官网](https://katex.org/) _(katex.org)_
而 [KaTeX](https://katex.org/) 只处理 LaTeX 的数学符号的一个更小的子集,用于 web 上展示
### 示例
```KaTeX
% \f is defined as #1f(#2) using the macro
f\relax(x) = \int_{-\infty}^\infty
f\hat\xi\,e^{2 \pi i \xi x}
\,d\xi
```
---
```LaTeX
% \f is defined as #1f(#2) using the macro
f\relax(x) = \int_{-\infty}^\infty
f\hat\xi\,e^{2 \pi i \xi x}
\,d\xi
```
### 行内展示
```markdown
基于 KaTeX 在一行
展示示例: `KaTeX:\int_0^\infty x^2 dx`
```
基于 KaTeX 在一行展示示例: `KaTeX:\int_0^\infty x^2 dx`
Supported Functions
---
### Accents
<!--rehype:wrap-class=col-span-2 row-span-2-->
:- | :- | :-
:- | :- | :-
`KaTeX:a'` <pur>`a'`</pur> | `KaTeX:\tilde{a}` <pur>`\tilde{a}`</pur> | `KaTeX:\mathring{g}` <pur>`\mathring{g}`</pur>
`KaTeX:a''` <pur>`a''`</pur> | `KaTeX:\widetilde{ac}` <pur>`\widetilde{ac}`</pur> | `KaTeX:\overgroup{AB}` <pur>`\overgroup{AB}`</pur>
`KaTeX:a^{\prime}` <pur>`a^{\prime}`</pur> | `KaTeX:\utilde{AB}` <pur>`\utilde{AB}`</pur> | `KaTeX:\undergroup{AB}` <pur>`\undergroup{AB}`</pur>
`KaTeX:\acute{a}` <pur>`\acute{a}`</pur> | `KaTeX:\vec{F}` <pur>`\vec{F}`</pur> | `KaTeX:\Overrightarrow{AB}` <pur>`\Overrightarrow{AB}`</pur>
`KaTeX:\bar{y}` <pur>`\bar{y}`</pur> | `KaTeX:\overleftarrow{AB}` <pur>`\overleftarrow{AB}`</pur> | `KaTeX:\overrightarrow{AB}` <pur>`\overrightarrow{AB}`</pur>
`KaTeX:\breve{a}` <pur>`\breve{a}`</pur> | `KaTeX:\underleftarrow{AB}` <pur>`\underleftarrow{AB}`</pur> | `KaTeX:\underrightarrow{AB}` <pur>`\underrightarrow{AB}`</pur>
`KaTeX:\check{a}` <pur>`\check{a}`</pur> | `KaTeX:\overleftharpoon{ac}` <pur>`\overleftharpoon{ac}`</pur> | `KaTeX:\overrightharpoon{ac}` <pur>`\overrightharpoon{ac}`</pur>
`KaTeX:\dot{a}` <pur>`\dot{a}`</pur> | `KaTeX:\overleftrightarrow{AB}` <pur>`\overleftrightarrow{AB}`</pur> | `KaTeX:\overbrace{AB}` <pur>`\overbrace{AB}`</pur>
`KaTeX:\ddot{a}` <pur>`\ddot{a}`</pur> | `KaTeX:\underleftrightarrow{AB}` <pur>`\underleftrightarrow{AB}`</pur> | `KaTeX:\underbrace{AB}` <pur>`\underbrace{AB}`</pur>
`KaTeX:\grave{a}` <pur>`\grave{a}`</pur> | `KaTeX:\overline{AB}` <pur>`\overline{AB}`</pur> | `KaTeX:\overlinesegment{AB}` <pur>`\overlinesegment{AB}`</pur>
`KaTeX:\hat{\theta}` <pur>`\hat{\theta}`</pur> | `KaTeX:\underline{AB}` <pur>`\underline{AB}`</pur> | `KaTeX:\underlinesegment{AB}` <pur>`\underlinesegment{AB}`</pur>
`KaTeX:\widehat{ac}` <pur>`\widehat{ac}`</pur> | `KaTeX:\widecheck{ac}` <pur>`\widecheck{ac}`</pur> | `KaTeX:\underbar{X}` <pur>`\underbar{X}`</pur>
### \text中的强调功能
:- | :- | :-
:- | :- | :-
`KaTeX:\'{a}` <pur>`\'{a}`</pur> | `KaTeX:\~{a}` <pur>`\~{a}`</pur> |
`KaTeX:\.{a}` <pur>`\.{a}`</pur> | `KaTeX:\H{a}` <pur>`\H{a}`</pur> |
``KaTeX:\\\`{a}`` <pur><code>\\&#96;{a}</code></pur> | `KaTeX:\={a}` <pur>`\={a}`</pur> |
`KaTeX:\"{a}` <pur>`\"{a}`</pur> | `KaTeX:\v{a}` <pur>`\v{a}`</pur> |
`KaTeX:\^{a}` <pur>`\^{a}`</pur> | `KaTeX:\u{a}` <pur>`\u{a}`</pur> |
`KaTeX:\r{a}` <pur>`\r{a}`</pur> |
### Delimiter Sizing
:- | :-
:- | :-
`KaTeX:\left(\LARGE{AB}\right)` | <pur>`\left(\LARGE{AB}\right)`</pur>
`KaTeX:( \big( \Big( \bigg( \Bigg(`| <pur>`( \big( \Big( \bigg( \Bigg(`</pur>
---
:- | :- | :- | :- | :-
:- | :- | :- | :- | :-
`\left` | `\big` | `\bigl` | `\bigm` | `\bigr`
`\middle` | `\Big` | `\Bigl` | `\Bigm` | `\Bigr`
`\right` | `\bigg` | `\biggl` | `\biggm` | `\biggr`
`` | `\Bigg` | `\Biggl` | `\Biggm` | `\Biggr`
### 分隔符 Delimiters
<!--rehype:wrap-class=col-span-3-->
预览 | 方法 | 预览 | 方法 | 预览 | 方法 | 预览| 方法 | 预览 | 方法
:- | :- | :- | :- | :- | :- | :- | :- | :- | :-
| `KaTeX:()` | <pur>`()`</pur> | `KaTeX:\lparen \rparen` | <pur>`\lparen` `\rparen`</pur> | `KaTex:⌈ ⌉` | <pur>`⌈ ⌉`</pur> | `KaTex:\lceil \rceil` | <pur>`\lceil` `\rceil`</pur> | `KaTex:\uparrow` | <pur>`\uparrow`</pur> |
| `KaTeX:[]` | <pur>`[]`</pur> | `KaTeX:\lbrack \rbrack` | <pur>`\lbrack` `\rbrack`</pur> | `KaTex:⌊ ⌋` | <pur>`⌊ ⌋`</pur> | `KaTex:\lfloor \rfloor` | <pur>`\lfloor` `\rfloor`</pur> | `KaTex:\downarrow` | <pur>`\downarrow`</pur> |
| `KaTeX:\{ \}` | <pur>`{}`</pur> | `KaTex:\lbrace \rbrace` | <pur>`\lbrace` `\rbrace`</pur> | `KaTex:⎰⎱` | <pur>`⎰⎱`</pur> | `KaTex:\lmoustache \rmoustache` | <pur>`\lmoustache` `\rmoustache`</pur> | `KaTex:\updownarrow` | <pur>`\updownarrow`</pur> |
| `KaTeX:⟨ ⟩` | <pur>`⟨⟩`</pur> | `KaTex:\langle \rangle` | <pur>`\langle` `\rangle`</pur> | `KaTex:⟮ ⟯` | <pur>`⟮ ⟯`</pur> | `KaTex:\lgroup \rgroup` | <pur>`\lgroup` `\rgroup`</pur> | `KaTex:\Uparrow` | <pur>`\Uparrow`</pur> |
| `KaTeX:` | <pur>`\|`</pur> | `KaTex:\vert` | <pur>`\vert`</pur> | `KaTex:┌ ┐` | <pur>`┌ ┐`</pur> | `KaTex:\ulcorner \urcorner` | <pur>`\ulcorner` `\urcorner`</pur> | `KaTex:\Downarrow` | <pur>`\Downarrow`</pur> |
| `KaTeX:\|` _(<red>MD语法冲突</red>)_ | <pur><code>\\&#124;</code></pur> | `KaTex:\Vert` | <pur>`\Vert`</pur> | `KaTex:└ ┘` | <pur>`└ ┘`</pur> | `KaTex:\llcorner \lrcorner` | <pur>`\llcorner` `\lrcorner`</pur> | `KaTex:\Updownarrow` | <pur>`\Updownarrow`</pur> |
| `KaTeX: ` | <pur>`\lvert` `\rvert`</pur> | `KaTex:\lVert \rVert` | <pur>`\lVert` `\rVert`</pur> | | <pur>`\left.`</pur> | | <pur>`\right.`</pur> | `KaTex:\backslash` | <pur>`\backslash`</pur> |
| `KaTeX:\lang` `KaTeX:\rang` | <pur>`\lang` `\rang`<pur> | `KaTeX:\lt \gt` | <pur>`\lt \gt`</pur> | `KaTex:⟦ ⟧` | <pur>`⟦ ⟧`</pur> | `KaTex:\llbracket \rrbracket` | <pur>`\llbracket` `\rrbracket`</pur> | `KaTex:\lBrace \rBrace` | <pur>`\lBrace \rBrace`</pur> |
<!--rehype:className=show-header left-align-->
Environments
---
### Environments 1
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
```KaTeX
\begin{matrix}
a & b \\
c & d
\end{matrix}
```
```LaTeX
\begin{matrix}
a & b \\
c & d
\end{matrix}
```
### Environments 2
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
```KaTeX
\begin{array}{cc}
a & b \\
c & d
\end{array}
```
```LaTeX
\begin{array}{cc}
a & b \\
c & d
\end{array}
```
### Environments 3
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
```KaTeX
\begin{pmatrix}
a & b \\
c & d
\end{pmatrix}
```
```LaTeX
\begin{pmatrix}
a & b \\
c & d
\end{pmatrix}
```
### Environments 4
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
```KaTeX
\begin{bmatrix}
a & b \\
c & d
\end{bmatrix}
```
```LaTeX
\begin{bmatrix}
a & b \\
c & d
\end{bmatrix}
```
### Environments 5
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
```KaTeX
\begin{vmatrix}
a & b \\
c & d
\end{vmatrix}
```
```LaTeX
\begin{vmatrix}
a & b \\
c & d
\end{vmatrix}
```
### Environments 6
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
```KaTeX
\begin{Vmatrix}
a & b \\
c & d
\end{Vmatrix}
```
```LaTeX
\begin{Vmatrix}
a & b \\
c & d
\end{Vmatrix}
```
### Environments 7
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
```KaTeX
\begin{Bmatrix}
a & b \\
c & d
\end{Bmatrix}
```
```LaTeX
\begin{Bmatrix}
a & b \\
c & d
\end{Bmatrix}
```
### Environments 8
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
```KaTeX
\def\arraystretch{1.5}
\begin{array}{c:c:c}
a & b & c \\ \hline
d & e & f \\
\hdashline
g & h & i
\end{array}
```
```LaTeX
\def\arraystretch{1.5}
\begin{array}{c:c:c}
a & b & c \\ \hline
d & e & f \\
\hdashline
g & h & i
\end{array}
```
### Environments 9
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
```KaTeX
x = \begin{cases}
a &\text{if } b \\
c &\text{if } d
\end{cases}
```
```LaTeX
x = \begin{cases}
a &\text{if } b \\
c &\text{if } d
\end{cases}
```
### Environments 10
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
```KaTeX
\begin{rcases}
a &\text{if } b \\
c &\text{if } d
\end{rcases}⇒…
```
```LaTeX
\begin{rcases}
a &\text{if } b \\
c &\text{if } d
\end{rcases}⇒…
```
### Environments 11
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
```KaTeX
\begin{smallmatrix}
a & b \\
c & d
\end{smallmatrix}
```
```LaTeX
\begin{smallmatrix}
a & b \\
c & d
\end{smallmatrix}
```
### Environments 12
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
```KaTeX
\sum_{
\begin{subarray}{l}
i\in\Lambda\\
0<j<n
\end{subarray}}
```
```LaTeX
\sum_{
\begin{subarray}{l}
i\in\Lambda\\
0<j<n
\end{subarray}}
```
### Environments 12
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
```KaTeX
\begin{equation}
\begin{split} a &=b+c\\
&=e+f
\end{split}
\end{equation}
```
<!--rehype:style=flex:1;-->
```LaTeX
\begin{equation}
\begin{split} a &=b+c\\
&=e+f
\end{split}
\end{equation}
```
### Environments 12
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
```KaTeX
\begin{align}
a&=b+c \\
d+e&=f
\end{align}
```
<!--rehype:style=flex:1;-->
```LaTeX
\begin{align}
a&=b+c \\
d+e&=f
\end{align}
```
### Environments 12
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
```KaTeX
\begin{gather}
a=b \\
e=b+c
\end{gather}
```
<!--rehype:style=flex:1;-->
```LaTeX
\begin{gather}
a=b \\
e=b+c
\end{gather}
```
### Environments 12
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
```KaTeX
\begin{alignat}{2}
10&x+&3&y=2\\
3&x+&13&y=4
\end{alignat}
```
<!--rehype:style=flex:1;-->
```LaTeX
\begin{alignat}{2}
10&x+&3&y=2\\
3&x+&13&y=4
\end{alignat}
```
### Environments 12
<!--rehype:body-style=display: flex;flex-direction: row;justify-content: flex-start;-->
```KaTeX
\begin{CD}
A @>a>> B \\
@VbVV @AAcA \\
C @= D
\end{CD}
```
<!--rehype:style=flex:1;-->
```LaTeX
\begin{CD}
A @>a>> B \\
@VbVV @AAcA \\
C @= D
\end{CD}
```
另见
----
- [LaTeX 官网](https://www.latex-project.org/) _(latex-project.org)_
- [KaTeX 官网](https://katex.org/) _(katex.org)_

972
docs/php.md Normal file
View File

@ -0,0 +1,972 @@
PHP 备忘清单
===
这份 [PHP](https://www.php.net/manual/zh/index.php) 备忘单为快速查找最常用代码的正确语法提供了参考
入门
------
### hello.php
```php
<?php // 以 PHP 开放标签开头
echo "Hello World\n";
print("Hello quickref.me");
?>
```
PHP 运行命令
```shell
$ php hello.php
```
### 变量 Variables
```php
$boolean1 = true;
$boolean2 = True;
$int = 12;
$float = 3.1415926;
unset($float); // 删除变量
$str1 = "How are you?";
$str2 = 'Fine, thanks';
```
查看: [Types](#php-类型)
### 字符串 Strings
```php
$url = "quickref.me";
echo "I'm learning PHP at $url";
// 连接字符串
echo "I'm learning PHP at " . $url;
$hello = "Hello, ";
$hello .= "World!";
echo $hello; # => Hello, World!
```
查看: [Strings](#php-字符串)
### 数组 Arrays
```php
$num = [1, 3, 5, 7, 9];
$num[5] = 11;
unset($num[2]); // 删除变量
print_r($num); # => 1 3 7 9 11
echo count($num); # => 5
```
查看: [Arrays](#php-数组)
### 运算符 Operators
```php
$x = 1;
$y = 2;
$sum = $x + $y;
echo $sum; # => 3
```
查看: [Operators](#php-运算符)
### Include
<!--rehype:wrap-class=row-span-3-->
#### vars.php
```php
<?php // 以 PHP 开放标签开头。
$fruit = 'apple';
echo "I was imported";
return 'Anything you like.';
?>
```
#### test.php
```php
<?php
include 'vars.php';
echo $fruit . "\n"; # => apple
/* 与 include 相同,
如果不能包含则导致错误*/
require 'vars.php';
// 也有效
include('vars.php');
require('vars.php');
// 通过 HTTP 包含
include 'http://x.com/file.php';
// 包含和返回语句
$result = include 'vars.php';
echo $result; # => Anything you like.
?>
```
### 功能 Functions
```php
function add($num1, $num2 = 1) {
return $num1 + $num2;
}
echo add(10); # => 11
echo add(10, 5); # => 15
```
查看: [Functions](#php-函数)
### 注释 Comments
```php
# 这是一个单行 shell 样式的注释
// 这是一行 c++ 风格的注释
/* 这是一个多行注释
另一行注释 */
```
### 常数 Constants
```php
const MY_CONST = "hello";
echo MY_CONST; # => hello
# => MY_CONST is: hello
echo 'MY_CONST is: ' . MY_CONST;
```
### 类 Classes
```php
class Student {
public function __construct($name) {
$this->name = $name;
}
}
$alex = new Student("Alex");
```
查看: [Classes](#php-类)
PHP 类型
------
### 布尔值 Boolean
<!--rehype:wrap-class=row-span-2-->
```php
$boolean1 = true;
$boolean2 = TRUE;
$boolean3 = false;
$boolean4 = FALSE;
$boolean5 = (boolean) 1; # => true
$boolean6 = (boolean) 0; # => false
```
布尔值不区分大小写
### 整数 Integer
<!--rehype:wrap-class=row-span-2-->
```php
$int1 = 28; # => 28
$int2 = -32; # => -32
$int3 = 012; # => 10 (octal)
$int4 = 0x0F; # => 15 (hex)
$int5 = 0b101; # => 5 (binary)
# => 2000100000 (decimal, PHP 7.4.0)
$int6 = 2_000_100_000;
```
另见: [Integers](https://www.php.net/manual/en/language.types.integer.php)
### 字符串 Strings
```php
echo 'this is a simple string';
```
查看: [Strings](#php-字符串)
### 数组 Arrays
```php
$arr = array("hello", "world", "!");
```
查看: [Arrays](#php-数组)
### 浮点数 Float (Double)
```php
$float1 = 1.234;
$float2 = 1.2e7;
$float3 = 7E-10;
$float4 = 1_234.567; // as of PHP 7.4.0
var_dump($float4); // float(1234.567)
$float5 = 1 + "10.5"; # => 11.5
$float6 = 1 + "-1.3e3"; # => -1299
```
### Null
```php
$a = null;
$b = 'Hello php!';
echo $a ?? 'a is unset'; # => a is unset
echo $b ?? 'b is unset'; # => Hello php
$a = array();
$a == null # => true
$a === null # => false
is_null($a) # => false
```
### 可迭代对象 Iterables
```php
function bar(): iterable {
return [1, 2, 3];
}
function gen(): iterable {
yield 1;
yield 2;
yield 3;
}
foreach (bar() as $value) {
echo $value; # => 123
}
```
PHP 字符串
------
### 字符串 String
```php
# => '$String'
$sgl_quotes = '$String';
# => 'This is a $String.'
$dbl_quotes = "This is a $sgl_quotes.";
# => a tab character.
$escaped = "a \t tab character.";
# => a slash and a t: \t
$unescaped = 'a slash and a t: \t';
```
### 多行 Multi-line
```php
$str = "foo";
// 未插值的多行
$nowdoc = <<<'END'
Multi line string
$str
END;
// 将执行字符串插值
$heredoc = <<<END
Multi line
$str
END;
```
### 操作 Manipulation
```php
$s = "Hello Phper";
echo strlen($s); # => 11
echo substr($s, 0, 3); # => Hel
echo substr($s, 1); # => ello Phper
echo substr($s, -4, 3);# => hpe
echo strtoupper($s); # => HELLO PHPER
echo strtolower($s); # => hello phper
echo strpos($s, "l"); # => 2
var_dump(strpos($s, "L")); # => false
```
另见: [字符串函数](https://www.php.net/manual/en/ref.strings.php)
PHP 数组
------
### 定义
<!--rehype:wrap-class=row-span-2-->
```php
$a1 = ["hello", "world", "!"]
$a2 = array("hello", "world", "!");
$a3 = explode(",", "apple,pear,peach");
```
#### 混合 int 和 string 键
```php
$array = array(
"foo" => "bar",
"bar" => "foo",
100 => -100,
-100 => 100,
);
var_dump($array);
```
#### 短数组语法
```php
$array = [
"foo" => "bar",
"bar" => "foo",
];
```
### 多阵列
```php
$multiArray = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
];
print_r($multiArray[0][0]) # => 1
print_r($multiArray[0][1]) # => 2
print_r($multiArray[0][2]) # => 3
```
### 多类型
<!--rehype:wrap-class=row-span-2-->
```php
$array = array(
"foo" => "bar",
42 => 24,
"multi" => array(
"dim" => array(
"a" => "foo"
)
)
);
# => string(3) "bar"
var_dump($array["foo"]);
# => int(24)
var_dump($array[42]);
# => string(3) "foo"
var_dump($array["multi"]["dim"]["a"]);
```
### 操作
```php
$arr = array(5 => 1, 12 => 2);
$arr[] = 56; // 附加
$arr["x"] = 42; // 用键添加
sort($arr); // 排序
unset($arr[5]); // 消除
unset($arr); // 移除所有
```
查看: [数组函数](https://www.php.net/manual/en/ref.array.php)
### 索引迭代
```php
$array = array('a', 'b', 'c');
$count = count($array);
for ($i = 0; $i < $count; $i++) {
echo "i:{$i}, v:{$array[$i]}\n";
}
```
### 价值迭代
```php
$colors = array('red', 'blue', 'green');
foreach ($colors as $color) {
echo "Do you like $color?\n";
}
```
### 关键迭代
```php
$arr = ["foo" => "bar", "bar" => "foo"];
foreach ( $arr as $key => $value )
{
echo "key: " . $key . "\n";
echo "val: {$arr[$key]}\n";
}
```
### 串联阵列
```php
$a = [1, 2];
$b = [3, 4];
// PHP 7.4 以后
# => [1, 2, 3, 4]
$result = [...$a, ...$b];
```
### Into 函数
```php
$array = [1, 2];
function foo(int $a, int $b) {
echo $a; # => 1
echo $b; # => 2
}
foo(...$array);
```
### Splat运算符
```php
function foo($first, ...$other) {
var_dump($first); # => a
var_dump($other); # => ['b', 'c']
}
foo('a', 'b', 'c' /*, ...*/ );
// 或
function foo($first, string ...$other){}
```
PHP 运算符
-------
### 算术
:- | -
:- | -
`+` | 添加
`-` | 减法
`*` | 乘法
`/` | 分配
`%` | 取模
`**` | 求幂
### 分配
:- | -
:- | -
`a += b` | 如同 `a = a + b`
`a -= b` | 如同 `a = a b`
`a *= b` | 如同 `a = a * b`
`a /= b` | 如同 `a = a / b`
`a %= b` | 如同 `a = a % b`
### 比较
:- | -
:- | -
`==` | 平等的
`===` | 完全相同的
`!=` | 不相等
`<>` | 不相等
`!==` | 不相同
`<` | 少于
`>` | 比...更棒
`<=` | 小于或等于
`>=` | 大于或等于
`<=>` | 小于/等于/大于
### 逻辑的
:- | -
:- | -
`and` | 和
`or` | 或者
`xor` | 独家或
`!` | 不是
`&&` | 和
`\|\|` | 或者
### 算术
```php
// 算术
$sum = 1 + 1; // 2
$difference = 2 - 1; // 1
$product = 2 * 2; // 4
$quotient = 2 / 1; // 2
// 速记算术
$num = 0;
$num += 1; // 将 $num 增加 1
echo $num++; // 打印 1评估后的增量
echo ++$num; // 打印 3评估前的增量
$num /= $float; // 将商除并分配给 $num
```
### 按位
:- | -
:- | -
`&` | 和
`|` | 或(包括或)
`^` | 异或(异或)
`~` | 不是
`<<` | 左移
`>>` | 右移
PHP 条件
------
### If elseif else
```php
$a = 10;
$b = 20;
if ($a > $b) {
echo "a is bigger than b";
} elseif ($a == $b) {
echo "a is equal to b";
} else {
echo "a is smaller than b";
}
```
### Switch
```php
$x = 0;
switch ($x) {
case '0':
print "it's zero";
break;
case 'two':
case 'three':
// do something
break;
default:
// do something
}
```
### 三元运算符
```php
# => Does
print (false ? 'Not' : 'Does');
$x = false;
# => Does
print($x ?: 'Does');
$a = null;
$b = 'Does print';
# => a is unsert
echo $a ?? 'a is unset';
# => print
echo $b ?? 'b is unset';
```
### 匹配
```php
$statusCode = 500;
$message = match($statusCode) {
200, 300 => null,
400 => '未找到',
500 => '服务器错误',
default => '已知状态码',
};
echo $message; # => 服务器错误
```
查看: [Match](https://www.php.net/manual/en/control-structures.match.php)
### 匹配表达式
```php
$age = 23;
$result = match (true) {
$age >= 65 => 'senior',
$age >= 25 => 'adult',
$age >= 18 => 'young adult',
default => 'kid',
};
echo $result; # => young adult
```
PHP 循环
------
### while 循环
```php
$i = 1;
# => 12345
while ($i <= 5) {
echo $i++;
}
```
### do while 循环
```php
$i = 1;
# => 12345
do {
echo $i++;
} while ($i <= 5);
```
### for i 循环
```php
# => 12345
for ($i = 1; $i <= 5; $i++) {
echo $i;
}
```
### break 跳出循环
```php
# => 123
for ($i = 1; $i <= 5; $i++) {
if ($i === 4) {
break;
}
echo $i;
}
```
### continue 继续
```php
# => 1235
for ($i = 1; $i <= 5; $i++) {
if ($i === 4) {
continue;
}
echo $i;
}
```
### foreach 循环
```php
$a = ['foo' => 1, 'bar' => 2];
# => 12
foreach ($a as $k) {
echo $k;
}
```
查看: [Array iteration](#关键迭代)
PHP 函数
------
### 返回值
```php
function square($x)
{
return $x * $x;
}
echo square(4); # => 16
```
### 返回类型
```php
// 基本返回类型声明
function sum($a, $b): float {/*...*/}
function get_item(): string {/*...*/}
class C {}
// 返回一个对象
function getC(): C { return new C; }
```
### 可空返回类型
```php
// 在 PHP 7.1 中可用
function nullOrString(int $v) : ?string
{
return $v % 2 ? "odd" : null;
}
echo nullOrString(3); # => odd
var_dump(nullOrString(4)); # => NULL
```
查看: [Nullable types](https://www.php.net/manual/en/migration71.new-features.php)
### 无效函数
```php
// 在 PHP 7.1 中可用
function voidFunction(): void
{
echo 'Hello';
return;
}
voidFunction(); # => Hello
```
### 变量函数
```php
function bar($arg = '')
{
echo "In bar(); arg: '$arg'.\n";
}
$func = 'bar';
$func('test'); # => In bar(); arg: test
```
### 匿名函数
```php
$greet = function($name)
{
printf("Hello %s\r\n", $name);
};
$greet('World'); # => Hello World
$greet('PHP'); # => Hello PHP
```
### 递归函数
```php
function recursion($x)
{
if ($x < 5) {
echo "$x";
recursion($x + 1);
}
}
recursion(1); # => 1234
```
### 默认参数
```php
function coffee($type = "cappuccino")
{
return "Making a cup of $type.\n";
}
# => 制作一杯卡布奇诺
echo coffee();
# => 制作一杯
echo coffee(null);
# => 制作一杯浓缩咖啡
echo coffee("espresso");
```
### 箭头函数
```php
$y = 1;
$fn1 = fn($x) => $x + $y;
// 相当于按值使用 $y
$fn2 = function ($x) use ($y) {
return $x + $y;
};
echo $fn1(5); # => 6
echo $fn2(5); # => 6
```
PHP 类
------
### 构造函数 Constructor
```php
class Student {
public function __construct($name) {
$this->name = $name;
}
public function print() {
echo "Name: " . $this->name;
}
}
$alex = new Student("Alex");
$alex->print(); # => Name: Alex
```
### 继承 Inheritance
```php
class ExtendClass extends SimpleClass
{
// 重新定义父方法
function displayVar()
{
echo "Extending class\n";
parent::displayVar();
}
}
$extended = new ExtendClass();
$extended->displayVar();
```
### 类变量 Classes variables
<!--rehype:wrap-class=row-span-2-->
```php
class MyClass
{
const MY_CONST = 'value';
static $staticVar = 'static';
// 可见度
public static $var1 = 'pubs';
// 仅限类
private static $var2 = 'pris';
// 类和子类
protected static $var3 = 'pros';
// 类和子类
protected $var6 = 'pro';
// 仅限类
private $var7 = 'pri';
}
```
静态访问
```php
echo MyClass::MY_CONST; # => value
echo MyClass::$staticVar; # => static
```
### 魔术方法
```php
class MyClass
{
// 对象被视为字符串
public function __toString()
{
return $property;
}
// 与 __construct() 相反
public function __destruct()
{
print "Destroying";
}
}
```
### 接口
```php
interface Foo
{
public function doSomething();
}
interface Bar
{
public function doSomethingElse();
}
class Cls implements Foo, Bar
{
public function doSomething() {}
public function doSomethingElse() {}
}
```
各种各样的
------
### 基本错误处理
```php
try {
// 做一点事
} catch (Exception $e) {
// 处理异常
} finally {
echo "Always print!";
}
```
### PHP 8.0 中的异常
<!--rehype:wrap-class=col-span-2-->
```php {.wrap}
$nullableValue = null;
try {
$value = $nullableValue ?? throw new InvalidArgumentException();
} catch (InvalidArgumentException) { // 变量是可选的
// 处理我的异常
echo "print me!";
}
```
### 自定义异常
<!--rehype:wrap-class=row-span-2-->
```php
class MyException extends Exception {
// 做一点事
}
```
用法
```php
try {
$condition = true;
if ($condition) {
throw new MyException('bala');
}
} catch (MyException $e) {
// 处理我的异常
}
```
### Nullsafe 运算符
<!--rehype:wrap-class=row-span-2-->
```php
// 从 PHP 8.0.0 开始,这一行:
$result = $repo?->getUser(5)?->name;
// 相当于下面的代码:
if (is_null($repo)) {
$result = null;
} else {
$user = $repository->getUser(5);
if (is_null($user)) {
$result = null;
} else {
$result = $user->name;
}
}
```
另见: [Nullsafe 运算符](https://wiki.php.net/rfc/nullsafe_operator)
### 常用表达
```php
$str = "Visit Quickref.me";
echo preg_match("/qu/i", $str); # => 1
```
查看: [PHP中的正则表达式](./regex.md#php中的正则表达式)
### fopen() 模式
:- | -
:- | -
`r` | 读
`r+` | 读写,前置
`w` | 写入,截断
`w+` | 读写,截断
`a` | 写,追加
`a+` | 读写,追加
### 运行时定义的常量
```php
define("CURRENT_DATE", date('Y-m-d'));
// 一种可能的表示
echo CURRENT_DATE; # => 2021-01-05
# => CURRENT_DATE is: 2021-01-05
echo 'CURRENT_DATE is: ' . CURRENT_DATE;
```
另见
----
- [PHP 官方中文文档](https://www.php.net/manual/zh/index.php) _(php.net)_
- [Learn X in Y minutes](https://learnxinyminutes.com/docs/php/) _(learnxinyminutes.com)_

View File

@ -623,7 +623,7 @@ $ sudo systemctl restart postgresql
另见:[复制](https://www.postgresql.org/docs/current/sql-copy.html)
Also see
--------
另见
----
- [Posgres-cheatsheet](https://gist.github.com/apolloclark/ea5466d5929e63043dcf#posgres-cheatsheet) _(gist.github.com)_

View File

@ -1232,3 +1232,10 @@ else: # try/except 块的可选子句。 必须遵循除块
finally: # 在所有情况下执行
print("我们可以在这里清理资源")
```
另见
----
- [Python](https://www.python.org/) _(python.org)_
- [Learn X in Y minutes](https://learnxinyminutes.com/docs/python/) _(learnxinyminutes.com)_
- [Regex in python](./regex.md#python-中的正则表达式) _(quickref.me)_

View File

@ -8,7 +8,7 @@ Quick Reference 备忘清单
### 本地编译预览
简单的将仓库克隆下来本地调试页面展示
将仓库克隆本地调试页面。请参阅[贡献指南](https://github.com/jaywcjlove/reference/blob/main/CONTRIBUTING.md)了解如何开始
#### 克隆仓库
@ -22,12 +22,101 @@ git clone git@github.com:jaywcjlove/reference.git
```shell
npm i # 安装依赖
npm run build # 编译输出 HTML
npm run start # 监听 md 文件编译输出 HTML
```
HTML 存放在仓库根目录下的 `dist` 目录中,将 `dist/index.html` 静态页面在浏览器中打开预览。
```shell
npm run start # 监听 md 文件编译输出 HTML
```
### 目录结构
```bash
.
├── CONTRIBUTING.md # 贡献说明
├── Dockerfile
├── LICENSE
├── README.md # Home(首页) 内容
├── dist # 编译后的静态资源目录
├── docs # Markdown 文档(速查表)
│   ├── bash.md
│   ├── ....
│   └── yaml.md
├── package.json
└── scripts # MD 转 HTML 的编译脚本
├── assets # LOGO 图标文件资源
├── ....
└── watch.mjs
```
### 添加一个备忘清单
一个简单的备忘清单包含 `页面大标题<h1>`,放在大标题下面的 `介绍` 文本,`<h2>` 分类标题,`<h3>` 内容为 `卡片`
```markdown
备忘清单 (页面大标题)
===
这是您可以在当前清单上使用的样式参考!备忘清单介绍
入门 (分类标题)
---
### 介绍 (卡片)
卡片内容
```
上面 markdown 内容存放到 `docs` 目录中,命名为 `xxx.md`
### 首页导航
<!--rehype:wrap-class=col-span-2-->
首页(`README.md`)存放在仓库的根目录,通过这个 `README.md` 自动生成首页导航,下面是导航实例:
```markdown
## Linux 命令
[Cron](./docs/cron.md)<!--rehype:style=background: rgb(239 68 68/var(\-\-bg\-opacity));-->
<!--rehype:class=home-card-->
```
首页导航图标存放在 `scripts/assets` 目录中,如果你的备忘清单定义为 `docs/cron.md`,那么你的图标就定义为 `cron.svg` 存放到 `scripts/assets` 目录中,重新编译首页当行菜单就拥有了图标。
- 图标存放在 [`scripts/assets`](https://github.com/jaywcjlove/reference/blob/main/scripts/assets) 目录中
- 图片名称与清单名称保持一致 `cron.md` -> `cron.svg` (注意大小写)
- SVG 图标尺寸 `<svg height="1em" width="1em"`
- SVG 图标颜色使用继承颜色值 `<svg fill="currentColor"`
- 使用 `<!--rehype:class=home-card-->` 标识卡片样式
### 首页提示配置
```markdown
[Django](./docs/djiango.md)<!--rehype:style=background: rgb(12 75 51/var(\-\-bg\-opacity));&class=contributing-->
```
<!--rehype:className=wrap-text-->
添加 `contributing` 类名,会在卡片下方默认添加 `👆待完善需要您的参与`
```markdown
class=tag&data-info=👆看看还缺点儿什么?
```
上面示例将默认提示更改为: `👆看看还缺点儿什么?`
```markdown
[Django](./docs/djiango.md)<!--rehype:style=background: rgb(12 75 51/var(\-\-bg\-opacity));&class=tag&data-lang=Python-->
```
<!--rehype:className=wrap-text-->
添加 `class=tag&data-lang=Python` 类名和参数,会在卡片右上角标记 _`Python`_
Markdown 语法注释
---
### 介绍
<!--rehype:wrap-class=row-span-2-->
在备忘清单采用 `HTML 注释语法`,标识网站布局和一些样式,目的是为了在 `GitHub` 中也是正常毫无瑕疵的预览 [`Markdown`](./markdown.md)。
@ -38,12 +127,12 @@ HTML 存放在仓库根目录下的 `dist` 目录中,将 `dist/index.html` 静
卡片 Markdown 内容展示,下面注释语法为文字内容改变样式
<!--rehype:style=color: red;-->
```
<!--rehype:className=wrap-text -->
<!--rehype:className=wrap-text-->
使用 `col-span-2` 类标识,卡片占 `2` 列位置
上面基础示例,使用 `col-span-2` 类标识,卡片占 `2` 列位置,参考现有备忘清单的源代码是一个好习惯!
### 注释语法介绍
<!--rehype:wrap-class=row-span-3&style=color:black;background-color: #d7a100;-->
<!--rehype:wrap-class=row-span-4&style=color:black;background-color: #d7a100;-->
- 在某个 [`Markdown`](./markdown.md) 语法下方或者后面,添加 HTML注释
-`<!--rehype:` 开始,`-->` 结束,包裹参数内容
@ -57,7 +146,7 @@ HTML 存放在仓库根目录下的 `dist` 目录中,将 `dist/index.html` 静
#### 示例
```markdown
### H2 部分
## H2 部分
<!--rehype:body-class=cols-2-->
### H3 部分
@ -70,7 +159,7 @@ HTML 存放在仓库根目录下的 `dist` 目录中,将 `dist/index.html` 静
### 标题
<!--rehype:wrap-class=row-span-3&style=color:red;-->
```
<!--rehype:className=wrap-text -->
<!--rehype:className=wrap-text-->
#### 参数说明
@ -96,7 +185,7 @@ _我是红色_<!--rehype:style=color: red;-->
**加粗变大红色**
<!--rehype:style=color: red;font-size: 18px-->
```
<!--rehype:className=wrap-text -->
<!--rehype:className=wrap-text-->
上面添加注释样式,文字 _加粗变大红色_<!--rehype:style=color: red;font-size: 18px-->`红`并且`大`
@ -106,7 +195,7 @@ _我是红色_<!--rehype:style=color: red;-->
\```js
function () {}
\```
<!--rehype:className=wrap-text -->
<!--rehype:className=wrap-text-->
```
如果代码块内容太长,使用强制换行类(`wrap-text`)解决
@ -149,11 +238,11 @@ export const Student = (
添加注释配置 `<!--rehype:tooltips-->` 添加一个 Tooltips 提示。
### H3 部分(卡片)背景颜色
<!--rehype:wrap-style=background: #00c69357;-->
<!--rehype:wrap-style=background: #8dffd42e;-->
```markdown
### H3 部分(卡片)背景颜色
<!--rehype:wrap-style=background: #00c69357;-->
<!--rehype:wrap-style=background: #8dffd42e;-->
```
<!--rehype:className=wrap-text -->
@ -214,35 +303,6 @@ 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;-->
```
隐藏卡片标题,在 H3 标题下面添加注释样式
```
```markdown {2}
### 隐藏卡片标题
<!--rehype:style=display:none;&wrap-style=padding-top: 0;-->
```
<!--rehype:className=wrap-text -->
### HTML 代码预览
```
@ -259,6 +319,35 @@ const school = <div>学校</div>;
上面的 [`markdown`](./markdown.md) 代码在 `meta` 位置添加 `preview` 标识,[HTML](./html.md) 代码将被执行预览
### 隐藏卡片标题
<!--rehype:style=display:none;&wrap-style=padding-top: 0;-->
```
隐藏卡片标题,在 H3 标题下面添加注释样式
```
```markdown {2}
### 隐藏卡片标题
<!--rehype:style=display:none;&wrap-style=padding-top: 0;-->
```
<!--rehype:className=wrap-text -->
### 注释类配置
<!--rehype:wrap-class=col-span-2-->
类 | 说明
---- | ----
`<!--rehype:className=wrap-text-->` | 强制换行
`<!--rehype:className=show-header-->` | 展示表格表头
`<!--rehype:className=shortcuts-->` | 快捷键样式
`<!--rehype:className=auto-wrap-->` | 隐藏表头强制小尺寸自动换行
`<!--rehype:className=style-list-arrow-->` | 列表箭头样式展示表格
`<!--rehype:className=style-list-->` | 列表样式展示表格
`<!--rehype:className=left-align-->` | 表格末尾列左对齐
`<!--rehype:className=style-none-->` | \<li> 没有标记
`<!--rehype:className=style-timeline-->` | 时间轴样式
`<!--rehype:className=style-arrow-->` | 箭头标记
### KaTeX 数学渲染
```KaTeX

View File

@ -452,7 +452,7 @@ M(?(?=.*?\bher\b)s|r)\.
表达式 | 匹配示例
:- | -
`.ar` | The `car` `par`ked in the `gar`age.
`.ar` | The `car` <pur>`par`</pur>ked in the `gar`age.
`ar[.]` | A garage is a good place to park a c`ar`.
<!--rehype:className=show-header-->
@ -474,7 +474,7 @@ M(?(?=.*?\bher\b)s|r)\.
表达式 | 匹配示例
:- | -
`[a-z]*` | T`he` `car` `parked` `in` `the` `garage` #21.
`[a-z]*` | T`he` <pur>`car`</pur> `parked` <pur>`in`</pur> `the` <pur>`garage`</pur> #21.
`\s*cat\s*` | The fat `cat` sat on the con`cat`enation.
表达式 `[a-z]*` 匹配一个行中所有以小写字母开头的字符串。
@ -503,7 +503,7 @@ M(?(?=.*?\bher\b)s|r)\.
`[0-9]{2,3}` | The number was 9.`999`7 but we rounded it off to `10`.0.
`[0-9]{2,}` | The number was 9.`9997` but we rounded it off to `10`.0.
`[0-9]{3}` | The number was 9.`999`7 but we rounded it off to 10.0.
<!--rehype:className=show-header-->
<!--rehype:className=style-list-arrow-->
### `(...)` 特征标群
@ -616,7 +616,7 @@ M(?(?=.*?\bher\b)s|r)\.
表达式 | 匹配示例
:- | -
`The` | The `fat` cat sat on the mat.
`/The/gi` | The `fat` `cat` `sat` on the `mat`.
`/The/gi` | `The` fat cat sat on `the` mat.
<!--rehype:className=show-header-->
修饰语 `i` 用于忽略大小写,`g` 表示全局搜索。
@ -722,7 +722,7 @@ False
函数 | 说明
:-|-
`re.findall` | 返回包含所有匹配项的列表
`re.finditer` | 返回一个可迭代的匹配对象每个匹配一个
`re.finditer` | 返回一个可迭代的匹配对象<br/> _(每个匹配一个)_
`re.search` | 如果字符串中的任何位置存在匹配项,则返回 Match 对象
`re.split` | 返回一个列表,其中字符串在每次匹配时被拆分
`re.sub` | 用字符串替换一个或多个匹配项

View File

@ -19,6 +19,7 @@ fn main() {
```shell
$ rustc Hello_World.rs
$ ./Hello_World
Hello, World!
```
@ -142,25 +143,55 @@ foo!(3);
### 结构体
结构体是一个使用关键字 `struct` 定义的标称型(nominal)结构体类型
```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
}
struct Color (i32, i32, i32);
let black = Color(0,0,0);
```
let baz_discriminant = Foo::Baz as u32;
assert_eq!(baz_discriminant, 123);
#### 单元结构体
不关心该类型的内容, 只关心它的行为。
```rust
struct Solution;
impl Solution{
// ...
}
```
### 语句与表达式
在 rust 中,语句无需返回值,而表达式总要返回值
#### 语句
```rust
let a = "hello".to_string();
let b = a + " world";
println!("{}", b);
```
#### 表达式
```rust
fn main(){
let x = {
let a = "hello".to_string();
a + " world"
};
println!("{}", x);
// hello world
}
```
Rust 类型
@ -220,6 +251,9 @@ println!("社区的名称是 {community_name},它有 {no_of_members} 个成员
查看: [字符串](#rust-字符串)
### 数组
<!--rehype:wrap-class=row-span-2-->
这里介绍的是固定长度的数组。rust 中常用的是集合类型 vec 表示的[动态数组](#rust-动态数组)
```rust
┌─────┬─────┬─────┬─────┬─────┬─────┐
@ -234,28 +268,8 @@ println!("社区的名称是 {community_name},它有 {no_of_members} 个成员
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;
@ -273,14 +287,6 @@ let mut slices: &[i64] = &array[0..3]
println!("切片的元素是:{slices:?}");
```
### 向量
```rust
let some_vector = vec![1,2,3,4,5];
```
使用 `vec!` 宏声明向量
### 元组
```rust
@ -411,8 +417,28 @@ println!("{:?}", element2);
}
```
### 多维数组
```rust
j0 j1 j2 j3 j4 j5
┌────┬────┬────┬────┬────┬────┐
i0 | 1 | 2 | 3 | 4 | 5 | 6 |
├────┼────┼────┼────┼────┼────┤
i1 | 6 | 5 | 4 | 3 | 2 | 1 |
└────┴────┴────┴────┴────┴────┘
```
----
```rust
let arr = vec![
vec![1, 2, 3, 4, 5, 6],
vec![6, 5, 4, 3, 2, 1]
];
```
### 常用方法
<!--rehype:wrap-class=col-span-3-->
<!--rehype:wrap-class=col-span-2-->
-|:-
-|:-
@ -429,6 +455,86 @@ println!("{:?}", element2);
`drain(range)` | 删除 `vec` 中指定范围的元素,同时返回一个迭代该范围所有元素的迭代器
`split_off(index)` | 切分 `vec`,索引左边的元素保留在原 `vec` 中(含索引),索引右边的元素(不含索引)在返回的 `vec` 中
枚举
--------
### 在结构体中使用枚举
```rust
enum IpAddrKind {
V4,
V6,
}
struct IpAddr {
kind: IpAddrKind,
address: String,
}
fn main(){
let ip = IpAddr{
kind: IpAddrKind::V4,
address: String::from("127.0.0.1")
};
}
```
### 枚举的变体
```rust
enum IpAddrKind {
V4(u8, u8, u8, u8),
V6(String),
}
fn main() {
let home = IpAddrKind::V4(127, 0, 0, 1);
let loopback = IpAddrKind::V6(String::from("::1"));
}
```
----
```rust
enum Message{
Quit,
Move {x:i32, y:i32},
Write(String),
ChangeColor(i32, i32, i32),
}
fn main(){
let q = Message::Quit;
let m = Message::Move {x:10, y:20};
let w = Message:: Write(String::from("hello"));
let c = Message::ChangeColor(10, 20, 30);
}
```
### 模式匹配结构体
```rust
#[derive(Debug)]
enum Grade {
A,
B,
C,
}
enum Subject {
Math(Grade),
English(Grade),
}
fn subject_grade(sub: Subject) {
match sub {
Subject::Math(grade) => println!("The Math is {:?}", grade),
Subject::English(grade) => println!("The Math is {:?}", grade),
}
}
fn main() {
subject_grade(Subject::Math(Grade::A));
}
```
Rust 运算符
-----------
@ -535,29 +641,7 @@ let mut l = k;
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 表达式
### If 表达式
```rust
let foo = 12;
@ -573,101 +657,30 @@ if foo == bar {
}
```
### 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 循环
<!--rehype:wrap-class=col-span-2-->
```rust
for mut i in 0..15 {
i-=1;
println!("i 的值为:{i}");
let mut vec = [1, 2, 3];
for v in &mut vec {
*v -= 1;
println!("v 的值为:{v}");
}
```
使用方法 | 等价使用方式 | 所有权
:-|:-:|:-
for item in collection | for item in collection.into_iter() | 转移所有权
for item in &collection | for item in collection.iter() | 不可变借用
for item in &mut collection | for item in collection.iter_mut() | 可变借用
### While 循环
```rust
let mut check = 0;
while check < 11{
println!("check 是:{check}");
check+=1;
check += 1;
println!("递增后:{check}");
if check == 10{
break; // 停止 while
@ -675,7 +688,7 @@ while check < 11{
}
```
### Loop 关键字
### Loop 循环
```rust
loop {
@ -685,19 +698,6 @@ loop {
无限循环表示
### Break 中断语句
```rust
let mut i = 1;
loop {
println!("i 是 {i}");
if i > 100 {
break;
}
i *= 2;
}
```
### Continue 继续声明
```rust
@ -711,118 +711,279 @@ for (v, c) in (0..10+1).enumerate(){
}
```
### Break 中断语句
`break` 可以单独使用,也可以带一个返回值
```rust
let mut i = 1;
let res = loop {
println!("i 是 {i}");
if i > 100 {
break i - 100;
}
i *= 2;
}
println!("{res}"); // 28
```
Rust 模式匹配
--------
### match
<!--rehype:wrap-class=row-span-2-->
match 模式匹配,使用 `a | b` 表示匹配 a **或** b使用 `_`,表示匹配剩余所有选项
```rust
fn main(){
let grade = Grade::A;
match grade {
Grade::A => println!("Good"),
Grade::B => println!("Not bad"),
Grade::C | Grade::D => println!("Come on"),
_ => println!("emmm"),
}
}
enum Grade {
A,
B,
C,
D,
E,
F,
}
```
#### `matches!` 宏
它可以将一个表达式跟模式进行匹配,然后返回匹配的结果 `true` 或 `false`
```rust
assert!(matches!('x' ',A'..='Z' | 'a'..='z'));
assert!(matches!(Some(101), Some(x) if x > 100));
```
### if let 匹配
match 表达式需要匹配所有的枚举才能结束,但通常我们只需要匹配我们需要的值
```rust
let x = 3;
match Some(x) {
Some(3) => println!("I guess that x is 3"),
_ => ()
}
```
使用 `if let`
```rust
let x = 3;
if let Some(3) = Some(x) {
println!("I guess that x is 3");
}
```
### while let
```rust
let mut stack = vec![];
stack.push(1);
stack.push(2);
stack.push(3);
while let Some(top) = stack.pop() {
println!("{}", top);
}
```
### 其它模式匹配
#### for 循环迭代器
```rust
for (i, v) in collection.iter().enumerate(){}
```
#### let
```rust
let (x, _, y) = (1, 2, 3);
println!("{x},{y}");
```
### 函数中的模式匹配
```rust
fn add((x, y): (i32, i32)) -> i32 {
x + y
}
fn main(){
let sum = add(1, 2);
println!("{sum}");
}
```
### 忽略参数
<!--rehype:wrap-class=row-span-2-->
#### 使用 `..` 忽略剩余参数
```rust
struct Point {
x: i32,
y: i32,
z: i32,
}
let origin = Point { x: 0, y: 0, z: 0 };
match origin {
Point { x, .. } => println!("x is {}", x),
}
```
#### 使用 `_` 忽略部分参数
```rust
let hello = ('h', 'e', 'l', 'l', 'o');
match hello {
(h, _, _, l, o) => {
println!("char: {}, {}, {}", h, l, o)
},
}
```
### 匹配命名变量
以下代码,只要给定的 x 是 Some 类型,但 Some 中的值不是 1都会匹配到 y
```rust
let x = Some(10);
match x {
Some(1) => println!("x = 1"),
Some(y) => println!("y = {:?}", y),
_ => println!("None"),
}// y = 10
```
### `@` 绑定
<!--rehype:wrap-class=row-span-2-->
`@` 运算符允许为一个字段绑定另外一个变量。
```rust
let grade = 'A';
match grade {
good @ 'A'..='C' => println!("your grade is {}", good),
_ => println!("Come on"),
}
```
----
```rust
#[derive(Debug)]
struct Point {
x: i32,
y: i32,
}
fn main(){
let p @ Point {x: px, y: py } = Point {x: 10, y: 23};
println!("x: {}, y: {}", px, py);
println!("{:?}", p);
}
```
----
如果使用 `|`,需要使用 `()`,进行多个模式的绑定
```rust
match 1 {
num @ (1 | 2) => {
println!("{}", num);
}
_ => {}
}
```
### 使用匹配守卫
```rust
let x = Some(2);
match x {
Some(1) => println!("x = 1"),
Some(y) if y == 2 => println!("y = {:?}", y),
_ => println!("No match"),
}// y = 2
```
Rust 函数
--------
### 基本函数
### 函数命名
rust 的函数使用蛇形命名法snake case
```rust
fn print_message(){
println!("Hello, Quick Reference!");
}
fn main(){
// 在 Rust 中调用函数
print_message();
}
```
### 按值传递
### 参数值
rust 需要为函数的参数标明确定的类型
```rust
fn main()
{
let x:u32 = 10;
let y:u32 = 20;
// => 200
println!("计算: {}", cal_rect(x, y));
fn another_fn(a:u8, b: &str){
println!("我是 u8:{}", a);
println!("我是 &str:{}", b);
}
fn cal_rect(x:u32, y:u32) -> u32
{
x * y
fn main(){
another_fn(10, "hello")
}
```
### 通过引用传递
### 返回值
如果不指定返回值rust 默认返回 `()` 类型
```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
}
// 在 bin 中的入口函数默认返回 ()
fn main(){}
```
### 返回
----
使用 `->` 指定返回值,如果**表达式**在最后一行,无需使用 return
```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);
fn add(a:i32, b:i32) -> i32 {
if a + b < 100 {
return a - b;
}
a + b
}
```
### 永不返回 `!`
```rust
fn dead_end() -> ! {
panic!("panic!!!!!");
}
```
<!--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]);
```
杂项
-----

View File

@ -10,8 +10,8 @@ TypeScript 备忘清单
TypeScript 是具有类型语法的 JavaScript。Interface 是为了匹配它们的运行时行为而构建的。
- [JavaScript 备忘清单](./javascript.md)
- [TypeScript 官网](https://www.typescriptlang.org/)
- [JavaScript 备忘清单](./javascript.md) _(jaywcjlove.github.io)_
- [TypeScript 官网](https://www.typescriptlang.org/) _(typescriptlang.org)_
### 内置类型基元
@ -1264,3 +1264,52 @@ class Select<T> extends React.Component<SelectProps<T>, any> {}
// 使用
const Form = () => <Select<string> items={['a', 'b']} />;
```
各种各样的技巧
---
### keyof 取 interface 的键
<!--rehype:wrap-class=row-span-2-->
```ts
interface Point {
x: number;
y: number;
}
// type keys = "x" | "y"
type keys = keyof Point;
```
### 索引签名
```ts
interface NumberOrString {
[index: string]: string | number;
length: number;
name: string;
}
```
### 从数组中提取类型
```ts
type Point = { x: number; y: number; }
type Data = Point[];
// Data 是个数组,提取里面的元素类型
type PointDetail = Data[number];
// type PointDetail = { x: number; y: number; }
```
### 只读元组类型
```ts
const point = [3, 4] as const
// type 'readonly [3, 4]'
```
另见
----
- [JavaScript 备忘清单](./javascript.md)
- [TypeScript 官网](https://www.typescriptlang.org/) _(typescriptlang.org)_

View File

@ -408,7 +408,7 @@ Vim 搜索和替换
`?foo` | 向后搜索
`/\v\d+` | 使用 [regex](./regex.md) 搜索
`n` | 下一个匹配的搜索模式
`N` | 上一场比赛
`N` | 上一个匹配的搜索
`*` | 向前搜索当前单词
`#` | 向后搜索当前单词

View File

@ -1,6 +1,6 @@
{
"name": "@wcj/reference",
"version": "1.19.0",
"version": "1.20.0",
"description": "为开发人员分享快速参考备忘单(主要是方便自己)。",
"author": "jaywcjlove",
"license": "MIT",

3
scripts/assets/dart.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="M4.105 4.105S9.158 1.58 11.684.316a3.079 3.079 0 0 1 1.481-.315c.766.047 1.677.788 1.677.788L24 9.948v9.789h-4.263V24H9.789l-9-9C.303 14.5 0 13.795 0 13.105c0-.319.18-.818.316-1.105l3.789-7.895zm.679.679v11.787c.002.543.021 1.024.498 1.508L10.204 23h8.533v-4.263L4.784 4.784zm12.055-.678c-.899-.896-1.809-1.78-2.74-2.643-.302-.267-.567-.468-1.07-.462-.37.014-.87.195-.87.195L6.341 4.105l10.498.001z"/>
</svg>

After

Width:  |  Height:  |  Size: 526 B

3
scripts/assets/latex.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 5.6 KiB

3
scripts/assets/php.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="M7.01 10.207h-.944l-.515 2.648h.838c.556 0 .97-.105 1.242-.314.272-.21.455-.559.55-1.049.092-.47.05-.802-.124-.995-.175-.193-.523-.29-1.047-.29zM12 5.688C5.373 5.688 0 8.514 0 12s5.373 6.313 12 6.313S24 15.486 24 12c0-3.486-5.373-6.312-12-6.312zm-3.26 7.451c-.261.25-.575.438-.917.551-.336.108-.765.164-1.285.164H5.357l-.327 1.681H3.652l1.23-6.326h2.65c.797 0 1.378.209 1.744.628.366.418.476 1.002.33 1.752a2.836 2.836 0 0 1-.305.847c-.143.255-.33.49-.561.703zm4.024.715.543-2.799c.063-.318.039-.536-.068-.651-.107-.116-.336-.174-.687-.174H11.46l-.704 3.625H9.388l1.23-6.327h1.367l-.327 1.682h1.218c.767 0 1.295.134 1.586.401s.378.7.263 1.299l-.572 2.944h-1.389zm7.597-2.265a2.782 2.782 0 0 1-.305.847c-.143.255-.33.49-.561.703a2.44 2.44 0 0 1-.917.551c-.336.108-.765.164-1.286.164h-1.18l-.327 1.682h-1.378l1.23-6.326h2.649c.797 0 1.378.209 1.744.628.366.417.477 1.001.331 1.751zm-2.595-1.382h-.943l-.516 2.648h.838c.557 0 .971-.105 1.242-.314.272-.21.455-.559.551-1.049.092-.47.049-.802-.125-.995s-.524-.29-1.047-.29z"/>
</svg>

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -162,14 +162,17 @@ menu {
padding: 0;
}
yel {
color: var(--color-prettylights-syntax-variable);
yel,
yel code {
color: var(--color-prettylights-syntax-variable) !important;
}
red {
color: var(--color-danger-fg);
red,
red code {
color: var(--color-danger-fg) !important;
}
pur {
color: var(--color-prettylights-syntax-entity);
pur,
pur code {
color: var(--color-prettylights-syntax-entity) !important;
}
:is(.h3wrap-body, .wrap-body) p > code,

View File

@ -107,7 +107,7 @@ export function getTocsTree(arr = [], result = []) {
{
type: 'element',
tagName: 'div',
properties: { class: 'wrap-body' },
properties: { class: ['wrap-body'] },
children: [...header],
},
],
@ -133,7 +133,12 @@ export function getTocsTree(arr = [], result = []) {
children: [...resultChilds],
});
} else {
panle.children[0].children[1].properties?.class.push(bodyClass);
panle.children[0].children[1].children = panle.children[0].children[1].children.concat(resultChilds);
if (panle.children[0].children[1].properties && bodyStyle) {
const initStyle = panle.children[0].children[1].properties?.style || '';
panle.children[0].children[1].properties.style = initStyle + bodyStyle;
}
}
}
}