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
class CacheBaseHandler(tornado.web.RequestHandler): | |
def prepare(self): | |
cached = self.application.db.cache.find_one({"slug": self.request.path}) | |
if cached is not None: | |
self.write(cached["content"]) | |
self.finish() | |
def render_string(self, template_name, **kwargs): | |
html_generated = \ |
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
from twisted.internet import reactor | |
from twisted.web import proxy, http | |
import datetime | |
import pymongo | |
db = pymongo.Connection()['proxy'] | |
class LoggingProxyRequest(proxy.ProxyRequest): | |
def process(self): |
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
db.grades.aggregate({ | |
'$group': {'_id': '$student_id'}}).forEach(function(i) { | |
var x = db.grades.find({ student_id: i._id, type: 'homework' }).sort({ score: 1 })[0]; | |
db.grades.remove({ _id: x._id }); | |
} | |
); |
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
from datetime import timedelta | |
def get_track(): | |
name = raw_input('Enter track name: ') | |
time = raw_input('Enter track time (in minutes): ') | |
return name, time | |
tracks = [] |
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 toro | |
from tornado import ioloop, gen, web | |
q = toro.JoinableQueue() | |
@gen.engine | |
def consumer(): |
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
<html> | |
<body> | |
<p> | |
Current user: <strong>{{ current_user }}</strong> | |
</p> | |
<a href="/logout">Logout</a> | |
</body> | |
</html> |
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
greeting = 'Hello, World' |
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
<html> | |
<head> | |
<title>TornadoMail Demo</title> | |
</head> | |
<body> | |
<form method="post" action="/"> | |
<input type="text" name="subject"/> | |
<input type="text" name="email"/> | |
<input type="submit" value="Send message"/> | |
</form> |
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
# -*- coding: utf-8 *-* | |
import logging | |
import motor | |
import pymongo | |
from mongolog.handlers import MongoHandler | |
from tornado import ioloop, options, web | |
from tornado.options import options as opts | |
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 tornado.ioloop | |
import email | |
from bonzo.smtpserver import SMTPServer | |
def receive_message(message): | |
print "New received message: " | |
print "From: " + message['from'] | |
print "Subject: " + message['subject'] |
OlderNewer