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
# encoding: utf-8 | |
""" return 返回的是完整的结果 | |
yield 返回的是一个值""" | |
def myzip1(*seqs): | |
"""使用返回值""" | |
seqs = [list(S) for S in seqs] | |
res = [] | |
while all(seqs): |
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
#!/usr/bin/env python | |
# coding: utf-8 | |
import subprocess | |
def test(size=1024*64): | |
""" pip默认为 64k""" | |
print 'start' | |
cmd = 'dd if=/dev/urandom bs=1 count=%d 2>/dev/null' % size | |
p = subprocess.Popen(args=cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True) |
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
#!/usr/bin/env python | |
# coding: utf-8 | |
import os | |
import sys | |
from subprocess import Popen, PIPE | |
def getPidList(prog_name): | |
"""获取进程的所有PID | |
输入:进程名 |
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
DATABASES = { | |
'default': { | |
'ENGINE': 'django.db.backends.mysql', | |
'NAME': 'cmdb', | |
'USER': 'root', | |
'PASSWORD': '', | |
'HOST': '127.0.0.1', | |
'PORT': '3306', | |
} | |
} |
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
db.collection.update( | |
<query>, | |
<update>, | |
{ | |
upsert: <boolean>, | |
multi: <boolean>, | |
writeConcern: <document>, | |
collation: <document>, | |
arrayFilters: [ <filterdocument1>, ... ] | |
} |
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
update_one(filter, update, upsert=False, bypass_document_validation=False, collation=None, array_filters=None, session=None) | |
Update a single document matching the filter. | |
>>> for doc in db.test.find(): | |
... print(doc) | |
... | |
{u'x': 1, u'_id': 0} | |
{u'x': 1, u'_id': 1} | |
{u'x': 1, u'_id': 2} | |
>>> result = db.test.update_one({'x': 1}, {'$inc': {'x': 3}}) |
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
import json | |
# some JSON: | |
x = '{ "name":"John", "age":30, "city":"New York"}' | |
# parse x: | |
y = json.loads(x) | |
# the result is a Python dictionary: | |
print(y["age"]) |
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
# 行迭代 | |
# while 循环法 | |
while read line;do | |
echo $line; | |
done < file.txt | |
# 命令行法 | |
cat file.txt | (while read line;do echo $line;done) | |
# awk法 |
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
function check_status() { | |
local app_name=$1 | |
local app_port=$2 | |
app_port_c=$(ss -antu | grep -c $app_port) | |
app_name_c=$(ps -ef | grep $app_name | grep -vc grep) | |
echo | |
} |
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
awk '{$5~/status/}{now=strftime("%T", $3/10000000);print now}' ky | sort | uniq -c | awk 'BEGIN{sum=0;count=0}{sum+=$1;count++}END{print sum/count}' |
OlderNewer