Skip to content

Instantly share code, notes, and snippets.

View cjgiridhar's full-sized avatar

Chetan Giridhar cjgiridhar

View GitHub Profile
@cjgiridhar
cjgiridhar / tornadomongo.py
Created August 30, 2012 11:14
Tornado - Mongo
import tornado.ioloop
import tornado.web
import urlparse
## mongodb and pymongo installation assumed
import pymongo
from pymongo import Connection
class Article(tornado.web.RequestHandler):
def initialize(self):
@cjgiridhar
cjgiridhar / tornadoreload.py
Created August 29, 2012 03:06
Tornado - AutoReload - Watch
import tornado.web
import tornado.autoreload
class Main(tornado.web.RequestHandler):
def get(self):
self.write('Main')
application = tornado.web.Application([
(r"/", Main)
])
@cjgiridhar
cjgiridhar / tornadoreload.py
Created August 28, 2012 17:15
Tornado - AutoReload
import tornado.web
import tornado.autoreload
class Main(tornado.web.RequestHandler):
def get(self):
self.write("Main")
application = tornado.web.Application([
(r"/", Main)
])
@cjgiridhar
cjgiridhar / config.py
Created August 28, 2012 14:19
Tornado - Options - 4
port="8000"
host="localhost"
databse="mydb"
user="root"
password="root"
@cjgiridhar
cjgiridhar / tornadooptions_2.py
Created August 28, 2012 14:14
Tornado - Options - 3
from tornado.options import define, options
import tornado.web
import tornado.database
define("port", default="8888")
class DBHandler(tornado.web.RequestHandler):
def get(self):
self.write("Main")
@cjgiridhar
cjgiridhar / opts.py
Created August 28, 2012 13:41
Tornado - Options - 2
from tornado.options import options,define
define("host", default="localhost", help="DB host")
define("database", default="mydb", help="DB used")
define("user", default="root", help="DB username")
define("password", default="root", help="DB Password")
define("port", default=8888)
@cjgiridhar
cjgiridhar / tornadooptions.py
Created August 28, 2012 13:35
Tornado - Options - 1
from tornado.options import define, options
import tornado.web
import tornado.database
define("host", default="localhost", help="DB host")
define("database", default="mydb", help="DB used")
define("user", default="root", help="DB username")
define("password", default="root", help="DB Password")
define("port", default=8888)
@cjgiridhar
cjgiridhar / tornadoescapeurl.py
Created August 27, 2012 12:16
Tornado - Escape - URL
import tornado.web
import tornado.escape
class Main(tornado.web.RequestHandler):
def get(self):
self.write("<br />")
self.write(tornado.escape.linkify("Linked URL: http://technobeans.com/2012/08/22/tornado-database-mysql-client-wrapper/"))
self.write("<br />")
self.write(tornado.escape.linkify("Short URL: http://technobeans.com/2012/08/22/tornado-database-mysql-client-wrapper/", shorten=True))
self.write("<br />")
@cjgiridhar
cjgiridhar / tornadojsonclient.py
Created August 26, 2012 12:24
Tornado - Escape - JSONClient
import tornado.httpclient
http = tornado.httpclient.HTTPClient()
response = http.fetch("http://localhost:8888/lang")
data = tornado.escape.json_decode(response.body)
print data['py'], data['js']
@cjgiridhar
cjgiridhar / jsonform.html
Created August 26, 2012 12:06
Tornado - Escape - JSON
<html>
<title>
JSON Example
</title>
<body>
<FORM ACTION="/blog" METHOD=POST>
Title: <input type="text" name="title">
Author: <input type="text" name="author">