forked from huataihuang/cloud-atlas-draft
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
arp inncompleted, cheat, python lambda, mysql index, LSI SAS2308
- Loading branch information
1 parent
c25bfcb
commit 0633d43
Showing
16 changed files
with
403 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
数据库索引是加速查询的利器,但是错误的设计和使用也会导致故障。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
网络协议学习和实践 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ARP协议是二层交换网络的基础协议,很多局域网问题和ARP相关,在故障排查中需要具体分析。 |
Oops, something went wrong.