Skip to content

Instantly share code, notes, and snippets.

View quiver's full-sized avatar

George Yoshida quiver

View GitHub Profile
@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 / 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 / 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 / README.md
Last active April 3, 2024 15:47
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.md
Created December 16, 2012 09:06
pub-sub based simple message push system. DB : Redis, program : Python

README

pub-sub based simple message push system.

programs

pub.py

  • pub-sub #admin publisher
  • pub-sub #channel_name publisher

sub_admin.py

@quiver
quiver / zabbix_api.py
Created February 10, 2013 06:52
Python script to demonstrate usage of Zabbix 1.8 API. Depends on requests module. (http://docs.python-requests.org/) API spec : https://www.zabbix.com/documentation/1.8/api
# 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
@quiver
quiver / redis-string-or-hash-insert.py
Last active July 29, 2022 08:39 — forked from mikeyk/gist:1329319
Testing storage of millions of keys in Redis http://instagram-engineering.tumblr.com/post/12202313862/storing-hundreds-of-millions-of-simple-key-value-pairs # major changes - removed pylibmc dependency
#! /usr/bin/env python
import redis
import random
import sys
r = redis.Redis(host = 'localhost', port = 6379)
REDIS_SETGET = False
REDIS_HSET = False
@quiver
quiver / copy_csv
Last active December 15, 2015 04:19
copy null data(tsv/csv) into postgresql
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)
@quiver
quiver / gist:5264557
Created March 28, 2013 16:18
Redis+trie auto complete Ruby program is a copy from http://stackoverflow.com/questions/1958005/redis-autocomplete, authored by Alex. http://en.wikipedia.org/wiki/Trie
require 'rubygems'
require 'redis'
class RedisTrie
TERMINAL = '+'
def initialize(prefix)
@prefix = prefix
@r = Redis.new
end