Skip to content

Instantly share code, notes, and snippets.

# python
# 企业名称正则:只允许汉字,数字,字母
re.match(u'^[a-zA-Z0-9\u4e00-\u9fa5]{4,50}$', u'0Aa_测试').group()
@lyhapple
lyhapple / gist:3b4cb50c865673b750e65bc58e8b9eb5
Created November 28, 2017 03:29
django自动注入app中间件
# 限制条件:中间件类名必须以Middleware结尾
APP_ROOT = os.path.join(BASE_DIR, 'app')
APP_DIR_LIST = os.listdir(APP_ROOT)
APPS = {} # {'account': '/var/test/account'}
for app_name in APP_DIR_LIST:
if app_name == 'tpl':
continue
app = os.path.join(APP_ROOT, app_name)
@lyhapple
lyhapple / gist:6ae476eed86bd5d345fa1dc793062bde
Last active November 28, 2017 03:29
django自动导入app自定义配置
import os
import importlib
APP_ROOT = os.path.join(BASE_DIR, 'app')
APP_DIR_LIST = os.listdir(APP_ROOT)
APPS = {} # {'account': '/var/test/account'}
for app_name in APP_DIR_LIST:
if app_name == 'tpl':
continue
@lyhapple
lyhapple / ajax_upload.py
Last active August 29, 2015 14:20
python ajax upload
class LocalUploadBackend(object):
BUFFER_SIZE = 10485760 # 10MB
def __init__(self,path,ext= '.bak'):
self.path = path
self.extension = ext
self.md5sum = None
def setup(self, filename):
@lyhapple
lyhapple / xvfb-init
Last active July 14, 2016 15:57 — forked from maxivak/xvfb-init
#!/bin/bash
# xvfb - this script starts and stops Xvfb
#
# chkconfig: 345 95 50
# description: Starts xvfb on display 99
# processname: Xvfb
# pidfile: /var/log/xvfb/xvfb.pid
# Source function library.
@lyhapple
lyhapple / 动态为表单的某些字段添加或移除验证
Last active August 29, 2015 14:12
使用jquery validate插件动态为表单的某些字段添加或移除验证
//add
$( "#myinput" ).rules( "add", {
required: true,
minlength: 2,
messages: {
required: "Required input",
minlength: jQuery.format("Please, at least {0} characters are necessary")
}
});
@lyhapple
lyhapple / 转换文件编码
Created June 30, 2014 04:26
尝试转换文件编码,默认转换成utf-8编码
#coding=utf-8
import codecs
import os
import shutil
import chardet
def convert_encoding(file_path, target_encoding="utf-8"):
"""
尝试转换文件编码,默认转换成utf-8编码
class DataRestore(object):
def __init__(self, request):
"""
数据恢复类
系统配置--数据恢复页面主要功能: 上传--备份恢复前的--解压覆盖
"""
self.request = request
self.uploadFileInputName = "uploadFile"
#上传文件存储的临时目录
self.strUploadTempDir = os.path.join(settings.WebTempDir, "dw-cbv4datarestore", pubfun.getTimestampStr())
@lyhapple
lyhapple / rename_file.py
Created December 16, 2013 08:55
rename file name
#coding=utf-8
__author__ = 'lyhapple'
import os
dir_path = '%s' % u'D:\\迅雷下载\\'
for name in os.listdir(dir_path):
@lyhapple
lyhapple / init_article_index.py
Created September 13, 2013 00:50
多线程对同步队列进行操作,创建ES索引的例子,使用生产者与消费者的数据模型进行处理。
#coding=utf-8
"""
百科ES搜索引擎初始化模块
"""
from Queue import Queue
import datetime
import time
import threading
import traceback
import pyes