noblog 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +25 -0
- package/dist/cmds/generate.d.ts +2 -0
- package/dist/cmds/generate.d.ts.map +1 -0
- package/dist/cmds/generate.js +46 -0
- package/dist/cmds/generate.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/cvtmd.d.ts +38 -0
- package/dist/lib/cvtmd.d.ts.map +1 -0
- package/dist/lib/cvtmd.js +111 -0
- package/dist/lib/cvtmd.js.map +1 -0
- package/dist/lib/nomd/cvter.d.ts +38 -0
- package/dist/lib/nomd/cvter.d.ts.map +1 -0
- package/dist/lib/nomd/cvter.js +111 -0
- package/dist/lib/nomd/cvter.js.map +1 -0
- package/dist/lib/nomd/nomd.d.ts +20 -0
- package/dist/lib/nomd/nomd.d.ts.map +1 -0
- package/dist/lib/nomd/nomd.js +73 -0
- package/dist/lib/nomd/nomd.js.map +1 -0
- package/dist/lib/nomd.d.ts +8 -0
- package/dist/lib/nomd.d.ts.map +1 -0
- package/dist/lib/nomd.js +50 -0
- package/dist/lib/nomd.js.map +1 -0
- package/dist/lib/nosm/default.d.ts +2 -0
- package/dist/lib/nosm/default.d.ts.map +1 -0
- package/dist/lib/nosm/default.js +3 -0
- package/dist/lib/nosm/default.js.map +1 -0
- package/dist/lib/nosm/nosm.d.ts +2 -0
- package/dist/lib/nosm/nosm.d.ts.map +1 -0
- package/dist/lib/nosm/nosm.js +2 -0
- package/dist/lib/nosm/nosm.js.map +1 -0
- package/dist/lib/notion/client.d.ts +6 -0
- package/dist/lib/notion/client.d.ts.map +1 -0
- package/dist/lib/notion/client.js +48 -0
- package/dist/lib/notion/client.js.map +1 -0
- package/dist/lib/notion/object.d.ts +148 -0
- package/dist/lib/notion/object.d.ts.map +1 -0
- package/dist/lib/notion/object.js +2 -0
- package/dist/lib/notion/object.js.map +1 -0
- package/dist/lib/notion/request.d.ts +36 -0
- package/dist/lib/notion/request.d.ts.map +1 -0
- package/dist/lib/notion/request.js +2 -0
- package/dist/lib/notion/request.js.map +1 -0
- package/output/00097769-2aac-4b6f-8f37-d9b658d46b2e +435 -0
- package/output/1707063b-7c0a-4572-9526-f7db2f7bbc49 +162 -0
- package/output/1ed588e1-2604-4e33-9685-722b03f66374 +89 -0
- package/output/2b1c0d09-40f7-4151-a053-11391f775ece +33 -0
- package/output/336b6a5a-f383-4d6c-8fe5-54c9a918c4c0 +264 -0
- package/output/37b77a0a-e233-405a-93f5-a60a808eee35 +72 -0
- package/output/3ac660cb-9503-4e88-8939-5aee30c98351 +24 -0
- package/output/5bc1b19a-8350-48b3-aa19-8073561ad45b +109 -0
- package/output/765976b5-7790-497b-8634-4be1d4770e16 +111 -0
- package/output/90f2cb44-90ab-40b7-a736-02bfb83a314c +1167 -0
- package/output/99a7b0c5-f9de-403c-95ec-eba3d700a195 +49 -0
- package/output/c844b66d-0bf3-4f89-bbe1-5974f2de454b +193 -0
- package/output/cd6299f7-54bb-4160-8735-16e629422a57 +193 -0
- package/output/d462cfca-0a39-4b65-8430-4eae35edbb76 +27 -0
- package/output/daafaad2-2570-43da-8e9e-f95a1b29ca17 +12 -0
- package/output/e45ef6bf-6c30-4fb2-9efc-a1984e5dc530 +84 -0
- package/output/sub/05009ca9-cb39-4356-8f24-c0db39cb4661 +64 -0
- package/output/sub/0b903359-2337-4ad9-adef-e77b69142581 +328 -0
- package/output/sub/18f0fae1-b7ca-40ea-b725-4e69404429dc +109 -0
- package/output/sub/232ae8ce-5ec3-4737-a18e-077774b84b1e +940 -0
- package/output/sub/34f4d4af-812e-4e56-a6dd-deb96e7f605c +3 -0
- package/output/sub/44331753-a264-40a4-b86f-eafd676b3da0 +509 -0
- package/output/sub/4bac355b-24f0-49e7-a317-e4f1cad63c79 +65 -0
- package/output/sub/4d6663a2-e93a-402e-89f8-a47cccc0c8cf +76 -0
- package/output/sub/5771c956-25bf-4714-bc2e-65959c9156d9 +52 -0
- package/output/sub/6ff91a18-494e-4ffc-a33b-b9fd2c36f43f +42 -0
- package/output/sub/81e4a2b0-05e2-4013-bd41-14b144979d91 +0 -0
- package/output/sub/99ef1497-0b94-490f-b9a0-f54b0e64194d +6 -0
- package/output/sub/9a33b8cc-101a-4f6a-9852-115595cd166b +172 -0
- package/output/sub/9c060d29-39a2-432b-b06b-b0bd91989a52 +1159 -0
- package/output/sub/a45b383c-d894-4480-8322-9c5d028722e3 +9 -0
- package/output/sub/b875bfe4-3c1e-4a8f-a56c-27a48ab874ca +438 -0
- package/output/sub/b8cbb8f9-f702-4a43-943c-02a6e39683d5 +222 -0
- package/output/sub/e339a686-bbb1-41d9-b6b5-18111e72a68c +1392 -0
- package/output/sub/e7931a8e-45ca-444a-8d6f-e6fed9415c26 +110 -0
- package/output/sub/e859552b-c597-49ed-9ede-fab320fafd87 +150 -0
- package/output/sub/f4237e72-fdce-44a4-b62c-659dce24b1ee +107 -0
- package/output/sub/ff7ea97c-55ac-471c-902f-b7a7bd101ee6 +0 -0
- package/package.json +31 -0
- package/src/cmds/generate.ts +54 -0
- package/src/index.ts +22 -0
- package/src/lib/nomd/cvter.ts +143 -0
- package/src/lib/nomd/nomd.ts +88 -0
- package/src/lib/nosm/default.ts +0 -0
- package/src/lib/nosm/nosm.ts +3 -0
- package/src/lib/notion/client.ts +59 -0
- package/src/lib/notion/object.ts +176 -0
- package/src/lib/notion/request.ts +42 -0
- package/tsconfig.json +35 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
|
|
2
|
+
# What is hash
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
## Prop of hash
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
# Implement hash table
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# Dive into sha256
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
## Implement Blockchain
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
## **Merkle Tree**
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
# Reference
|
|
33
|
+
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
# Intro
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
本篇主要 follow 书籍 **Fluent Python** ,对python的现代优雅实现进行汇总学习,由于语法检查器和python本身的发展,有些书籍中的不足之处或是不到位的地方都会在笔者的Elegant python中进行补充。
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
# None 的静态类型警告
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
你可能会写出类似以下的代码
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
def step(context: Context = None):
|
|
19
|
+
context = context or Context.new()
|
|
20
|
+
"""
|
|
21
|
+
code snippet
|
|
22
|
+
"""
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
程序顺利运行了
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
但是LSP会毫不留情地给你一个错:”Expression of type "None" cannot be assigned to parameter of type [Context]”
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
你愤懑不平,抱怨LSP是如何迂腐而不智能,连这样简单的代码逻辑都无法理清
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
但是我们可以
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from typing import Union
|
|
40
|
+
def step(context: Union[Context, None] = None):
|
|
41
|
+
context = context or Context.new()
|
|
42
|
+
"""
|
|
43
|
+
code snippet
|
|
44
|
+
"""
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
或者
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from typing import Optional
|
|
53
|
+
def step(context: Optional[Context] = None):
|
|
54
|
+
context = context or Context.new()
|
|
55
|
+
"""
|
|
56
|
+
code snippet
|
|
57
|
+
"""
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
是的,it’s boring but this is the way
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
# Fluent Python
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
## abstract
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
I don’t like meta class in Python,these shit makes your code unexplicit,which I despise a lot. 除了一些 asyncio 的场景下会对异步元编程进行简单总结,其余的相关内容将跳过。
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
## ch2 序列组成的数组
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
## 摘要
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
作者会将主要精力放在第五、七、八、九章中,运算符的重载等内容对于本人来说实在不算一种优秀的编程习惯。有些人可能很喜欢元编程,但是本人更加青睐函数化,这样更加直观,通过不同的函数命名也会使得代码更加易于维护,而不是通过 `tree sitter` 去给自己没事找事。观后感不会明确区分章节,只会在思路和概念上进行区分。
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
## 列表
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
### Numpy的技巧
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
在NumPy 中,`...` 用作多维数组切片的快捷方式。如果 `x` 是四维数组,那么 `x[i, ...]` 就是 `x[i, :, :, :]` 的缩写。
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
### 用 `*` 来处理多余的元素
|
|
92
|
+
|
|
93
|
+
- `*`运算符可以把一个可迭代对象拆开作为函数的参数
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
>>> divmod(20, 8)
|
|
97
|
+
(2, 4)
|
|
98
|
+
>>> t = (20, 8)
|
|
99
|
+
>>> divmod(*t)
|
|
100
|
+
(2, 4)
|
|
101
|
+
>>> quotient, remainder = divmod(*t)
|
|
102
|
+
>>> quotient, remainder
|
|
103
|
+
(2, 4)
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
### 用 `*` 来处理剩下的元素
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
在 `Python` 中,函数用 `*args` 来获取不确定数量的参数是一种经典写法。
|
|
112
|
+
于是 Python 3 里,这个概念被扩展到了平行赋值中:
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
>>> a, b, *rest = range(5)
|
|
117
|
+
>>> a, b, rest
|
|
118
|
+
(0, 1, [2, 3, 4])
|
|
119
|
+
>>> a, b, *rest = range(3)
|
|
120
|
+
>>> a, b, rest
|
|
121
|
+
(0, 1, [2])
|
|
122
|
+
>>> a, b, *rest = range(2)
|
|
123
|
+
>>> a, b, rest
|
|
124
|
+
(0, 1, [])
|
|
125
|
+
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
在平行赋值中,`*` 前缀只能用在一个变量名前面,但是这个变量可以出现在赋值表达式的任意位置:
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
>>> a, *body, c, d = range(5)
|
|
134
|
+
>>> a, body, c, d
|
|
135
|
+
(0, [1, 2], 3, 4)
|
|
136
|
+
>>> *head, b, c, d = range(5)
|
|
137
|
+
>>> head, b, c, d
|
|
138
|
+
([0, 1], 2, 3, 4)
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
### 嵌套结构的元组拆包
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
metro_areas = [
|
|
148
|
+
('Tokyo','JP',36.933,(35.689722,139.691667)),
|
|
149
|
+
('Delhi NCR', 'IN', 21.935, (28.613889, 77.208889)),
|
|
150
|
+
('Mexico City', 'MX', 20.142, (19.433333, -99.133333)),
|
|
151
|
+
('New York-Newark', 'US', 20.104, (40.808611, -74.020386)),
|
|
152
|
+
('Sao Paulo', 'BR', 19.649, (-23.547778, -46.635833)),
|
|
153
|
+
]
|
|
154
|
+
print('{:15} | {:^9} | {:^9}'.format('', 'lat.', 'long.'))
|
|
155
|
+
fmt = '{:15} | {:9.4f} | {:9.4f}'
|
|
156
|
+
for name, cc, pop, (latitude, longitude) in metro_areas:
|
|
157
|
+
if longitude <= 0:
|
|
158
|
+
print(fmt.format(name, latitude, longitude))
|
|
159
|
+
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
## namedtuple
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
>>> from collections import namedtuple
|
|
168
|
+
>>> City = namedtuple('City', 'name country population coordinates')
|
|
169
|
+
>>> tokyo = City('Tokyo', 'JP', 36.933, (35.689722, 139.691667))
|
|
170
|
+
>>> tokyo
|
|
171
|
+
City(name='Tokyo', country='JP', population=36.933, coordinates=(35.689722,
|
|
172
|
+
139.691667))
|
|
173
|
+
>>> tokyo.population
|
|
174
|
+
36.933
|
|
175
|
+
>>> tokyo.coordinates
|
|
176
|
+
(35.689722, 139.691667)
|
|
177
|
+
>>> tokyo[1]
|
|
178
|
+
'JP'
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
创建一个具名元组需要两个参数,一个是类名,另一个是类的各个字段的名字。后者可以是由数个字符串组成的可迭代对象,或者是由空格分隔开的字段名组成的字符串。
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
存放在对应字段里的数据要以一串参数的形式传入到构造函数中(注意,元组的构造函数却只接受单一的可迭代对象)
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
可以通过字段名或者位置来获取一个字段的信息。除了从普通元组那里继承来的属性之外,具名元组还有一些自己专有的属性。下面的示例中就展示了几个最有用的:`_fields` 类属性、类方法
|
|
189
|
+
`_make(iterable)` 和实例方法 `_asdict()`。
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
```python
|
|
193
|
+
>>> City._fields
|
|
194
|
+
('name', 'country', 'population', 'coordinates')
|
|
195
|
+
>>> LatLong = namedtuple('LatLong', 'lat long')
|
|
196
|
+
>>> delhi_data = ('Delhi NCR', 'IN', 21.935, LatLong(28.613889, 77.208889))
|
|
197
|
+
>>> delhi = City._make(delhi_data)
|
|
198
|
+
>>> delhi._asdict()
|
|
199
|
+
OrderedDict([('name', 'Delhi NCR'), ('country', 'IN'), ('population',
|
|
200
|
+
21.935), ('coordinates', LatLong(lat=28.613889, long=77.208889))])
|
|
201
|
+
>>> for key, value in delhi._asdict().items():
|
|
202
|
+
print(key + ':', value)
|
|
203
|
+
name: Delhi NCR
|
|
204
|
+
country: IN
|
|
205
|
+
population: 21.935
|
|
206
|
+
coordinates: LatLong(lat=28.613889, long=77.208889)
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
## bisect
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
`bisect(haystack, needle)` 在 `haystack`(干草垛)里搜索 `needle`(针)的位置,该位置满足的条件是,把 `needle` 插入这个位置之后,`haystack` 还能保持升序。也就是在说这个函数返回的位置前面
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
的值,都小于或等于 `needle` 的值。其中 `haystack` 必须是一个有序的序列。你可以先用 `bisect(haystack, needle)` 查找位置 `index`,再用 `haystack.insert(index, needle)` 来插入新值。但你也可用 `insort` 来一步到位,并且后者的速度更快一些。
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
### 数组保存与读取的优雅实现
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
如果我们需要一个只包含数字的列表,那么 `array.array` 比 `list` 更高效。数组支持所有跟可变序列有关的操作,包括 `.pop`、`.insert` 和 `.extend`。另外,数组还提供从文件读取和存入文件的更快的方法,如 `.frombytes` 和 `.tofile`。
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
`Python` 数组跟 `C` 语言数组一样精简。创建数组需要一个类型码,这个类型码用来表示在底层的 C 语言应该存放怎样的数据类型。比如 b 类型码代表的是有符号的字符(signed char),因此 `array('b')` 创建出的数组就只能存放一个字节大小的整数,范围从 -128 到 127,这样在序列很大的时候,我们能节省很多空间。而且 `Python` 不会允许你在数组里存放除指定类型之外的数据。
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
```python
|
|
229
|
+
>>> from array import array
|
|
230
|
+
>>> from random import random
|
|
231
|
+
>>> floats = array('d', (random() for i in range(10**7)))
|
|
232
|
+
>>> floats[-1]
|
|
233
|
+
0.07802343889111107
|
|
234
|
+
>>> fp = open('floats.bin', 'wb')
|
|
235
|
+
>>> floats.tofile(fp)
|
|
236
|
+
>>> fp.close()
|
|
237
|
+
>>> floats2 = array('d')
|
|
238
|
+
>>> fp = open('floats.bin', 'rb')
|
|
239
|
+
>>> floats2.fromfile(fp, 10**7)
|
|
240
|
+
>>> fp.close()
|
|
241
|
+
>>> floats2[-1]
|
|
242
|
+
0.07802343889111107
|
|
243
|
+
>>> floats2 == floats
|
|
244
|
+
True
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
## 高阶函数相关
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
`map`、`filter`和`reduce`,`all` 和 `any`
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
## Decorator
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
Just fully read chapter 7.
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
## Coroutine & asyncio
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
Fully read chapter 14, 16, 17 and 18
|
|
264
|
+
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
# HTML/CSS
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
[https://www.reddit.com/r/Frontend/comments/g05kc1/when_should_you_use_grid_css_instead_of_flexbox/](https://www.reddit.com/r/Frontend/comments/g05kc1/when_should_you_use_grid_css_instead_of_flexbox/)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
**some advice: you should only use tailwind css, I spit on it on first sight, now I Fucking loving it.**
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# Type/Javascript
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## Tutorial
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
[javascript tutorial](https://javascript.info/mixins)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
[ts tooling](https://www.typescriptlang.org/docs/handbook/typescript-tooling-in-5-minutes.html)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
[project config](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
## Tools
|
|
30
|
+
|
|
31
|
+
<details>
|
|
32
|
+
<summary>bundle tool</summary>
|
|
33
|
+
|
|
34
|
+
**vite** webpack
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
</details>
|
|
38
|
+
|
|
39
|
+
<details>
|
|
40
|
+
<summary>framework</summary>
|
|
41
|
+
|
|
42
|
+
hono, **react**, **remix**, nextjs, **astro**
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
</details>
|
|
46
|
+
|
|
47
|
+
<details>
|
|
48
|
+
<summary>package manager</summary>
|
|
49
|
+
|
|
50
|
+
npm **pnpm** bun yarn
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
[https://stackoverflow.com/questions/75413361/can-i-use-npx-with-pnpm](https://stackoverflow.com/questions/75413361/can-i-use-npx-with-pnpm)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
</details>
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
## All bout prototype
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
[https://stackoverflow.com/questions/18198178/null-prototype-object-prototype-and-object-create](https://stackoverflow.com/questions/18198178/null-prototype-object-prototype-and-object-create)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
[https://juejin.cn/post/7039580424170897421](https://juejin.cn/post/7039580424170897421)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
# React
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
[debouncing with useEffect](99ef1497-0b94-490f-b9a0-f54b0e64194d.md)
|
|
72
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
“for people who want to learn things, you just fuck around, and you find out” - youtube@TsodingDaily
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
# Selfie
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
我是汉堡粥 / I’m humbornjo。
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
I am a apprentice, a coder, former child, couch potato, the lord of meme, killer of salmon, shield of whiterun, and a Chinese.
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
By the way, I like the word “Illusion”, and I dont know why.
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# Masterpiece
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
People who ain’t smart enough can not see the masterpiece I publish below.
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
Actually I am planning to make a website where I can show the web design I made and the meme I collected. Maybe later.
|
|
24
|
+
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
|
|
2
|
+
> 💡 “you are no god” - Process
|
|
3
|
+
> ”yeah, god have mercy, I don’t” - OS
|
|
4
|
+
> This lyrics just come out of no where to my mind when I finally made a bite on the ECF. Alone with virtual memory, the crown of computer is granted.
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
This article is for those who want to correctly have a shallow understanding on signal. I will try to make it as simple, clean and straight-forward as possible.
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# Exception control flow
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
## process
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## process control
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
## signal
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
> A _signal_ is a small message that notifies a process that an event of some type has occurred in the system. —— CSAPP
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
To understand signal, we need to know its,
|
|
35
|
+
|
|
36
|
+
- data structure
|
|
37
|
+
- where it is stored
|
|
38
|
+
- how to send it
|
|
39
|
+
- how to receive it
|
|
40
|
+
|
|
41
|
+
### **data structure**
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+

|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
Ok, if we don’t dive too deep, that’s it. An array of **bits**. If the bit is set, the according signal is received, otherwise not received. You can google the mapping between number and signal if you are interested.
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
### where it is stored
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
> [Process control block](Process%20control%20block)
|
|
54
|
+
|
|
55
|
+
- Interprocess communication information – flags, **signals** and messages associated with the communication among independent processes;
|
|
56
|
+
|
|
57
|
+
Wow, it is stored in PCB, **not in the memory model (like stack or heap)**. And it also indicates kernel would manage it for us.
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
The place it is preserved may not explain everything, but it would let the following talk makes sense, so bite it.
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
### how to send it
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
### how to receive it
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
### in case you aren’t satisfied
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
[How do unix signals work?](https://stackoverflow.com/questions/4208004/how-do-unix-signals-work)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
### anons on Reddit argues
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
[Should you be scared of Unix signals?](https://www.reddit.com/r/programming/comments/4o027w/should_you_be_scared_of_unix_signals/)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
# Why bother reaping
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
## wait & waitpid
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
## SIGCHLD
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
## signal & sigaction
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
# CSAPP shell lab
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
|
|
2
|
+
ok,来到了看起来很厉害,实际上也很厉害的零知识证明,这里根据论文 [Why and How zk-SNARK Works](http://arxiv.org/abs/1906.07221) 梳理一遍,对于自己死去的代数记忆也进行一个妙手回春。
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
# 定义
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
**什么是 zk-SNARK?**
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
> Zero-knowledge succinct non-interactive arguments of knowledge (zk-SNARK) is the truly ingenious method of proving that something is true without revealing any other information
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# 多项式的魅力时刻
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
首先,三次多项式的等式可以被定义为:
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
$$
|
|
21
|
+
c_3x^3+c_2x^2+c_1x+c_0=0
|
|
22
|
+
$$
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
也就是说,这个多项式的阶 $d$(degree: The degree of a polynomial is determined by its greatest exponent of x)为3。更直观的,这个等式最多有三个解。
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
此时假设我们有一个场景,
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
> prover claims to know some polynomial (no matter how large its degree is) that the verifier also knows
|
|
35
|
+
|
|
36
|
+
- Verifier chooses a random value for x and evaluates his polynomial locally
|
|
37
|
+
- Verifier gives x to the prover and asks to evaluate the polynomial in question
|
|
38
|
+
- Prover evaluates his polynomial at x and gives the result to the verifier
|
|
39
|
+
- Verifier checks if the local result is equal to the prover’s result, and if so then the statement is proven with a high confidence
|
|
40
|
+
|
|
41
|
+
我们假设 verifier 选择的值是 $x=\alpha$ ,两方都知晓的多项式为 $p(x)$ ,多项式在一个限定的范围内的总共结果数为 $10^{77}$ 个,在这其中,结果不等于 $p(\alpha)$ 的数量为 $10^{77}-k,~where~k\in[1,~d],~k\in Z^+$ ,也就是说,如果 prover 如果不知道这个多项式 $p(x)$ ,那么猜中的几率只有 $\frac{k}{10^{77}}$ 。
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
> That is why polynomials are at the very core of zk-SNARK, although it is likely that other proof mediums exist as well.
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
# Non-Interactive Zero-Knowledge of a Polynomial
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
> The discussion so far has focused on a weak notion of a proof, where parties have to trust each other because there are no measures yet to enforce the rules of the protocol. For example, the prover is not required to know a polynomial, and he can use any other means available to him to come up with a correct result. Moreover, if the amplitude of the verifier’s polynomial evaluations is not large, let us say 10, the verifier can guess a number, and there is a non-negligible probability that it will be accepted.
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
所以啊,为了解决上一段中(也就是下方)protocol 的问题,我可以回顾一下多项式的定义,
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
> prover claims to know some polynomial (no matter how large its degree is) that the verifier also knows
|
|
60
|
+
|
|
61
|
+
- Verifier chooses a random value for x and evaluates his polynomial locally
|
|
62
|
+
- Verifier gives x to the prover and asks to evaluate the polynomial in question
|
|
63
|
+
- Prover evaluates his polynomial at x and gives the result to the verifier
|
|
64
|
+
- Verifier checks if the local result is equal to the prover’s result, and if so then the statement is proven with a high confidence
|
|
65
|
+
|
|
66
|
+
对于 $d = n$ 的多项式:
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
$$
|
|
70
|
+
c_nx^n+c_{n-1}x^{n-1}+...+c_1x+c_0
|
|
71
|
+
$$
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
假设,如果有人说他了解一个 $d=1$ 的多项式($c_1x+c_0$),这实际上说明的是他知道 $c_1$ 和 $c_0$ 的值。
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
现在把问题推广一下,有人说他了解一个 $d=3$ 的多项式 $p(x)$,而且他知道 $p(1) = p(2) = 0$。我们假设 $p(x) = x^3-3x^2+2x$。那么根据代数的因式分解,我们可以得到 $p(x) = (x-0)(x-1)(x-2)$。也就是剩下的一个解是 $x=0$。在这个人的视角中,$(x-1)$ 和 $(x-2)$ 是 $p(x)$ 的辅因子(cofactor)。所以,如果他想在不泄露 $p(x)$ 的情况下让别人相信他真的知道 $p(x)$,其中的一个方法就是证明 $t(x) = (x-1)(x-2)$ 可以整除 $p(x)$ ,我们把 $t(x)$ 称为 _target polynomial_ ,因此,会存在一个多项式 $h(x)$,使得:
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
$$
|
|
81
|
+
p(x) = t(x)h(x)
|
|
82
|
+
$$
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
ok,那现在我们想要验证的话,由于 $p(x)$ 是已知的,可以进行多项式除法,只要多项式除法没有余数(remainder),就说明 $p(x)$ 确实包含了 $t(x)$。下面是改进的方法:
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
> Using our polynomial identity check protocol we can compare polynomials p(x) and t(x)·h(x):
|
|
89
|
+
|
|
90
|
+
- Verifier samples a random value r, calculates t = t(r) (i.e., evaluates) and gives r to the prover
|
|
91
|
+
- Prover calculates h(x) = p(x)/t(x) and evaluates p(r) and h(r); the resulting values p,h are provided to the verifier
|
|
92
|
+
- Verifier then checks that p = t · h, if so those polynomials are equal, meaning that p(x) has t(x) as a cofactor.
|
|
93
|
+
|
|
94
|
+
基本逻辑是:
|
|
95
|
+
|
|
96
|
+
1. prover 把自己用于证明的 t(x) 发给 verifier
|
|
97
|
+
2. verifier 搞一个随机数 r,计算 t(r),并把 r 发给 prover
|
|
98
|
+
3. prover 目前“应该”知道 p(x) 和 t(x) ,所以 prover 也可以根据多项式除法得到对应的 h(x),由此得到 p(r) 和 h(r),并发送给 verifier。
|
|
99
|
+
4. verifier 验证 p(r) = t(r) · h(r)。如果成立,则 t(x) 确实为 p(r) 的 cofactor。
|
|
100
|
+
|
|
101
|
+
## QA
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
不是完全理解 verifier 和 prover 一开始都知道些什么
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
#
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|