Skip to content

Instantly share code, notes, and snippets.

# Author: Jacob Kristhammar, 2010
#
# Updated version of websocket.py[1] that implements latest[2] stable version
# of the websocket protocol.
#
# NB. It's no longer possible to manually select which callback that should
# be invoked upon message reception. Instead you must override the
# on_message(message) method to handle incoming messsages.
# This also means that you don't have to explicitly invoke
# receive_message, in fact you shouldn't.
"""
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:
@asmallteapot
asmallteapot / brainerd.py
Created January 24, 2011 15:42
Simple Markdown server in Python. Assumes you have Markdown files in ~/Text. Access ~/Text/Hello.mdown at http://localhost:5000/w/Hello.
#!/usr/bin/env python
# -*- coding: utf8 -*-
from flask import Flask, redirect, url_for
from markdown import markdown
import os
import re
# create the app
# TODO: load config/template from files, with fallbacks
@darktable
darktable / app.yaml
Created March 16, 2011 19:10
GAE: App.yaml designed for serving a static site on Google App Engine (Python). Copy your static html and files into a folder called "static" next to app.yaml. Contains a bunch of mimetype declarations from html5boilerplate's .htaccess. May not be neces
application: you-app-name-here
version: 1
runtime: python
api_version: 1
default_expiration: "30d"
handlers:
- url: /(.*\.(appcache|manifest))
mime_type: text/cache-manifest
@joshuapowell
joshuapowell / HTML5 Stub
Created April 12, 2011 04:53
A generic & empty HTML5 page structure.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="author" content="" />
<meta name="copyright" content="" />
<meta name="robots" content="index, follow" />
@robcowie
robcowie / tornado_socket_server.py
Created May 16, 2011 15:48
Simple example of creating a socket server with Tornado
import errno
import functools
import socket
from tornado import ioloop, iostream
class Connection(object):
def __init__(self, connection):
self.stream = iostream.IOStream(connection)
self._read()
@certik
certik / gist:994243
Created May 26, 2011 22:25
Fortran epsilon test
program test
implicit none
integer, parameter :: dp = 8
real(dp) :: a, b
a = 1.0_dp
b = a + epsilon(1.0_dp)
print *, "First we show, that we have two different 'a' and 'b':"
print *, "a == b:", a == b, "b-a:", b-a
print *, "using (es22.15)"
print "(es22.15)", a
@bdarnell
bdarnell / fdserver.py
Created July 9, 2011 20:41
Demonstration of sharing file descriptors across processes
#!/usr/bin/env python
"""This is a demonstration of sharing file descriptors across processes.
It uses Tornado (need a recent post-2.0 version from github) and the
multiprocessing module (from python 2.6+). To run it, start one copy
of fdserver.py and one or more copies of testserver.py (in different
terminals, or backgrounded, etc). Fetch http://localhost:8000 and
you'll see the requests getting answered by different processes (it's
normal for several requests to go to the same process under light
load, but under heavier load it tends to even out).
@certik
certik / README.md
Created July 20, 2011 22:12
C vs Fortran benchmark

On my machine, the timings are:

Fortran:

$ time ./a.out 
   249999999500000000

real	0m0.510s
user	0m0.510s
sys	0m0.000s
@soemarko
soemarko / theme.html
Created November 26, 2011 16:18
embed github gist to tumblr
<!-- Add the following lines to theme's html code right before </head> -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script src="http://static.tumblr.com/fpifyru/VCxlv9xwi/writecapture.js"></script>
<script src="http://static.tumblr.com/fpifyru/AKFlv9zdu/embedgist.js"></script>
<!--
Usage: just add <div class="gist">[gist URL]</div>
Example: <div class="gist">https://gist.github.com/1395926</div>
-->