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
$ 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 | |
$ |
# 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' |
# 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 |
# vim: set fileencoding=utf8 | |
# | |
# authenticate with zabbix api server, and retrieve monitored hosts | |
# specification : https://www.zabbix.com/documentation/1.8/api | |
# | |
# $ python zabbix_api.py | |
import requests | |
from pprint import pprint | |
import json |
#! /usr/bin/env python | |
import redis | |
import random | |
import sys | |
r = redis.Redis(host = 'localhost', port = 6379) | |
REDIS_SETGET = False | |
REDIS_HSET = False |
postgres=# copy t(id, name) from '/tmp/data.csv' (format csv) ; | |
COPY 5 | |
postgres=# select id , name, length(name) from t; | |
id | name | length | |
----+--------+-------- | |
1 | food | 4 | |
2 | energy | 6 | |
3 | '' | 2 | |
4 | | 0 | |
5 | | |
# vim: set fileencoding=utf8 | |
from tornado import ioloop | |
import functools | |
import os | |
import sys | |
def start(io_loop, check_time=500): | |
modify_times = {} # watch list | |
callback = functools.partial(_reload_on_update, modify_times) |
require 'rubygems' | |
require 'redis' | |
class RedisTrie | |
TERMINAL = '+' | |
def initialize(prefix) | |
@prefix = prefix | |
@r = Redis.new | |
end |