Skip to content

Instantly share code, notes, and snippets.

View quiver's full-sized avatar

George Yoshida quiver

View GitHub Profile
@quiver
quiver / stack_issue08.diff
Created September 7, 2011 09:58
Py-StackExchange issue#8
diff --git a/stackexchange/__init__.py b/stackexchange/__init__.py
index c257838..32e3fb7 100644
--- a/stackexchange/__init__.py
+++ b/stackexchange/__init__.py
@@ -542,7 +542,7 @@ through here."""
try:
if isinstance(ob, datetime.datetime):
return str(time.mktime(ob.timetuple()))
- elif isinstance(ob, str):
+ elif isinstance(ob, basestring):
@quiver
quiver / inotify.py
Created September 3, 2012 15:10
Python implementation of "IBM DeveloperWorks : Monitor Linux file system events with inotify"
import collections
import ctypes
import ctypes.util
# bit masks
IN_ISDIR = 0x40000000
IN_ALL_EVENTS = 0xfff
class inotify_event_struct(ctypes.Structure):
"""
@quiver
quiver / client.py
Created September 16, 2012 10:54
Python port of half duplex FIFO program : http://developers.sun.com/solaris/articles/named_pipes.html
# Python port of half duplex FIFO program : http://developers.sun.com/solaris/articles/named_pipes.html
import sys
import config
def main():
if len(sys.argv) < 2:
print 'Usage : %s <string to be sent to the server>' % sys.argv[0]
sys.exit(0)
wr = open(config.HALF_DUPLEX, 'wb')
@quiver
quiver / client.py
Created September 22, 2012 09:12
Michael Kerrisk : "The Linux Programming Interface" CH.44 : sequence number server(Python Implementation)
# Michael Kerrisk : "The Linux Programming Interface" CH.44 : sequence number server(Python Implementation)
# fifo_seqnum_client
import atexit
import os
import struct
import sys
import config
@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)]
@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 / 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 / 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 / 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 / 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