Skip to content

Instantly share code, notes, and snippets.

View quiver's full-sized avatar

George Yoshida quiver

View GitHub Profile
@quiver
quiver / README.md
Last active September 19, 2024 12:21
Who says PostgreSQL can't Pub/Sub like Redis?

Pub/Sub pattern with PostgreSQL's LISTEN/NOTIFY command

This is a simple chat-like program using pub-sub pattern, backed by PostgreSQL's LISTEN/NOTIFY command.

Publish

publish message to foo channel from user nickname.

$ python pub.py foo nickname
PUBLISH to channel #foo
@quiver
quiver / README.txt
Created November 23, 2012 06:15
[python]demo of os.wait3/4:with wait3/4 you can retrieve resource usage information about the child processes.
# 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
@quiver
quiver / receiver.py
Created November 19, 2012 15:36
[python]chat server using multicast
# 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'
@quiver
quiver / session.txt
Created November 16, 2012 15:27
Linux Programming Interface 57.2 Stream Sockets in the UNIX Domain(in Python)
$ 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
$
@quiver
quiver / session.txt
Created November 16, 2012 15:12
Linux Programming Interface Listing 57-6: A simple UNIX domain datagram server in Python
# 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
@quiver
quiver / install_riak_on_ubuntu
Created November 3, 2012 06:18
Install Riak on Ubuntu with Basho official repository
# 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
@quiver
quiver / consume.py
Created November 3, 2012 03:47
rabbitmq : mirrored-queue sample code
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',
@quiver
quiver / zabbix_get.py
Created October 13, 2012 05:37
Python port of zabbix_get command
# 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):
@quiver
quiver / new_task.py
Created October 6, 2012 12:15
rabbitmq : dead letter exchange example with python/pika
#!/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!"
@quiver
quiver / counting_bloom_filter.py
Created September 29, 2012 02:29
counting bloom filter
# 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)]