Skip to content

Instantly share code, notes, and snippets.

View pigletfly's full-sized avatar
🎯
Focusing

Bing Wang pigletfly

🎯
Focusing
  • Hangzhou
  • 06:24 (UTC +08:00)
View GitHub Profile
@pigletfly
pigletfly / dabblet.css
Created September 23, 2013 06:38
The first commented line is your dabblet’s title
/**
* The first commented line is your dabblet’s title
*/
background: #f06;
background: linear-gradient(45deg, #f06, yellow);
min-height: 100%;
margin:auto
@pigletfly
pigletfly / routing.py
Created May 19, 2014 10:03
routing for tornado
#!/usr/bin/env python
#coding=utf-8
"""
extensions.route
Example:
@route(r'/', name='index')
class IndexHandler(tornado.web.RequestHandler):
pass
@pigletfly
pigletfly / README
Created May 21, 2014 01:35 — forked from thedod/README
A simple trick against CSRF for web.py (webpy.org)
* At the GET() template, you add a hidden field called csrf_token with value "$csrf_token()"
* The POST() should have the @csrf_protected decorator
That's it.
Request for comments:
* Is this secure? Can you see any holes?
* Is there anything in [or for] web.py that does this? Am I reinvevting the wheel here?
worker_processes 2;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
use epoll;
}
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# code by from1to9
# from1to9@gmail.com
import oauth2 as oauth
import re, time
def range(start, stop=None, step=None):
result = []
s = 1
if step is not None:
s = step
if stop is not None:
while True:
if start < stop:
result.append(start)
start += s
# -*- coding: utf-8 -*-
# 2.如遇到 UnicodeEncodeError: 'ascii' codec can't encode characters in position 22-25: ordinal not in range(128)
# 增加如下3行
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
from pyquery import PyQuery as pq
# -*- coding: utf-8 -*-
# 2.如遇到 UnicodeEncodeError: 'ascii' codec can't encode characters in position 22-25: ordinal not in range(128)
# 增加如下3行
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
from pyquery import PyQuery as pq
@pigletfly
pigletfly / gist:02ead1068749ddd49ce3
Last active August 29, 2015 14:26 — forked from creotiv/gist:1217855
Multicore gevent wsgi server
import sys
from gevent import server
from gevent.baseserver import _tcp_listener
from gevent import pywsgi
from gevent.monkey import patch_all; patch_all()
from multiprocessing import Process, current_process, cpu_count
def hello_world(env, start_response):
if env['PATH_INFO'] == '/':
start_response('200 OK', [('Content-Type', 'text/html')])
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2012 Ethan Zhang<http://github.com/Ethan-Zhang>
#
# 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