Skip to content

Commit

Permalink
arp inncompleted, cheat, python lambda, mysql index, LSI SAS2308
Browse files Browse the repository at this point in the history
  • Loading branch information
huataihuang committed Jan 3, 2018
1 parent c25bfcb commit 0633d43
Show file tree
Hide file tree
Showing 16 changed files with 403 additions and 15 deletions.
11 changes: 11 additions & 0 deletions SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@
* [网络块设备(Network Block Device, nbd)](os/linux/storage/nbd/README.md)
* [nbd概览](os/linux/storage/nbd/nbd_overview.md)
* [网络](os/linux/network/README.md)
* [网络协议](os/linux/network/protocol/README.md)
* [ARP](os/linux/network/protocol/arp/README.md)
* ["arp incomplete"问题排查](os/linux/network/protocol/arp/arp_incomplete.md)
* [iproute2](os/linux/network/iproute2/README.md)
* [ip](os/linux/network/iproute2/ip.md)
* [可伸缩网络堆栈](os/linux/network/scaling/README.md)
Expand Down Expand Up @@ -268,6 +271,8 @@
* [磁盘I/O](database/mysql/disk_io/README.md)
* [什么时候MySQL执行IO](database/mysql/disk_io/when_does_mysql_perform_io.md)
* [如何解决MySQL IOWait过高问题](database/mysql/disk_io/fix_mysql_high_iowait.md)
* [索引](database/mysql/index/README.md)
* [检查MySQL表索引](database/mysql/index/show_index.md)
* [主从同步](database/mysql/replication/README.md)
* [如何诊断同步备库延迟](database/mysql/replication/troubleshoot_replication_slave_lag.md)
* [故障排查](database/mysql/troubleshooting/README.md)
Expand Down Expand Up @@ -304,6 +309,7 @@
* [存储](storage/README.md)
* [服务器直连存储DAS](storage/das/README.md)
* [mpt2sas](storage/das/mpt2sas/README.md)
* [LSI SAS2308控制芯片](storage/das/mpt2sas/lsisas2308.md)
* [mpt2sas驱动系统日志分析](storage/das/mpt2sas/mpt2sas_kernel_messages.md)
* [mpt2sas系统日志"0x3003010a"和奇怪的sdm磁盘设备](storage/das/mpt2sas/mpt2sas_log_info_0x3003010a_with_sdm.md)
* [mpt2sas故障排查](storage/das/mpt2sas/troubleshooting/README.md)
Expand Down Expand Up @@ -653,6 +659,8 @@
* [python列表](develop/python/startup/list.md)
* [python数组](develop/python/startup/array.md)
* [python字典](develop/python/startup/dictionary.md)
* [Python的map函数](develop/python/startup/map.md)
* [`lambda`语法糖:无需定义函数名的简便方法](develop/python/startup/lambda.md)
* [python过滤字符](develop/python/startup/strip.md)
* [python百分比](develop/python/startup/percent.md)
* [python三元运算](develop/python/startup/ternary_conditional_operator.md)
Expand Down Expand Up @@ -793,6 +801,7 @@
* [命令输出处理工具xargs](develop/shell/utilities/xargs.md)
* [文件查找工具find](develop/shell/utilities/find.md)
* [parallel利用多核CPU加速Linux命令](develop/shell/utilities/parallel.md)
* [命令速查表cheat](develop/shell/utilities/cheat.md)
* [vim](develop/vim/README.md)
* [vim结合ctags作为开发平台](develop/vim/vim_with_ctags.md)
* [将Vim打造成Python开发平台](develop/vim/vim_python_ide.md)
Expand Down Expand Up @@ -825,6 +834,8 @@
* [RESTful认证和权限机制浅析](develop/architecture/restful/restful_authentication_and_permission.md)
* [DevOps](devops/README.md)
* [基础架构工程师视角的DevOps](devops_from_infra_engineer_view.md)
* [持续集成/交付/部署](devops/ci_cd_cd/README.md)
* [持续集成/交付/部署概述](devops/ci_cd_cd/continuous_integration_delivery_deployment.md)
* [Git](devops/git/README.md)
* [git分支的新建与合并](devops/git/git_branch_create_and_merge.md)
* [git pull覆盖本地文件(完全舍弃本地文件)](devops/git/git_pull_overwrite_local_file.md)
Expand Down
1 change: 1 addition & 0 deletions database/mysql/index/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
数据库索引是加速查询的利器,但是错误的设计和使用也会导致故障。
19 changes: 19 additions & 0 deletions database/mysql/index/show_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
* 查看指定表格的索引使用`show index`命令:

```sql
show index from yourtable;
```

* 要查看特定schema的所有表格的索引,从`INFORMATION_SCHEMA`查询`STATISTICS`表:

```sql
SELECT DISTINCT
TABLE_NAME,
INDEX_NAME
FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA = 'your_schema';
```

# 参考

* [How to see indexes for a database or table?](https://stackoverflow.com/questions/5213339/how-to-see-indexes-for-a-database-or-table)
90 changes: 90 additions & 0 deletions develop/python/startup/lambda.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
> `lambda`是希腊字母的第11个字`λ`(大写`Λ`,小写`λ`
Python 中定义函数有两种方法,一种是用常规方式 def 定义,函数要指定名字,第二种是用 lambda 定义,不需要指定名字,称为 Lambda 函数。

Lambda 函数又称匿名函数,匿名函数就是没有名字的函数。有些函数如果只是临时一用,而且它的业务逻辑也很简单时,就没必要非给它取个名字不可。(否则只使用一次就建立一个函数,会带来"环境污染")

简单的lambda函数:

```python
>>> add = lambda x, y : x+y
>>> add
<function <lambda> at 0x102bc2140>
>>> add(1,2)
3
```

同于常规函数

```python
>>> def add2(x, y):
... return x+y
...
>>> add2
<function add2 at 0x102bc1c80>
>>> add2(1,2)
3
```

# 函数式编程

尽管 Python 算不上是一门纯函数式编程语言,但它本身提供了很多函数式编程的特性,像 `map``reduce``filter``sorted` 这些函数都支持函数作为参数,`lambda` 函数就可以应用在函数式编程中。

* 一个整数列表,要求按照列表中元素的绝对值大小升序排列

```python
>>> list1 = [3,5,-4,-1,0,-2,-6]
>>> sorted(list1, key=lambda x: abs(x))
[0, -1, -2, 3, -4, 5, -6]
```

排序函数`sorted`支持接收一个函数作为参数,该参数作为`sorted`的排序一句。这里按照列表元素的绝对值进行排序。以下是采用普通函数来实现的方法:

```python
>>> def foo(x):
... return abs(x)
...
>>> sorted(list1, key=foo)
[0, -1, -2, 3, -4, 5, -6]
```

但是这种方法不简洁清晰。

# 闭包

`闭包`是一个晦涩难懂的概念,这里简单粗暴理解为**`闭包就是定义在一个函数内部的函数`**,闭包使得变量即使脱离了该函数的所用域范围也依然能够被访问到。

一个用 lambda 函数作为闭包的例子:

```python
>>> def my_add(n):
... return lambda x:x+n
...
>>> add_3 = my_add(3)
>>> add_3(7)
10
```

这里的lambda函数就是一个闭包,在全局作用域范围内,`add_3(7)`可以正常执行并返回值10是因为在`my_add`局部作用域中,变量n的值在闭包的作用使得它在全局作用域也可以被访问到。

换成常规函数也可以实现闭包,只不过是这种方式稍显啰嗦:

```python
>>> def my_add(n):
... def wrapper(x):
... return x+n
... return wrapper
...
>>> add_5 = my_add(5)
>>> add_5(2)
7
```

> 如果用 lambda 函数不能使你的代码变得更清晰时,这时你就要考虑使用常规的方式来定义函数。
# 参考

* [什么时候使用Lambda函数?](https://foofish.net/lambda.html)
* [Python学习笔记(十二):lambda表达式与函数式编程](http://blog.csdn.net/mathboylinlin/article/details/9413551)
* [Lambda 表达式有何用处?如何使用?](https://www.zhihu.com/question/20125256/answer/14058285)
* [为什么匿名函数叫lambda 表达式?](https://www.zhihu.com/question/27448188/answer/36701731)
8 changes: 6 additions & 2 deletions develop/python/startup/list.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ ham
eggs
```

但是,如果list中有数字,则会导致问题
但是,如果list中有数字,则会导致打印问题

解决方法是使用`map()`转换

> `map`是Python的内置高阶函数,参数是一个函数和一个列表,将函数作用于列表的每个元素,得到一个新的列表并返回,是非常高效的一个方法。详细请参考[Python的map函数](map)
```
>>> print ', '.join(map(str, list_of_ints))
80, 443, 8080, 8081
Expand All @@ -41,4 +43,6 @@ eggs
8081
```

> 参考[Python tips - How to easily convert a list to a string for display](https://www.decalage.info/en/python/print_list)
#参考

* [Python tips - How to easily convert a list to a string for display](https://www.decalage.info/en/python/print_list)
62 changes: 62 additions & 0 deletions develop/python/startup/map.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
Python的`map`函数是一个使用方便直观而且非常常用的函数,参数是一个函数和一个列表,将函数作用于列表的每个元素,得到一个新的列表并返回。

# map函数简介

* 将一个列表的每个值平方:

```python
def square(x):
return x*x

print map(square, [1, 2, 3, 4, 5, 6, 7, 8, 9])
```

则输出结果就是

```
[1, 4, 9, 10, 25, 36, 49, 64, 81]
```

> 注意:`map()`函数不改变原有的列表,而是返回一个新的列表。
上述python程序中,`square(x)`函数可以简化成`lambda`匿名函数([`lambda`语法糖:无需定义函数名的简便方法](lambda)):

```python
print map(lambda x: x ** 2, [1, 2, 3, 4, 5, 6, 7, 8, 9])
```

* 将用户输入内容(列表)的首字母大写,后续字母小写

例如:

```
输入:['adam', 'LISA', 'barT']
输出:['Adam', 'Lisa', 'Bart']
```

```python
def format_name(s):
s1 = s[0:1].upper() + s[1:].lower()
return s1

print map(format_name, ['adam', 'LISA', 'barT'])
```

# map函数进阶

实际上,`map()`函数的参数不仅仅是2个,从第2个列表开始,可以是多个列表(多个`iterable`)

```
map(function, iterable, ...)
```

例如,提供两个列表,将相同位置的列表数据进行相加:

```python
map(lambda x, y: x + y, [1, 3, 5, 7, 9], [2, 4, 6, 8, 10])
```

# 参考

* [python map函数](http://www.cnblogs.com/superxuezhazha/p/5714970.html)
* [Python map() 函数](http://www.runoob.com/python/python-func-map.html)
31 changes: 31 additions & 0 deletions develop/shell/utilities/cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
即使Linux老鸟也会对命令行众多参数以及各种非常用案例无法精确一一背出,虽然`man`给我们带来了手册,但是太过繁复和面面俱到的手册,有时候也会消耗太多的精力。

有没有最常用的案例手册,类似手头的速查小抄:有一个python开发的工具`cheat`提供了众多命令的速查手册。

这个`cheat`是采用Python开发的工具,需要通过`pip`安装。通常发行版已经安装了`pip`模块,所以只需要通过如下命令安装`cheat`

```python
sudo pip install cheat
```

使用方法类似`man`,只要`cheat XYZ`就可以查看和XYZ命令有关的使用方法。举例,查看`tar`命令使用方法:

```
cheat tar
```

查看可用的速查表

```
cheat -l
```

获取帮助

```
cheat -h
```

# 参考

* [Cheat : 一个实用 Linux 命令示例集合](https://linux.cn/article-9193-1.html)
5 changes: 4 additions & 1 deletion devops/ci/README.md → devops/ci_cd_cd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ Martin Fowler说过,"持续集成并不能消除Bug,而是让它们非常容

# 参考

* [持续集成是什么?](http://www.ruanyifeng.com/blog/2015/09/continuous-integration.html)
* [持续集成是什么?](http://www.ruanyifeng.com/blog/2015/09/continuous-integration.html)
* [维基百科:持续交付](https://zh.wikipedia.org/zh-cn/%E6%8C%81%E7%BA%8C%E4%BA%A4%E4%BB%98)
* [如何理解持续集成、持续交付、持续部署?](https://www.zhihu.com/question/23444990)
* [谈谈持续集成,持续交付,持续部署之间的区别](http://blog.flow.ci/cicd_difference/)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,7 @@ TensorFlow的计算模型是有向图(directed graph),其中每个节点

* TensorFlow 是用于定义机器学习模型、用数据训练模型,并将模型导出供后续使用的API。主要的API均可通过Python访问。
* TensorBoard 是一个包含在任意标准TensorFlow安装中的图可视化软件。
* TensorFlow Serving 接收输入数据,并将之送入预训练的模型,然后将模型的输出结果返回。TensorFlow Serving完全是用C++编写的,其API也只能通过C++访问。
* TensorFlow Serving 接收输入数据,并将之送入预训练的模型,然后将模型的输出结果返回。TensorFlow Serving完全是用C++编写的,其API也只能通过C++访问。

> TensorFlow的灵活性之一体现在它可轻松扩展到计算性能不高的系统中。例如,它可在安卓设备以及像树莓派(Raspberry Pi)这样的微型计算机中运行。TensorFlow代码库中包含了一个在安卓系统中运行预训练模型的例程。
1 change: 1 addition & 0 deletions os/linux/network/protocol/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
网络协议学习和实践
1 change: 1 addition & 0 deletions os/linux/network/protocol/arp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ARP协议是二层交换网络的基础协议,很多局域网问题和ARP相关,在故障排查中需要具体分析。
Loading

0 comments on commit 0633d43

Please sign in to comment.