Philip Thrasher
Web hacker at a private cyber security company.
""" | |
This is a simple example of WebSocket + Tornado + Redis Pub/Sub usage. | |
Do not forget to replace YOURSERVER by the correct value. | |
Keep in mind that you need the *very latest* version of your web browser. | |
You also need to add Jacob Kristhammar's websocket implementation to Tornado: | |
Grab it here: | |
http://gist.github.com/526746 | |
Or clone my fork of Tornado with websocket included: | |
http://github.com/pelletier/tornado | |
Oh and the Pub/Sub protocol is only available in Redis 2.0.0: |
from concurrent.futures import ThreadPoolExecutor | |
from functools import partial, wraps | |
import time | |
import tornado.ioloop | |
import tornado.web | |
EXECUTOR = ThreadPoolExecutor(max_workers=4) |
# from: http://www.tornadoweb.org/documentation | |
# running-tornado-in-production | |
user nginx; | |
worker_processes 1; | |
error_log /var/log/nginx/error.log; | |
pid /var/run/nginx.pid; | |
events { |
import collections | |
import json | |
import redis | |
import threading | |
from tornado import gen | |
from tornado import ioloop | |
from tornado import web | |
from tornado.options import define | |
from tornado.options import options | |
import tornadoredis |
<div id="main-container"> | |
<div id="main"> | |
<h1> | |
<img alt="scubabook logo" src="{{ static_url("img/logo.png") }}"> | |
</h1> | |
<div id="login-form"> | |
<form action="/auth/login/" method="post" id="login_form"> | |
<fieldset> | |
<label for="username">Username</label> | |
<input autocapitalize="off" autocorrect="off" class="text-input" id="username" name="username" tabindex="1" type="text" value=""> |
# http://papercruncher.com/2013/01/15/truly-async-with-tornado/ | |
import tornado.httpclient | |
import tornado.ioloop | |
import tornado.web | |
import tornado.websocket | |
import tornado.template | |
import tornado.gen | |
import tornado.autoreload | |
import time, json | |
import tornado.httpserver |
import tornado.ioloop | |
import tornado.web | |
import pika | |
from pika.adapters.tornado_connection import TornadoConnection | |
import logging | |
import logging.config | |
TORNADO_PORT = 8889 | |
RMQ_USER = 'user' |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> | |
<title> - jsFiddle demo</title> | |
<script type='text/javascript' src='http://code.jquery.com/jquery-1.8.3.js'></script> | |
<link rel="stylesheet" type="text/css" href="/css/normalize.css"> | |
<script type="text/javascript" src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script> |
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from __future__ import division, print_function | |
import emcee | |
import numpy as np | |
import matplotlib.pyplot as pl | |
np.random.seed(123) |