Skip to content

Instantly share code, notes, and snippets.

# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Update 7 Oct 2010:
# - This example does *not* appear to work with Chrome >=6.0. Apparently,
# the WebSocket protocol implementation in the cramp gem does not work
# well with Chrome's (newer) WebSocket implementation.
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby
@denik
denik / gevent-multiprocess.py
Created August 25, 2011 04:24 — forked from notedit/gevent-multiprocess.py
gevent-multiprocess
import sys
from gevent import server
from gevent.baseserver import _tcp_listener
from gevent.monkey import patch_all; patch_all()
from multiprocessing import Process, current_process, cpu_count
def note(format, *args):
sys.stderr.write('[%s]\t%s\n' % (current_process().name, format%args))
@dcrosta
dcrosta / htmlabbrev.py
Created November 4, 2011 17:50
truncates HTML without screwing up tag nesting
import re
from HTMLParser import HTMLParser
whitespace = re.compile('(\w+)')
class HTMLAbbrev(HTMLParser):
def __init__(self, maxlength, *args, **kwargs):
HTMLParser.__init__(self, *args, **kwargs)
self.stack = []
@kracekumar
kracekumar / core.py
Created March 4, 2012 09:45
parallelpip demo
#! -*- Coding: utf-8 -*-
from gevent import monkey
monkey.patch_all()
import gevent
import time
from envoy import run
from sys import exit, argv
import subprocess
import pip
@hankchan
hankchan / ServerRack.py
Created April 9, 2012 02:42 — forked from denik/ServerRack.py
class for managing multiple servers in gevent
# Class for managing multiple servers or anything with start() and stop() methods
class ServerRack(object):
def __init__(self, servers):
self.servers = servers
def start(self):
started = []
try:
@hankchan
hankchan / upgrade_example.py
Created April 11, 2012 07:30 — forked from denik/upgrade_example.py
Upgradable WSGI server websocket example
import gevent.pywsgi
from websocket import WebSocketUpgrader
class UpgradableWSGIHandler(gevent.pywsgi.WSGIHandler):
def handle_one_response(self):
connection_header = self.environ.get('HTTP_CONNECTION', '').lower()
if connection_header == 'upgrade' and self.server.upgrade_handler:
upgrade_header = self.environ.get('HTTP_UPGRADE', '').lower()
handler = self.server.upgrade_handler(upgrade_header, self.environ)