View gist:575270
#!/usr/bin/env python
# coding: utf-8
# How Twisted's inlineCallbacks work?
# If you use it but don't know exactly what it does,
# and didn't understand the code shipped with Twisted,
# keep reading.
import types, functools
from twisted.python import failure
from twisted.web.client import getPage
View gist:1811995
def checkQuota(method):
@defer.inlineCallbacks
@functools.wraps(method)
def wrapper(self, *args, **kwargs):
key = "ip:%s" % self.request.remote_ip
try:
n = yield self.redis.incr(key)
except Exception, e:
log.msg("Redis failed to incr('%s'): %s" % (key, str(e)))
View tcp-proxy.py
#!/usr/bin/env python
# coding: utf-8
# http://musta.sh/2012-03-04/twisted-tcp-proxy.html
import sys
from twisted.internet import defer
from twisted.internet import protocol
from twisted.internet import reactor
from twisted.python import log
View webtail.py
#!/usr/bin/env python
# coding: utf-8
#
# start the server:
# python webtail.py /var/log/syslog
#
# point all your browsers to:
# http://localhost:8888
View txredisapi_inet_vs_unix.py
#!/usr/bin/env python
# coding: utf-8
#
# Compare txredisapi's inet vs unix sockets.
# Don't forget to enable redis' unix socket prior to executing this.
import time
import txredisapi as redis
from twisted.internet import defer
View akinator.py
#!/usr/bin/env python
# coding: utf-8
#
# Interactive command line crawler to akinator.com
# http://musta.sh/2012-07-20/twisting-python-and-freeswitch.html
import re
import sys
from twisted.internet import defer
View test.py
# coding: utf-8
# twistd -n cyclone -r test.Application
import cyclone.web
from twisted.internet import defer
from twisted.internet import protocol
from twisted.internet import reactor
from twisted.protocols.memcache import MemCacheProtocol
View cities.py
#!/usr/bin/env python
# coding: utf-8
#
# The World Gazetteer provides a downloadable file that contains a list
# of all cities, towns, administrative divisions and agglomerations with
# their population, their English name parent country.
#
# Article: http://answers.google.com/answers/threadview/id/774429.html
# Download: http://www.world-gazetteer.com/dataen.zip
View gist:9664255
package main
import (
"encoding/hex"
"log"
"net"
"time"
)
const (
View gist:9927296
func pcapReader(filename string) (io.ReadCloser, error) {
pr, pw, err := os.Pipe()
if err != nil {
return nil, err
}
handle, err := pcap.OpenOffline(filename)
if err != nil {
return nil, err
}