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
#日志 | |
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') | |
#app handler's log | |
handler_logger = logging.getLogger('handler') | |
handler_logger.setLevel(logging.DEBUG) | |
handler_fh = logging.FileHandler(log_dir+'/handler.log') | |
handler_fh.setLevel(logging.DEBUG) | |
handler_fh.setFormatter(formatter) | |
handler_logger.addHandler(handler_fh) |
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 | |
#coding=utf-8 | |
from functools import wraps | |
import errno | |
import os | |
import signal | |
class TimeoutError(Exception): | |
pass |
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
#!/bin/bash | |
# Copyright 2013 Percona LLC and/or its affiliates | |
set -e | |
if [ -z "$3" ]; then | |
echo "rename_db <server> <database> <new_database>" | |
exit 1 | |
fi | |
db_exists=`mysql -h $1 -e "show databases like '$3'" -sss` | |
if [ -n "$db_exists" ]; then | |
echo "ERROR: New database already exists $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
/** | |
* 对日期进行格式化, | |
* @param date 要格式化的日期 | |
* @param format 进行格式化的模式字符串 | |
* 支持的模式字母有: | |
* y:年, | |
* M:年中的月份(1-12), | |
* d:月份中的天(1-31), | |
* h:小时(0-23), | |
* m:分(0-59), |
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
#! /bin/sh | |
# chkconfig: 2345 55 25 | |
# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and | |
# run 'update-rc.d -f nginx defaults', or use the appropriate command on your | |
# distro. For CentOS/Redhat run: 'chkconfig --add nginx' | |
### BEGIN INIT INFO | |
# Provides: nginx | |
# Required-Start: $all | |
# Required-Stop: $all |
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
crontab -l > cron.tmp | |
echo "0 0 */1 * * /path/to/script.sh" >> cron.tmp | |
crontab cron.tmp | |
rm -f cron.tmp |
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
filename = "%s_attack_report.xls" % file_to_download | |
f = open(filename, "r") | |
self.set_header('Content-Type', 'text/csv') | |
self.set_header('Content-Disposition', 'attachment; filename=' + filename + '') | |
self.write(f.read()) |
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 config | |
import logging | |
from logging.handlers import TimedRotatingFileHandler | |
logger = logging.getLogger(config.LOG_NAME) | |
logfile = '%s/%s' % (config.LOG_BASE_PATH, config.LOG_FILENAME) | |
fileTimeHandler = TimedRotatingFileHandler(logfile, "midnight", 1) | |
fileTimeHandler.suffix = "%Y%m%d.log" # 设置切分后日志文件名格式 |
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 type="text/javascript"> | |
$(document).ready(function(){ | |
$.ajax({ | |
url: "/ajax_url", | |
type: "POST", | |
data: { | |
"dataname": data | |
}, | |
dataType: "json", | |
success:function(data_info){ |
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 | |
import sys | |
pid = str(os.getpid()) | |
pidfile = "/tmp/pidfilename.pid" | |
if os.path.isfile(pidfile): | |
print "%s already exists, exiting" % pidfile | |
sys.exit() | |
else: |
NewerOlder