This file contains 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 | |
""" | |
@author Sunil Mallya | |
Sample code to show a parent - child like process communication model where parent listens on a port and passes the pickled file descriptor | |
to the child process to read the bytes off the socket. The communication in this snippet is via a Queue which is thread/process safe | |
Just to be clear, the parent process is still accepting the connection and we are sending a live fd to the child | |
""" | |
import os | |
import sys |
This file contains 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
""" | |
Dump python object | |
@author: Not sure, had this code snippet, happy to attribute to who wrote this, saving for personal use | |
""" | |
def printDict(di, format="%-25s %s"): | |
for (key, val) in di.items(): | |
print format % (str(key)+':', val) | |
def dumpObj(obj, maxlen=77, lindent=24, maxspew=600): | |
"""Print a nicely formatted overview of an object. |
This file contains 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
#Pseduo python code | |
class HttpDownload(object): | |
def __init__(self,job,ioloop): | |
self.ioloop = ioloop | |
#create async http request | |
self.http_client = tornado.httpclient.AsyncHTTPClient() | |
self.http_client.fetch(self.req, self.async_callback) | |
def async_callback(self,reponse): |
This file contains 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
''' | |
A Non blocking task scheduler and executor implemented using co routines and Tornado | |
Torando components acts as a non blocking listener and the 2 co routines scheduler and task exectutor | |
''' | |
import tornado.ioloop | |
import tornado.web | |
import tornado.httpserver | |
import tornado.gen | |
import time |
This file contains 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 | |
''' | |
Mocking Httpclient and AsyncHttpclient in Tornado Server | |
''' | |
import unittest | |
import urllib | |
import tornado.gen | |
import tornado.ioloop | |
import tornado.web |
This file contains 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
syntax on | |
filetype indent plugin on | |
setlocal tabstop=4 | |
set tabstop=4 shiftwidth=4 expandtab | |
set showmatch " highlight matching braces | |
set comments=sl:/*,mb:\ *,elx:\ */ " intelligent comments | |
set nocompatible " dont support vi stuff | |
set autoindent | |
set smartindent | |
set textwidth=80 |
This file contains 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 math | |
import stemmer | |
def irange(sequence): | |
return zip(range(len(sequence)), sequence) | |
class CosineScore(object): | |
def __init__(self,all_docs): | |
self.documents = all_docs #list all docs [doc1,doc2..] | |
self.ndocs = len(all_docs) |
This file contains 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 urllib | |
import urllib2 | |
CLOSURE_URL = "http://closure-compiler.appspot.com/compile" | |
def compile_js(contents): | |
data = { "compilation_level" : "SIMPLE_OPTIMIZATIONS", | |
"output_format" : "text", | |
"output_info" : "compiled_code", | |
"js_code" : contents |
This file contains 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
''' | |
A useful DB Connection class with both sync & async redis clients | |
It uses a threadpool to make the redis library asynchronous so as | |
to work with tornado seamlessly. There is also a retry wrapper built in | |
to retry in case of connection failures to redis server | |
Tornado 4.0 required, for the rest of the requirements check the imports | |
''' |
This file contains 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
<?xml version='1.0' encoding='UTF-8' ?> | |
<?charles serialisation-version='2.0' ?> | |
<rewriteSet-array> | |
<rewriteSet> | |
<active>true</active> | |
<name>Rewrite</name> | |
<hosts> | |
<locationPatterns> | |
<locationMatch> | |
<location> |
OlderNewer