docs(vault): add feature walkthroughs and sync local notes
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
---
|
||||
title: 多语言代码与公式
|
||||
tags: 演示, 代码, 数学
|
||||
---
|
||||
|
||||
# 多语言代码与公式
|
||||
|
||||
代码块用于展示源码,不会在工作区自动执行。切换明暗主题时,可以观察关键字、字符串和注释的配色。
|
||||
|
||||
## Python:安全计算平均值
|
||||
|
||||
```python
|
||||
def average(scores: list[float]) -> float | None:
|
||||
"""空列表没有平均值。"""
|
||||
if not scores:
|
||||
return None
|
||||
return sum(scores) / len(scores)
|
||||
|
||||
print(average([72, 86, 94]))
|
||||
```
|
||||
|
||||
## TypeScript:整理标签
|
||||
|
||||
```typescript
|
||||
interface Note {
|
||||
title: string
|
||||
tags: string[]
|
||||
}
|
||||
|
||||
const note: Note = {
|
||||
title: '星灯资料站',
|
||||
tags: ['演示', '项目', '演示'],
|
||||
}
|
||||
const uniqueTags = [...new Set(note.tags)]
|
||||
console.log(uniqueTags)
|
||||
```
|
||||
|
||||
## Rust:只读文本处理
|
||||
|
||||
```rust
|
||||
fn main() {
|
||||
let title = "星灯资料站";
|
||||
let count = title.chars().count();
|
||||
println!("标题包含 {count} 个字符");
|
||||
}
|
||||
```
|
||||
|
||||
## SQL:演示查询
|
||||
|
||||
下面是虚构表结构的查询示例,不表示应用数据库的实际表名。
|
||||
|
||||
```sql
|
||||
SELECT title, updated_at
|
||||
FROM demo_notes
|
||||
WHERE category = '演示'
|
||||
ORDER BY updated_at DESC;
|
||||
```
|
||||
|
||||
## JSON 与 YAML
|
||||
|
||||
```json
|
||||
{
|
||||
"project": "星灯资料站",
|
||||
"offlineFirst": true,
|
||||
"reviewDays": 7
|
||||
}
|
||||
```
|
||||
|
||||
```yaml
|
||||
project: 星灯资料站
|
||||
milestones:
|
||||
- 收集资料
|
||||
- 完成校对
|
||||
- 整理索引
|
||||
```
|
||||
|
||||
## 数学公式
|
||||
|
||||
行内公式:当 $n > 0$ 时,均值为 $\bar{x}=\frac{1}{n}\sum_{i=1}^{n}x_i$。
|
||||
|
||||
块级公式:
|
||||
|
||||
$$
|
||||
\operatorname{cos}(\mathbf{a},\mathbf{b})
|
||||
=\frac{\mathbf{a}\cdot\mathbf{b}}
|
||||
{\lVert\mathbf{a}\rVert\lVert\mathbf{b}\rVert}
|
||||
$$
|
||||
|
||||
两个向量都非零时,上式表示余弦相似度。本文只演示公式显示,不执行向量检索。
|
||||
Reference in New Issue
Block a user