Skip to content

Instantly share code, notes, and snippets.

@lyhapple
lyhapple / settings.py
Created May 27, 2013 05:03
django settings.py LOGGING config and formatter
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format':
"""level: %(levelname)s
time: %(asctime)s
module : %(module)s
function:%(funcName)s
@lyhapple
lyhapple / views_idata.py
Last active December 17, 2015 18:48
带参数装饰器函数例子-计算出最大列宽
def deco_set_max_field_width(tmpl=""):
def render(func):
def wrapper(req, *args, **kwargs):
output = func(req, *args, **kwargs)
if not isinstance(output, dict):
return output
tpl = tmpl
if output and output.has_key("tpl"):
tpl = output["tpl"]
fields_cn = output["fields_cn"]
@lyhapple
lyhapple / password.py
Last active December 17, 2015 22:49
使用AES算法,对用户输入的密码进行加解密.
#coding=utf-8
# Created with PyCharm.
# Author: liyinhui
# Date: 13-5-31
# Time: 下午1:49
# 基于PyCrypto库实现
import base64
from Crypto.Cipher import AES
iv = "fedcba9876543210"
@lyhapple
lyhapple / password_openssl.py
Created May 31, 2013 13:47
基于m2crypto库的用户密码加解密
#coding=utf-8
# Created with PyCharm.
# Author: liyinhui
# Date: 13-5-31
# Time: 下午8:19
# 基于m2crypto库
import base64
from M2Crypto import EVP
@lyhapple
lyhapple / rzrk_portal.js
Last active April 3, 2019 02:40
jquery-validate插件:1汉化提示,2常用的扩展验证
jQuery.extend(jQuery.validator.messages, {
required:"请输入此项",
remote:"请修正该字段",
email:"请输入正确格式的电子邮件",
url:"请输入合法的网址",
date:"请输入合法的日期",
dateISO:"请输入合法的日期 (ISO).",
number:"请输入合法的数字",
digits:"只能输入整数",
creditcard:"请输入合法的信用卡号",
@lyhapple
lyhapple / form_valid.js
Created June 3, 2013 08:33
用户注册表单验证,包含名称唯一性校验
createAccountFormValid.validate({
errorElement:"span",
rules:{
username:{
required:true,
digits:true,
minlength:5,
maxlength:20,
remote:{
url:"/account/exists/",
@lyhapple
lyhapple / details_to_idata.py
Created July 4, 2013 07:13
相同库中,表结构类似的两个表的数据复制
#coding=utf-8
# Created with PyCharm.
# Author: liyinhui
# Date: 13-7-3
# Time: 上午10:33
#
from _mysql import IntegrityError
import logging
import traceback
import MySQLdb
@lyhapple
lyhapple / views.py
Created August 16, 2013 08:41
求高手把此函数重构。
def api(request, cate_pinyin, title):
response = {"success": False, "msg": "", "code": "", "result": {}}
article_class = ARTICLE_CLASS_MAPPING.get(cate_pinyin, None)
if not article_class:
response["code"] = 404
response["msg"] = CATEGORY_DOES_NOT_EXIST["error"]
else:
title = urllib.unquote(title)
if cate_pinyin == "renwu":
articles = article_class.objects.filter(name=title)
@lyhapple
lyhapple / init_article_index.py
Created August 30, 2013 05:19
从mssql数据库获取所有数据,向ES搜索引擎中插入初始化索引,还需要优化,最好使用批量插入的方式创建索引
#coding=utf-8
"""
百科ES搜索引擎初始化模块
"""
import datetime
import pyes
import pymssql
__author__ = 'lyhapple'
@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