Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f170f72

Browse files
ruicoregitbook-bot
authored andcommitted
GitBook: [master] 17 pages and one asset modified
1 parent 27a7ca0 commit f170f72

File tree

19 files changed

+338
-121
lines changed

19 files changed

+338
-121
lines changed

.gitbook/assets/Wechat.jpeg

163 KB
Loading

.gitbook/assets/book.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"plugins": ["disqus"],
3+
"pluginsConfig": {
4+
"disqus": {
5+
"shortName": "ruicore"
6+
}
7+
}
8+
}

README.md

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,14 @@
1-
## Python 使用技巧
1+
# Python 使用技巧
22

33
> This repositorie contains ancillary function which code in python3. Use it freely.
44
>
55
> Crawl web function may conatain error\(s\) as the web elements changed.
66
>
77
> If you had any idea to improve my code or you find any mistake in my file, please contact me. \(Email me at [email protected]\)
88
9-
### 1.在列表,字典,集合中根据条件筛选数据
9+
## 1.在列表,字典,集合中根据条件筛选数据
1010

11-
需求:
12-
1. 过滤 list 中大于 0 的数:[14, 0, -6, 0, -10, -8, -1, 19, -10, -16\]
13-
>
14-
2. 筛选出字典中值大于 0 的项目:{0: 9, 1: -3, 2: -8, 3: 6, 4: -4, 5: -4, 6: -7, 7: -8, 8: 7, 9: -3}
15-
>
16-
3. 筛选出集合中能被 2 整除的数:{3, 4, 9, 12, 15, 17, 19, 20}
17-
>
18-
4. 找到字典中值最小的健值对:prices = {'ACME': 45.23,'AAPL': 612.78,'IBM': 205.55,'HPQ': 37.20,'FB': 10.75}
19-
>
20-
5. 对字典排序,首先按照值排序,值相同再按照健排序 6. 对字典的健按照值排序
11+
需求: 1. 过滤 list 中大于 0 的数:\[14, 0, -6, 0, -10, -8, -1, 19, -10, -16\] > 2. 筛选出字典中值大于 0 的项目:{0: 9, 1: -3, 2: -8, 3: 6, 4: -4, 5: -4, 6: -7, 7: -8, 8: 7, 9: -3} > 3. 筛选出集合中能被 2 整除的数:{3, 4, 9, 12, 15, 17, 19, 20} > 4. 找到字典中值最小的健值对:prices = {'ACME': 45.23,'AAPL': 612.78,'IBM': 205.55,'HPQ': 37.20,'FB': 10.75} > 5. 对字典排序,首先按照值排序,值相同再按照健排序 6. 对字典的健按照值排序
2112

2213
```python
2314
list_bigger = [x for x in list_nums if x > 0]
@@ -30,7 +21,7 @@ sorted_keys = sorted(prices,prices.get)
3021
# zip 创建的对象只能访问一次
3122
```
3223

33-
### 2.命名,统计,字典
24+
## 2.命名,统计,字典
3425

3526
需求:在表格中,每一行的信息固定,为了访问某个位置的值,不使用索引
3627

@@ -92,7 +83,7 @@ for x in sample("abcdefgh", randint(3, 6)):
9283
order[x] = randint(4,10)
9384
```
9485

95-
### 3.字符串
86+
## 3.字符串
9687

9788
需求:根据多个分隔符,拆分字符串
9889

@@ -118,7 +109,7 @@ text = "07/20/2019"
118109
res = re.sub(r"(\d{2})\/(\d{2})\/(\d{4})", r"\3-\1-\2", text)
119110
```
120111

121-
### 4.遍历
112+
## 4.遍历
122113

123114
需求:同时遍历可迭代对象
124115

@@ -137,7 +128,7 @@ for x in chain(nums1, nums2, nums3):
137128
print(x)
138129
```
139130

140-
### 5.类
131+
## 5.类
141132

142133
需求:为了确保用户输入正确格式的数,强制用户使用函数进行访问;为了简介,通过 property 自动调用函数,实现「设置属性自动调用函数的效果」
143134

@@ -245,7 +236,7 @@ fun = methodcaller("get_value", 2, -1)
245236
print(fun(mc))
246237
```
247238

248-
### 6. 装饰器
239+
## 6. 装饰器
249240

250241
1. 需求:为某一个函数增加功能,不影响原来的函数
251242

@@ -319,7 +310,7 @@ for i in range(20):
319310
test()
320311
```
321312

322-
### 7. 优先队列
313+
## 7. 优先队列
323314

324315
需求:实现一个有优先级的队列
325316

@@ -339,7 +330,7 @@ class PriorityQueue(object):
339330
return heapq.heappop(self._queue)[-1] if self._queue else None
340331
```
341332

342-
### 8. 展开嵌套的 list
333+
## 8. 展开嵌套的 list
343334

344335
```python
345336
from collections.abc import Iterable
@@ -356,7 +347,8 @@ items = [1, 2, [3, 4, (5, 6), 7], 8, "temp", "core", {-1, -2, -4, -6}]
356347
for x in flatten(items):
357348
print(x)
358349
```
359-
### 9. 文件
350+
351+
## 9. 文件
360352

361353
1. 打印输出到文件中
362354

@@ -375,7 +367,7 @@ with open('somefile', 'xt') as f:
375367
f.write('Hello\n')
376368
```
377369

378-
### 10. 使用强制关键字参数
370+
## 10. 使用强制关键字参数
379371

380372
```python
381373
def recv(maxsize, *, block):
@@ -385,28 +377,26 @@ def recv(maxsize, *, block):
385377
recv(1024, True) # TypeError
386378
recv(1024, block=True) # Ok
387379
```
388-
### 11. 比较两个字典是否相等
380+
381+
## 11. 比较两个字典是否相等
389382

390383
* 键个数相等,键名一一对应,键值一一对应相等
391-
```py
392-
import json
393-
from datetime import datetime
394384

395-
from bson.json_util import default
385+
\`\`\`py
396386

387+
import json
397388

398-
def compare_2_dict(dict_1, dict_2):
399-
return (json.dumps(dict_1, default=default, sort_keys=dict.keys) ==
400-
json.dumps(dict_2, default=default, sort_keys=dict.keys))
389+
from datetime import datetime
401390

391+
from bson.json\_util import default
402392

403-
dicta = {"a": datetime.now(), "b": 2}
404-
dictb = {"a": datetime.now(), "b": 2}
393+
def compare\_2\_dict\(dict\_1, dict\_2\): return \(json.dumps\(dict\_1, default=default, sort\_keys=dict.keys\) == json.dumps\(dict\_2, default=default, sort\_keys=dict.keys\)\)
405394

406-
print(compare_2_dict(dicta, dictb))
395+
dicta = {"a": datetime.now\(\), "b": 2} dictb = {"a": datetime.now\(\), "b": 2}
407396

408-
```
397+
print\(compare\_2\_dict\(dicta, dictb\)\)
409398

399+
```text
410400
### 12. Lambda
411401
* 在 for loop 中使用 lambda,如果有赋值,请小心
412402
@@ -417,13 +407,15 @@ m = [lambda i=i: i for i in range(4)]
417407
res_t = [func() for func in t]
418408
res_m = [func() for func in m]
419409
```
420-
* res_t: [3, 3, 3, 3]
421-
* rest_m: [0, 1, 2, 3]
422410

423-
### 13. Iterator
411+
* res\_t: \[3, 3, 3, 3\]
412+
* rest\_m: \[0, 1, 2, 3\]
413+
414+
## 13. Iterator
415+
424416
* iterator 不走回头路,可以利用此特性来判断 list 是否存在于另一个 list 中
425417

426-
```py
418+
```python
427419
# a = [1,2,3]
428420
# b = [1,3,2,4,5,6]
429421
# check if all num in a is in b, ordered
@@ -433,3 +425,4 @@ def check(a, b):
433425
b = iter(b)
434426
return all(i in b for i in a)
435427
```
428+

SUMMARY.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Table of contents
2+
3+
* [Python 使用技巧](README.md)
4+
* [doc](doc/README.md)
5+
* [在服务器上生成 SSH-KEY 密钥](doc/ssh-key.md)
6+
* [monitor](doc/monitor.md)
7+
* [pyspark](doc/pyspark.md)
8+
* [docker 拷贝文件到 docker 外](doc/docker.md)
9+
* [command](doc/command.md)
10+
* [说明](usage/README.md)
11+
* [tree](usage/tree/README.md)
12+
* [Tree](usage/tree/tree.md)
13+
* [simple decorator usage](usage/decorator.md)
14+
* [5118](usage/5118/README.md)
15+
* [词语分析聚合](usage/5118/5118.md)
16+
* [Batch Read file](usage/read_file.md)
17+
* [sdk](sdk/README.md)
18+
* [load2neo4j](sdk/load2neo4j.md)
19+

doc/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# doc
2+

doc/command.md

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1+
# command
2+
13
## zsh
24

3-
On Ubuntu:
4-
apt install zsh
5+
On Ubuntu: apt install zsh
56

6-
On CentOS:
7-
dnf install zsh
7+
On CentOS: dnf install zsh
88

9-
On Ubuntu:
10-
chsh -s /usr/bin/zsh root
9+
On Ubuntu: chsh -s /usr/bin/zsh root
1110

12-
On CentOS:
13-
chsh -s /bin/zsh root
11+
On CentOS: chsh -s /bin/zsh root
1412

1513
apt install wget git
1614

1715
apt install wget git
1816

19-
wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | zsh
17+
wget [https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh](https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh) -O - \| zsh
2018

2119
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
2220

@@ -26,22 +24,17 @@ source ~/.zshrc
2624

2725
sudo tail -n 20 /var/log/nginx/error.log
2826

29-
<!-- nginx docker log-->
30-
rm -f /var/log/nginx/*
31-
nginx -s reload
27+
rm -f /var/log/nginx/\* nginx -s reload
3228

3329
## Coverage
3430

3531
`# pragma: no cover`
3632

3733
## nginx搭建自签名SSL证书
3834

39-
openssl genrsa -out server.key 2048
40-
openssl req -new -key server.key -out server.csr
41-
Common Name (e.g. server FQDN or YOUR name) []:10.10.10.10
42-
openssl x509 -req -in server.csr -signkey server.key -out server.crt
35+
openssl genrsa -out server.key 2048 openssl req -new -key server.key -out server.csr Common Name \(e.g. server FQDN or YOUR name\) \[\]:10.10.10.10 openssl x509 -req -in server.csr -signkey server.key -out server.crt
36+
37+
在 Chrome 浏览器中输入 `thisisunsafe`,直接在浏览器中输入即可 [https://cloud.tencent.com/developer/article/1160294](https://cloud.tencent.com/developer/article/1160294)
4338

44-
在 Chrome 浏览器中输入 `thisisunsafe`,直接在浏览器中输入即可
45-
https://cloud.tencent.com/developer/article/1160294
39+
~~缓存自动刷新\(v2.2 及以前版本支持\)~~
4640

47-
~~缓存自动刷新(v2.2 及以前版本支持)~~

doc/docker.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
## docker 拷贝文件到 docker 外
1+
# docker 拷贝文件到 docker 外
2+
3+
`docker cp d7908371bcab:/home/herui/baikeNode .`
24

3-
``` docker cp d7908371bcab:/home/herui/baikeNode .```

0 commit comments

Comments
 (0)