This file contains hidden or 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
def run_with_cgi(application): | |
environ = dict(os.environ.items()) | |
environ['wsgi.input'] = sys.stdin | |
environ['wsgi.errors'] = sys.stderr | |
environ['wsgi.version'] = (1, 0) | |
environ['wsgi.multithread'] = False | |
environ['wsgi.multiprocess'] = True | |
environ['wsgi.run_once'] = True |
This file contains hidden or 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
def simple_app(environ, start_response): | |
"""Simplest possible application object""" | |
status = '200 OK' | |
response_headers = [('Content-type', 'text/plain')] | |
start_response(status, response_headers) | |
return ['Hello world!\n'] | |
import os, sys | |
from bottle import Bottle |
This file contains hidden or 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 | |
import re | |
class MappingFileError(Exception): pass | |
class SimpleParser(object): | |
"""Callable to turn path expressions into regexes with named groups. | |
This file contains hidden or 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
#from bottle src | |
class ConfigDict(dict): | |
''' A dict-subclass with some extras: You can access keys like attributes. | |
Uppercase attributes create new ConfigDicts and act as name-spaces. | |
Other missing attributes return None. Calling a ConfigDict updates its | |
values and returns itself. | |
>>> cfg = ConfigDict() | |
>>> cfg.Namespace.value = 5 |
This file contains hidden or 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
class ConfigDict(dict): | |
''' A dict-subclass with some extras: You can access keys like attributes. | |
Uppercase attributes create new ConfigDicts and act as name-spaces. | |
Other missing attributes return None. Calling a ConfigDict updates its | |
values and returns itself. | |
>>> cfg = ConfigDict() | |
>>> cfg.Namespace.value = 5 | |
>>> cfg.OtherNamespace(a=1, b=2) | |
>>> cfg |
This file contains hidden or 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 functools | |
from urllib2 import * | |
TEMPLATE_PATH = ['./', './views/'] | |
TEMPLATES = {} | |
#------------------------------------------utils------------------------------------------ | |
def tob(s, enc='utf8'): | |
return s.encode(enc) if isinstance(s, unicode) else bytes(s) |
This file contains hidden or 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/env python | |
#coding: utf-8 | |
#author: shiweifu | |
#mail : [email protected] | |
import os | |
def fork_process(cmd, args, env): | |
child_pid = os.fork() |
This file contains hidden or 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
def randstr(l): | |
s = ["chr(randint(65, 90))", #A-Z | |
"chr(randint(97, 122))", #a-z | |
"str(randint(0,9))"] #0-9 | |
return "".join([eval(s[randint(0, len(s)-1)]) for x in xrange(l)]) |
This file contains hidden or 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
#include <stdio.h> | |
#include <time.h> | |
int main(int argc, const char *argv[]) | |
{ | |
/*time_t t = time(NULL);*/ | |
time_t t = 1346122873; | |
printf("%s\n", ctime(&t)); | |
return 0; |
This file contains hidden or 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
function isUrl(s) { | |
var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/ | |
return regexp.test(s); | |
} |