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 os.path | |
import contextlib | |
import hashlib | |
from flask import Flask | |
from flask.helpers import safe_join | |
# Injects an "h" parameter on the URLs of static files that contains a hash of | |
# the file. This allows the use of aggressive cache settings on static files, | |
# while ensuring that content changes are reflected immediately due to the | |
# changed URLs. Hashes are cached in-memory and only checked for updates when |
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
def str_to_datetime(string): | |
return datetime.datetime.strptime(string, "%Y-%m-%d %H:%M:%S") | |
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
class PrefixLogger(object): | |
def __init__(self, prefix="", logger= logger): | |
self.logger = logger | |
self.prefix = prefix | |
self.logging_methods = {} | |
for funcname in ["debug", "info", "warning", "warn", "error", "critical", "log", "exception"]: | |
self.logging_methods[funcname] = self.wrap_log_method(self.prefix)(getattr(self.logger, funcname)) | |
@staticmethod |
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 sqlalchemy.ext.declarative import declarative_base | |
Base = declarative_base() | |
from sqlalchemy import Column, Integer, String | |
class User(Base): | |
__tablename__ = 'user' | |
id = Column(Integer, primary_key=True) | |
name = Column(String) |
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 | |
import sys,os | |
import logging | |
from logging.handlers import TimedRotatingFileHandler | |
def is_stdout_attached_to_terminal(): | |
'''判断当前进程组是不是前台进程组(主要关注stdout是否被关联到/dev/tty)''' | |
try: | |
# 如果stdout被绑定到终端设备上,则是前端进程组 | |
if os.getpgrp() == os.tcgetpgrp(sys.stdout.fileno()): |
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
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" |
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 signal | |
from functools import wraps | |
from nose.tools import nottest, with_setup | |
class TestTimeoutException(Exception): | |
pass | |
@nottest | |
def raise_timeout_exception(*args, **kwargs): |
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 | |
"""调度系统日志分析:日志统计""" | |
import multiprocessing | |
from multiprocessing import Process, Queue, Pool | |
import logging | |
import time | |
import pprint | |
import os |
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
jQuery.postJSON = function(url, args, successCall, errorCall){ | |
$.ajax({ | |
type:"post", | |
url:url, | |
data:JSON.stringify(args), | |
contentType:"application/json; charset=UTF-8", | |
success:successCall, | |
error:errorCall | |
}); | |
} |
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
{ | |
"province": [ | |
{ | |
"code": 110000, | |
"name": "北京市", | |
"py": "beijingshi" | |
}, | |
{ | |
"code": 120000, | |
"name": "天津市", |