Skip to content

Instantly share code, notes, and snippets.

@wingyiu
wingyiu / lang_zh.js
Created February 11, 2014 10:13
lang_zh.js
// 网页简繁体转换
// 本js用于客户在网站页面选择繁体中文或简体中文显示,默认是正常显示,即简繁体同时显示
// 在用户第一次访问网页时,会自动检测客户端语言进行操作并提示.此功能可关闭
// 本程序只在UTF8编码下测试过,不保证其他编码有效
// -------------- 以下参数大部分可以更改 --------------------
//s = simplified 简体中文 t = traditional 繁体中文 n = normal 正常显示
var zh_default = 'n'; //默认语言,请不要改变
var zh_choose = 'n'; //当前选择
@wingyiu
wingyiu / database.py
Created August 25, 2014 08:49
take from tornado 2.x, which it now https://github.com/bdarnell/torndb
#!/usr/bin/env python
#
# Copyright 2009 Facebook
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
@wingyiu
wingyiu / Pool.py
Last active August 29, 2015 14:10 — forked from cnicodeme/Pool.py
"""
The Pool module provides some classes for managing a fixed-size thread-safe pool of functionally identical objects. One use for this is database connections, which tend to take awhile to create.
Pool
class that manages the pool of objects.
Constructor
class used to create new instances of items in the Pool.
For more details, use pydoc or read the docstrings in the code.
"""A dynamic class mixer."""
__author__ = "Andy Dustman <andy@dustman.net>"
__revision__ = "$Revision: 1.5 $"[11:-2]
import types
import new
if hasattr(types, 'ObjectType'):
classobj = type
else:
@wingyiu
wingyiu / bcompare-git.md
Last active September 2, 2015 07:00 — forked from jfromaniello/bcompare-git.md
Integrate beyond compare 4 with git

Install command line tools:

then run this:

git config --global diff.tool bc3
git config --global difftool.bc3 trustExitCode true
git config --global merge.tool bc3
@wingyiu
wingyiu / CustomCollectionFlowLayout.h
Last active September 12, 2015 13:19 — forked from toblerpwn/CustomCollectionFlowLayout.h
Sticky Headers at the top of a UICollectionView! -- // -- http://stackoverflow.com/questions/13511733/how-to-make-supplementary-view-float-in-uicollectionview-as-section-headers-do-i -- // -- still needs work around contentInsets.bottom and oddly-sized footers.
//
// CustomCollectionFlowLayout.h
// evilapples
//
// http://stackoverflow.com/questions/13511733/how-to-make-supplementary-view-float-in-uicollectionview-as-section-headers-do-i
//
//
#import <UIKit/UIKit.h>
@wingyiu
wingyiu / wsgi和tornado.md
Created November 21, 2015 12:57 — forked from nature-python/wsgi和tornado.md
python wsgi 与 tornado

#WSGI:(web server gateway interface)WEB服务器网关接口 WSGI是为python语言定义的web服务器和web应用程序或框架之间的一种简单而实用的借口。wsgi是一个web组件的接口规范,它将web组件分为三类:server,middleware,application

##wsgi server wsgi server可以理解为一个符合wsgi规范的web server,接收request请求,封装一系列环境变量,按照wsgi规范调用注册的wsgi app,最后将response返回给客户端。文字很难解释清楚wsgi server到底是什么东西,以及做些什么事情,最直观的方式还是看wsgi server的实现代码。以python自带的wsgiref为例,wsgiref是按照wsgi规范实现的一个简单wsgi server。其工作流程如下:

  1. 服务器创建socket,监听端口,等待客户端连接。
  2. 当有请求来时,服务器解析客户端信息放到环境变量environ中,并调用绑定的handler来处理请求。
  3. handler解析这个http请求,将请求信息例如method,path等放到environ中。
  4. wsgi handler再将一些服务器端信息也放到environ中,最后服务器信息,客户端信息,本次请求信息全部都保存到了环境变量environ中。
@wingyiu
wingyiu / memcached
Created August 17, 2013 06:54
memcached init script for centos
#! /bin/bash
#
# memcached: MemCached Daemon
#
# chkconfig: - 90 25
# description: MemCached Daemon
#
### BEGIN INIT INFO
# Provides: memcached
# Required-Start: $syslog
@wingyiu
wingyiu / nginx
Created August 17, 2013 06:53
Nginx Init Script for centos
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid
# post_commit and post_rollback transaction signals for Django with monkey patching
# Author Grégoire Cachet <gregoire.cachet@gmail.com>
# http://gist.github.com/247844
#
# Usage:
# You have to make sure to load this before you use signals.
# For example, create utils/__init__.py and then utils/transaction.py contening
# this gist in you project. Then add "import utils.transaction" in your project
# __init__.py file
#