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:
@bdarnell
bdarnell / django_tornado_handler.py
Created October 29, 2010 18:59
django_tornado_handler.py
# NOTE: This code was extracted from a larger class and has not been
# tested in this form. Caveat emptor.
import django.conf
import django.contrib.auth
import django.core.handlers.wsgi
import django.db
import django.utils.importlib
import httplib
import json
import logging
@manzke
manzke / TailorWebSocketServlet.java
Created June 12, 2011 21:04
Jetty 7+8 Web Socket Example
package de.devsurf.html.tail;
import java.io.IOException;
import java.util.Date;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@jorgebastida
jorgebastida / ipdb.sublime-snippet
Created June 15, 2011 08:42
Sublime text 2 ipdb snippet - import ipdb; ipdb.set.trace()
<snippet>
<content><![CDATA[import ipdb; ipdb.set_trace()]]></content>
<tabTrigger>ipdb</tabTrigger>
<scope>source.python</scope>
<description>ipdb</description>
</snippet>
@lucasfais
lucasfais / gist:1207002
Created September 9, 2011 18:46
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@jorgebastida
jorgebastida / gist:1221680
Created September 16, 2011 09:37
My .gitconfig
# My .gitconfig
# C&P from http://cheat.errtheblog.com/s/git
[user]
name = NAME
email = EMAIL
[color]
ui = auto
@stefanv
stefanv / sparks.py
Created November 17, 2011 00:25
Command line sparks in Python
#!/usr/bin/python
# coding=utf-8
# Python version of Zach Holman's "spark"
# https://github.com/holman/spark
# by Stefan van der Walt <stefan@sun.ac.za>
"""
USAGE:
@chrisgeo
chrisgeo / names.list
Created January 26, 2012 03:17
TextMate or Sublime Text 2 restructured text scopes
These are all the tags from the RestructuredText.tmtheme, it honestly needs to be a little bit better to come close to VIM.
comment.line.double-dot.restructuredtext
constant.other.citation.link.restructuredtext
constant.other.footnote.link.restructuredtext
entity.name.tag.restructuredtext
markup.bold.restructuredtext
markup.heading.restructuredtext
markup.italic.restructuredtext
markup.other.command.restructuredtext
@jorgebastida
jorgebastida / gist:1886036
Created February 22, 2012 17:01
Get credit card type by number
import re
def credit_card_type(number):
"""
Return a string that represents the type of the credit card number.
Criteria:
AMEX: Starts with 34 or 37 and the length 15.
MASTERCARD: Starts with 51-55 and the length is 16.