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/python | |
import logging | |
from logging.handlers import RotatingFileHandler | |
from flask import Flask, request, jsonify | |
from time import strftime | |
import traceback | |
app = Flask(__name__) |
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
sudo apt-get update # Fetches the list of available updates | |
sudo apt-get upgrade # Strictly upgrades the current packages | |
sudo apt-get dist-upgrade # Installs updates (new ones) |
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 logging | |
class LogHandler(object): | |
format = '%(levelname)s %(message)s' | |
files = { | |
'ERROR': 'error.log', | |
'CRITICAL': 'error.log', | |
'WARN': 'warn.log', | |
} | |
def write(self, msg): |
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 logging, sys | |
class SingleLevelFilter(logging.Filter): | |
def __init__(self, passlevel, reject): | |
self.passlevel = passlevel | |
self.reject = reject | |
def filter(self, record): | |
if self.reject: | |
return (record.levelno != self.passlevel) |
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
# Show the size of all the directories in the current directory and sort them by size. | |
du -h --max-depth=1 | sort -hr | |
# Find Out Which Process Is Listening Upon a Port | |
netstat -tulpn | |
# find all files containing specific text on Linux | |
grep -rnw '/path/to/somewhere/' -e 'pattern' | |
# log CPU load | |
while true; do uptime >> uptime.log; sleep 1; done |
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
# coding=utf-8 | |
# 详细语法说明见 https://www.python.org/dev/peps/pep-0318/#current-syntax | |
# 通过装饰器能够获取到调用函数的参数,函数执行的返回值,能够直接运行所装饰的函数 | |
def checkType(*acceptedType): # 检查传入函数的参数类型 | |
print 'calling checkType with %s'%str(acceptedType) | |
def warpper(fun): ## fun为下一个要执行的函数,可以把fun(fun1(fun2...))看作整体 | |
print fun.__name__ | |
def anotherFun(*calledArgs): ## 最外层函数的参数 此处为 传入a的参数 | |
print calledArgs ## | |
for i,j in zip(acceptedType, calledArgs): |
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
# from https://stackoverflow.com/questions/7499767/temporarily-disable-auto-now-auto-now-add | |
# my model | |
class FooBar(models.Model): | |
title = models.CharField(max_length=255) | |
updated_at = models.DateTimeField(auto_now=True, auto_now_add=True) | |
# my tests | |
foo = FooBar.objects.get(pk=1) |