Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
wenerme committed Aug 9, 2024
1 parent dbd958f commit e4a5270
Show file tree
Hide file tree
Showing 31 changed files with 1,081 additions and 195 deletions.
44 changes: 44 additions & 0 deletions notes/db/kv/redis/redis-faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,47 @@ redis-cli
ulimit -Sn 100000
sysctl -w fs.file-max=100000
```

## LOCK

- key 为 lock name
- value 为 holder

**acquire**

```
SET key uuid PX timeout NX
```

**release**

```lua
if redis.call('GET', KEYS[1]) == ARGV[1] then
return redis.call('DEL', KEYS[1])
end
return 0
```

**extend**

```lua
if redis.call('GET', KEYS[1]) == ARGV[1] then
return redis.call('PEXPIRE', KEYS[1], ARGV[2])
end
return 0
```

- 其他方案

```
WATCH key # Begin watching the key for changes
GET key # Retrieve its value, return an error if not equal to the lock's UUID
MULTI # Start transaction
DEL key # Delete the key
EXEC # Execute the transaction, which will fail if the key had expired
```

- 参考
- [mike-marcacci/node-redlock](https://github.com/mike-marcacci/node-redlock)
- https://redis.io/docs/latest/develop/use/patterns/distributed-locks/
- [microfleet/ioredis-lock](https://github.com/microfleet/ioredis-lock)
34 changes: 34 additions & 0 deletions notes/dev/design/design-drive.md
Original file line number Diff line number Diff line change
Expand Up @@ -460,13 +460,26 @@ export type TemporaryUrlOptions = MiscellaneousOptions & {

## Object

- Hash 分层
- CAS (Content Addressable Storage) 内容可寻址存储系统
- hash -> object
- kv
- FCS - fixed content storage

**git**

- .git/objects
- .git/objects/pack - 已打包的对象文件 - .pack+.idx
- .git/objects/info - 对象的附加信息
- `.git/objects/[0-9a-f]{2}` - 对象的哈希前两位
- `.git/objects/[0-9a-f]{2}/[0-9a-f]{38}` - 对象的剩余哈希值
- git-annex
- .git/annex/objects/12/34/SHA256E-s1024--1234567890abcdef
- `HASH-sSIZE--FILENAME`
- 对象为 symlink / pointer
- 参考
- https://git-annex.branchable.com/internals/
- https://git-annex.branchable.com/internals/hashing/

**juicefs**

Expand Down Expand Up @@ -583,7 +596,28 @@ type sustained struct {
}
```

## Glossory

- path - 完整路径 `/home/user/documents/report.pdf`
- path=dirname+basename
- filename - 文件名 `report.pdf`
- name+extname
- extname 包含 `.`
- `^[^\\/:*?"<>|]+(\.[a-zA-Z0-9]+)?$`
- reserved
- Windows
- 保留文件名 CON, PRN, AUX, NUL, COM{1..9}, LPT{1..9} - 大小写不敏感
- `NUL.txt` `NUL.tar.gz` 也等同于 `NUL`
- https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file
- 保留字符 `/\:*?"<>|`
- 特殊文件名 `Thumbs.db`, `desktop.ini`
- macOS
- `:` - HFS 分隔符
- dirname - 目录名 `/home/user/documents`
- basename - 指路径中最后一部分的名称,无论它是文件还是目录

## 参考 {#reference}

- https://en.wikipedia.org/wiki/Filename
- https://github.com/opencurve/curve/blob/master/docs/cn/chunkserver_design.md
- https://github.com/opencurve/curve/blob/master/docs/en/chunkserver_design_en.md
71 changes: 71 additions & 0 deletions notes/dev/std/unicode/unicode-faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,74 @@ dos2unix test.xml
- GBK - 1995年,21003个字符
- 是 GB2312 的扩展/升级
- 兼容 GB2312

## Normalize

- NFC
- Canonical Decomposition, followed by Canonical Composition.
- NFD
- Canonical Decomposition.
- NFKC
- Compatibility Decomposition, followed by Canonical Composition.
- NFKD
- Compatibility Decomposition.
- Lone leading surrogate
- `ab\uD800`
- `ab\uD800c`
- Lone trailing surrogate
- `\uDFFFab`
- `c\uDFFFab`
- JS
- String.prototype.isWellFormed - Chrome 111+, Safari 16.4+, Node 20.0+
- 避免 encodeURI 时出错
- String.prototype.toWellFormed
- String.prototype.normalize - Chrome 34+, Safari 10.1+, Node 0.12+

```js
{
let string1 = '\u00F1'; // ñ
let string2 = '\u006E\u0303'; // ñ

string1 = string1.normalize('NFD');
string2 = string2.normalize('NFD');

console.log(string1 === string2); // true
console.log(string1.length); // 2
console.log(string2.length); // 2
}

{
let string1 = '\u00F1'; // ñ
let string2 = '\u006E\u0303'; // ñ

string1 = string1.normalize('NFC');
string2 = string2.normalize('NFC');

console.log(string1 === string2); // true
console.log(string1.length); // 1
console.log(string2.length); // 1
console.log(string2.codePointAt(0).toString(16)); // f1
}

{
let string1 = '\uFB00';
let string2 = '\u0066\u0066';

console.log(string1); //
console.log(string2); // ff
console.log(string1 === string2); // false
console.log(string1.length); // 1
console.log(string2.length); // 2

string1 = string1.normalize('NFKD');
string2 = string2.normalize('NFKD');

console.log(string1); // ff <- visual appearance changed
console.log(string2); // ff
console.log(string1 === string2); // true
console.log(string1.length); // 2
console.log(string2.length); // 2
}
```

- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize
17 changes: 17 additions & 0 deletions notes/dev/theory/design-pattern.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ title: 设计模式

# 设计模式

- 参考
- https://en.wikipedia.org/wiki/Design_Patterns
- https://sourcemaking.com/
- https://www.baeldung.com/design-patterns-series

## 网络

- Control plane & Data plane
Expand All @@ -17,3 +22,15 @@ title: 设计模式
## 并发

## 分布式

## application context

- ApplicationContext as alternative to ioc
- 作为 DI 的 Container
- IoC 的 容器
- Encapsulate Context
- Context Object
- 参考
- http://www.corej2eepatterns.com/ContextObject.htm
- https://www.baeldung.com/cs/context-design-pattern
- https://stackoverflow.com/a/16161219/1870054
31 changes: 31 additions & 0 deletions notes/hardware/power/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title: 电源
---

# 电源

- [电池](./battery.md)
- [UPS](./ups.md)

## Power consumption

- RasPi0 / Pi Zero W
- 100 mA: 没有连接外设,WiFi和蓝牙关闭
- 160 mA: 蓝牙开启
- 170 mA: WiFi开启
- 230 mA: 相机连接并捕捉图像
- ESP32
- Active Mode - RTC + ULP + ESP32 Core + 外设 + Radio + WiFi + BT
- 160~260mA - WiFi Tx 13dBm~21dBm
- 120mA - WiFi/BT Tx 0dBm
- 80-90mA - WiFi/BT Rx & listening
- Modem Sleep - RTC + UPL + ESP32 Core
- Light Sleep - RTC + UPL + ESP32 Core Paused
- Deep Sleep - RTC + UPL
- Hibernation - RTC

---

- 参考
- https://raspi.tv/2017/how-much-power-does-pi-zero-w-use
- https://lastminuteengineers.com/esp32-sleep-modes-power-consumption/
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ title: 电池
- 可生产为不同形状

| Size | 尺寸 | 容量(mAh) | 大小(直径 ✖️ 高) |
| ---- | ---- | -------------------------------------------------------------------------------------------------- | ---------------- |
| AAA | 七号 | 200 (alkaline)<br/>540 (carbon–zinc)<br/>800–1000 (NiMH) | 10.5 × 44.5 |
| AA | 五号 | 2700 (alkaline)<br/>1100 (carbon–zinc)<br/>3000 (Li–FeS2)<br/>1700–2700 (NiMH)<br/>600–1000 (NiCd) | 14.5 × 50.5 |
| C | 二号 | 8000 (alkaline)<br/>3800 (carbon–zinc)<br/>4500–6000M<br/>(NiMH) | 26.2 × 50 |
| D | 一号 | 12000 (alkaline)<br/>8000 (carbon–zinc)<br/>2200–11000 (NiMH)<br/>2000-5500 (NiCd) | 34.2 × 61.5 |
| ---: | ---- | -------------------------------------------------------------------------------------------------- | ---------------- |
| AAA | 七号 | 200 (alkaline)<br/>540 (carbon–zinc)<br/>800–1000 (NiMH) | 10.5 × 44.5 |
| AA | 五号 | 2700 (alkaline)<br/>1100 (carbon–zinc)<br/>3000 (Li–FeS2)<br/>1700–2700 (NiMH)<br/>600–1000 (NiCd) | 14.5 × 50.5 |
| C | 二号 | 8000 (alkaline)<br/>3800 (carbon–zinc)<br/>4500–6000M<br/>(NiMH) | 26.2 × 50 |
| D | 一号 | 12000 (alkaline)<br/>8000 (carbon–zinc)<br/>2200–11000 (NiMH)<br/>2000-5500 (NiCd) | 34.2 × 61.5 |

## 锂电池

Expand Down
File renamed without changes.
25 changes: 25 additions & 0 deletions notes/languages/c/cpp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
title: cpp
---

# cpp

- cpp -> C PreProcessor
- `__FILE__`, `__LINE__`
- `__FUNCTION__`
- `__func__` - C++11

**predefined identifier**

```
__LINE__: The line number of the current source line (a decimal constant).
__FILE__: The presumed name of the source file (a character string literal).
__DATE__: The date of translation of the source file (a character string literal...)
__TIME__: The time of translation of the source file (a character string literal...)
__STDC__: Whether__STDC__ is predefined
__cplusplus: The name __cplusplus is defined to the value 199711L when compiling a C ++ translation unit
```

- http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1642.html
- https://en.cppreference.com/w/cpp/utility/source_location
- `std::source_location`
7 changes: 7 additions & 0 deletions notes/languages/php/php-conf.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@ tags:
```bash
php --ini # 配置目录和加载的配置文件
```

```ini
memory_limit=128M
```


- https://www.php.net/manual/en/ini.core.php
45 changes: 44 additions & 1 deletion notes/languages/regexp.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,54 @@ const notThis = /^(?:(?!this).)*$/;

## JavaScript

:::caution

- RegExp 是有状态的
- lastIndex
- 连续执行 `exec()` 可能结果不一样

:::

| synbax | for | notes |
| ---------------------------------------------: | ------------------------------- | ----------------------- |
| `\N` | Backreference |
| `\k<name>` | Named backreference | Chrome 64+, Safari 11.1 |
| `\c[A-Za-z]` | control character = `char % 32` |
| `\0` | NULL, U+0000 |
| `(?<name>pattern)` | Named capture group | Chrome 64+, Safari 11.1 |
| `(?:pattern)` | Non-capturing group |
| `(?=pattern)`,`(?!pattern)` | Lookahead assertion |
| `(?<=pattern)`,`(?<!pattern)` | Lookbehind assertion |
| `(?flags1:pattern)`,`(?flags1-flags2:pattern)` | Modifier, ims, `-flags2` 是关闭 |

- flags
- i - ignoreCase
- m - multiline
- s - dotAll
- g - global
- y - sticky
- d - hasIndices
- u - unicode
- v - unicodeSets
- atoms - 正则最基础单元
- `\c[A-Za-z]`
- 控制字符
- = `char % 32`
- 因为大写和小写相差 32 因此 `\cJ``\cj` 是一样的
- `\cJ` = `\n`
- replacement - 替换
- `$$` -> `$`
- `$&`
- `$\``
- `$'`
- `$<n>`
- replacer(match,p1,p2,offset,wholeString,namedGroups)

- `/u` -> unicode
- 影响 `\w`, `\u{HHHH}`, `\uHHHH`
- `/[\p{L}\p{N}]+/u`
- RegExp `/v`, unicodeSets
- `/^\p{RGI_Emoji}$/v.test('😵‍💫')`=true - Unicode string properties
- `/^[\q{😵‍💫}]$/v.test('😵‍💫')`=true - \q for String literals
- `/^[\p{RGI_Emoji}--\q{😵‍💫}]$/v.test('😵‍💫')`=false - 支持排除
- 参考
- [Regular expressions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions)
6 changes: 6 additions & 0 deletions notes/os/linux/shell/shell-faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ tar -xzvf backup.tar.gz -C ./restored # 恢复
tar -I zstd -xvf archive.tar.zst # zstd
```

## ip

```bash
ip -o -4 addr show | grep -v veth | awk '{print $2, $4}'
```

## skip first n line

```bash
Expand Down
9 changes: 9 additions & 0 deletions notes/platform/youtube.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ title: Youtube

# Youtube

- YouTube Premium
- 去广告
- 后台播放 & 画中画
- 离线下载
- YouTube Music Premium
- YouTube Originals
- 参考
- 国家地区 https://support.google.com/youtube/answer/6307365

**会员价格**

| 地区 | 价格 USD/月 | 差额 USD/月 |
Expand Down
Loading

0 comments on commit e4a5270

Please sign in to comment.