Skip to content

Instantly share code, notes, and snippets.

@saghul
saghul / imapfilter.sh
Created June 12, 2011 21:41
imapfilter + expect automation
#!/bin/bash
_exit() {
echo "CTRL + C pressed, exiting."
exit 0
}
trap _exit INT
read -p "Password: " -s PASSWORD
@saghul
saghul / bogus_scope.py
Created June 16, 2011 06:46
Name binding and UnboundLocalError
from application.system import host
class Foo(object):
def __init__(self, host_ip=None):
self.host_ip = host_ip or host.default_ip
for host in range(10):
print host
f = Foo()
print f.host_ip
@saghul
saghul / webimport.py
Created June 21, 2011 06:31
Importing Python modules from the web
# Derived from: http://paste.pocoo.org/show/407530/
import sys
import imp
import urllib2
import urlparse
class WebImporter(object):
@saghul
saghul / gist:1045544
Created June 24, 2011 19:56
Tropo WebImport example
# Derived from: http://paste.pocoo.org/show/407530/
import sys
import imp
import urllib2
import urlparse
class WebImporter(object):
@saghul
saghul / producer.py
Created June 25, 2011 21:48
ZeroMQ producer example
# producer
import zmq
context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.setsockopt(zmq.LINGER, 0) # discard unsent messages on close
socket.connect('tcp://127.0.0.1:5000')
while True:
@saghul
saghul / consumer.py
Created June 25, 2011 21:49
ZeroMQ consumer example
# consumer
import zmq
context = zmq.Context()
socket = context.socket(zmq.SUB)
socket.bind('tcp://127.0.0.1:5000')
socket.setsockopt(zmq.SUBSCRIBE, 'test')
socket.setsockopt(zmq.SUBSCRIBE, 'topic_1')
@saghul
saghul / multithreaded_producer.py
Created June 25, 2011 21:54
ZeroMQ multithreaded producer example
# producer
import os
import random
import threading
import time
import zmq
context = zmq.Context()
@saghul
saghul / producer_multicast.py
Created June 25, 2011 21:57
ZMQ multicast producer example
# producer
import zmq
context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.setsockopt(zmq.LINGER, 0) # discard unsent messages on close
socket.connect('epgm://239.192.1.1:5000')
while True:
@saghul
saghul / consumer_multicast.py
Created June 25, 2011 21:57
ZMQ multicast consumer example
# consumer
import zmq
context = zmq.Context()
socket = context.socket(zmq.SUB)
socket.connect('epgm://239.192.1.1:5000')
socket.setsockopt(zmq.SUBSCRIBE, 'test')
socket.setsockopt(zmq.SUBSCRIBE, 'topic_1')
@saghul
saghul / index.html
Created June 28, 2011 18:38
Simple HTML WebSocket client for the ZeroMQ gateway
<html>
<head>
<title>ZWS Example</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" ></script>
<script language='javascript'>
$(document).ready(function() {
var ws = new WebSocket("ws://localhost:9999/test");
ws.onmessage = function(evt) {
$('#output').append(evt.data+'<br />');