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 | |
from tornado.httpclient import AsyncHTTPClient | |
def handle_request(response): | |
'''callback needed when a response arrive''' | |
if response.error: | |
print("Error:", response.error) | |
else: | |
print('called') | |
print(response.body) |
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.web | |
import tornado.gen | |
from tornado.httpclient import AsyncHTTPClient | |
class GenAsyncHandler(tornado.web.RequestHandler): | |
@tornado.gen.coroutine | |
def get(self): | |
http_client = AsyncHTTPClient() | |
response = yield http_client.fetch("http://ip.jsontest.com") | |
print(response) |
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 asyncio | |
@asyncio.coroutine | |
def factorial(name, number): | |
f = 1 | |
for i in range(2, number+1): | |
print("Task %s: Compute factorial(%s)..." % (name, i)) | |
yield from asyncio.sleep(1) | |
f *= i | |
print("Task %s: factorial(%s) = %s" % (name, number, f)) |
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
# Null Object Pattern | |
class AbstractLogging: | |
def Log(self, msg): | |
pass | |
from time import asctime, localtime | |
class RealLogging(AbstractLogging): | |
def Log(self, msg): | |
print 'Logged at', asctime(localtime()), msg |
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
package API::ReviewBoard; | |
use strict; | |
use warnings; | |
use LWP; | |
use HTTP::Cookies; | |
use Carp qw(croak); | |
use Params::Validate qw[validate OBJECT SCALAR ARRAYREF]; | |
use Data::Dumper; | |
use vars qw( @EXPORT @ISA ); |
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
## Torando Web Server hello World | |
import tornado.ioloop | |
import tornado.web | |
class Hello(tornado.web.RequestHandler): | |
def get(self): | |
self.write("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
mport tornado.ioloop | |
import tornado.web | |
class Hello(tornado.web.RequestHandler): | |
def get(self): | |
self.write("Hello, world") | |
class User(tornado.web.RequestHandler): | |
def get(self, username,designation): | |
self.get_arguments(username, strip=True) |
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 tornado.web | |
import time | |
## MongoDB | |
import pymongo | |
from pymongo import Connection | |
conn = Connection() | |
db=conn['library'] | |
collection = db['articles'] |
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>{{ title }}</title> | |
</head> | |
<body> | |
<table border="1"> | |
{% for key,value in dict.items() %} | |
<tr> | |
<td>{{ key }}</td> | |
<td>{{ value }}</td> |
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
{%extends "templateinheritance.html" %} | |
{% block header %} | |
<table border="1"> | |
<tr> | |
<td>Article2</td> | |
<td>Author2</td> | |
</tr> | |
{% end %} |
OlderNewer