Skip to content

Instantly share code, notes, and snippets.

View UBarney's full-sized avatar

UBarney

  • moon
View GitHub Profile
@UBarney
UBarney / Flask - Logging Requests
Created June 28, 2017 06:14 — forked from ivanleoncz/flask_app_logging.py
Logging every request received from Flask.
#/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__)
@UBarney
UBarney / ubuntu_update_package.sh
Created July 6, 2017 02:34
ubuntu_update_package
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)
@UBarney
UBarney / gist:6bfdcc35eb25a9985cb765da368e102b
Last active July 8, 2017 12:46
log to diffierent file
import logging
class LogHandler(object):
format = '%(levelname)s %(message)s'
files = {
'ERROR': 'error.log',
'CRITICAL': 'error.log',
'WARN': 'warn.log',
}
def write(self, msg):
@UBarney
UBarney / ex.py
Created July 8, 2017 12:52
set_log_filter
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)
@UBarney
UBarney / cheatsheet.sh
Last active September 6, 2017 15:11
linux_command_line_cheatsheet
# 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
@UBarney
UBarney / playground.py
Created September 6, 2017 14:35
python 装饰器
# 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):
@UBarney
UBarney / force_updaet.py
Created March 22, 2018 06:32
force update field of auto now
# 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)