This is a simple chat-like program using pub-sub pattern, backed by PostgreSQL's LISTEN/NOTIFY command.
publish message to foo
channel from user nickname
.
$ python pub.py foo nickname
PUBLISH to channel #foo
# RESOURCE | |
- WAIT4(2) | |
http://www.kernel.org/doc/man-pages/online/pages/man2/wait4.2.html | |
- GETRUSAGE(2) | |
http://www.kernel.org/doc/man-pages/online/pages/man2/getrusage.2.html | |
- The Linux Programming Interface | |
§26.1.6 The wait3() and wait4() System Calls | |
- Python Documentation | |
http://docs.python.org/2/library/os.html | |
http://docs.python.org/2/library/resource.html |
# chat server using multicast | |
# python fork of the original ruby implementation | |
# http://tx.pignata.com/2012/11/multicast-in-ruby-building-a-peer-to-peer-chat-system.html | |
# receiver.py | |
# usage : $ python receiver.py # wait for messages to come in | |
import socket | |
import struct | |
multicast_addr = '224.0.0.1' |
$ python us_xfr_sv.py > b & | |
[1] 1553 | |
$ cat *py > a | |
$ python us_xfr_cl.py < a | |
$ kill %1 | |
[1]+ Terminated python us_xfr_sv.py > b | |
$ diff -u a b | |
$ |
# The Linux Programming Interface Listing 57-6 | |
$ python ud_ucase_sv.py & | |
[1] 437 | |
$ python ud_ucase_cl.py hello world | |
Server received 5 bytes from /tmp/ud_ucase.452 | |
Response 1 : HELLO | |
Server received 5 bytes from /tmp/ud_ucase.452 | |
Response 2 : WORLD | |
$ python ud_ucase_cl.py 'long message' | |
Server received 10 bytes from /tmp/ud_ucase.763 |
# http://basho.com/blog/technical/2012/10/16/Basho-Package-Repos-Now-Online/ | |
$ curl http://apt.basho.com/gpg/basho.apt.key | sudo apt-key add - | |
% Total % Received % Xferd Average Speed Time Time Time Current | |
Dload Upload Total Spent Left Speed | |
100 1016 100 1016 0 0 1407 0 --:--:-- --:--:-- --:--:-- 4861 | |
OK | |
$ sudo bash -c "echo deb http://apt.basho.com `lsb_release -sc` main > /etc/apt/sources.list.d/basho.list" | |
$ sudo apt-get update | |
... | |
Ign http://apt.basho.com precise/main Translation-en_US |
from pika.adapters import BlockingConnection | |
connection = BlockingConnection() | |
channel = connection.channel() | |
def callback(ch, method, properties, body): | |
print " [x] Received %r" % (body,) | |
channel.basic_consume(callback, | |
queue='test_queue', |
# zabbix_get.py : Python port of zabbix_get | |
# http://www.zabbix.com/documentation/1.8/protocols/agent | |
# http://www.zabbix.com/wiki/doc/tech/proto/zabbixagentprotocol | |
import argparse | |
import socket | |
import struct | |
import sys | |
def str2packed(data): |
#!/usr/bin/env python | |
# http://www.rabbitmq.com/tutorials/tutorial-two-python.html | |
import pika | |
import sys | |
connection = pika.BlockingConnection(pika.ConnectionParameters( | |
host='localhost')) | |
channel = connection.channel() | |
message = ' '.join(sys.argv[1:]) or "Hello World!" |
# http://en.wikipedia.org/wiki/Bloom_filter#Counting_filters | |
# http://www.michaelnielsen.org/ddi/why-bloom-filters-work-the-way-they-do/ | |
import hashlib | |
class BloomFilter(object): | |
def __init__(self, m, k): | |
self.m = m | |
self.k = k | |
self.array = [0 for i in range(m)] |