西维蜀黍

【Format】csv

一个奇怪的 Scenario

如果你的机器上装了 Microsoft Excel 的话,.csv 文件默认是被 Excel 打开的。

需要注意的是,当你双击一个.csv 文件,Excel 打开它以后即使不做任何的修改,在关闭的时候 Excel 往往会提示是否要改成正确的文件格式,这个时候如果选择“是”,因为 Excel 认为.CSV 文件中的数字是要用科学记数法来表示的,Excel 会把 CSV 文件中所有的数字用科学计数来表示(2.54932E+5 这种形式),这样操作之后,只是在 Excel 中显示的时候会不正常,而 csv 文件由于是纯文本文件,在使用上没有影响;如果选择了“否”,那么会提示你以 xls 格式另存为 Excel 的一个副本。

所以,建议把 .csv 的默认打开方式改成任意一个文本编辑器。

  ...


【Software Testing】Postman 使用

Environment

环境变量 (Environment Variable)

  ...


【Performance】Linux 性能调优

定位性能瓶颈

查看操作系统负载

首先,当我们系统有问题的时候,我们不要急于去调查我们代码,这个毫无意义。我们首要需要看的是操作系统的报告。看看操作系统的CPU利用率,看看内存使用率,看看操作系统的IO,还有网络的IO,网络链接数,等等。Windows下的perfmon是一个很不错的工具,Linux下也有很多相关的命令和工具,比如:SystemTap,LatencyTOP,vmstat, sar, iostat, top, tcpdump等等 。通过观察这些数据,我们就可以知道我们的软件的性能基本上出在哪里。比如:

  1. 先看CPU利用率,如果CPU利用率不高,但是系统的Throughput和Latency上不去了,这说明我们的程序并没有忙于计算,而是忙于别的一些事,比如IO。(另外,CPU的利用率还要看内核态的和用户态的,内核态的一上去了,整个系统的性能就下来了。而对于多核CPU来说,CPU 0 是相当关键的,如果CPU 0的负载高,那么会影响其它核的性能,因为CPU各核间是需要有调度的,这靠CPU0完成)
  ...


【Python】显示对象的所有 Attribute

dir

my_list = [1, 2, 3]
dir(my_list)
# Output: ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__',
# '__delslice__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__',
# '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__',
# '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__',
# '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__',
# '__setattr__', '__setitem__', '__setslice__', '__sizeof__', '__str__',
# '__subclasshook__', 'append', 'count', 'extend', 'index', 'insert', 'pop',
# 'remove', 'reverse', 'sort']

inspect module

The inspect module also provides several useful functions to get information about live objects. For example you can check the members of an object by running:

import inspect
print(inspect.getmembers(str))
# Output: [('__add__', <slot wrapper '__add__' of ... ...
  ...


【Python】print

基础用法

print语句可以向屏幕上输出指定的文字

例如:

print 'Hello World!'
  ...


【Python】断言(assert)

Python assert(断言)用于判断一个表达式,在表达式条件为 false 的时候触发异常。

断言可以在条件不满足程序运行的情况下直接返回错误,而不必等待程序运行后出现崩溃的情况,例如我们的代码只能在 Linux 系统下运行,可以先判断当前系统是否符合条件。

语法格式如下:

assert expression

等价于:

if not expression:
    raise AssertionError

assert 后面也可以紧跟参数:

assert expression [, arguments]

等价于:

if not expression:
    raise AssertionError(arguments)

以下为 assert 使用实例:

>>> assert True     # 条件为 true 正常执行
>>> assert False    # 条件为 false 触发异常
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AssertionError
>>> assert 1==1    # 条件为 true 正常执行
>>> assert 1==2    # 条件为 false 触发异常
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AssertionError

>>> assert 1==2, '1 不等于 2'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AssertionError: 1 不等于 2
>>>
  ...


【WordPress】修改站点域名

  ...


【Python】常见错误

Variable

未定义的 variable

>>> len(abc)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'abc' is not defined

Dict

不存在的 Key

>>> a = {}
>>> a["s"]
Traceback (most recent call last):
  File "<console>", line 1, in <module>
KeyError: 's'

Function

未定义的函数

>>> fun()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'fun' is not defined
>>> a = None
>>> a()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
TypeError: 'NoneType' object is not callable
  ...


【MySQL】Lock Demo(锁实验)- Read

Locking Read

If you query data and then insert or update related data within the same transaction, the regular SELECT statement does not give enough protection. Other transactions can update or delete the same rows you just queried. InnoDB supports two types of locking reads that offer extra safety:

  1. select ... for share
  2. select ... for update

It has the potential to produce a deadlock, depending on the isolation level of the transaction. The opposite of a non-locking read.

  ...


【Python】Basics - 特殊变量(Special Variables)

  ...