This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding: utf-8 | |
# | |
# start the server: | |
# python webtail.py /var/log/syslog | |
# | |
# point all your browsers to: | |
# http://localhost:8888 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/hex" | |
"log" | |
"net" | |
"time" | |
) | |
const ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
OlderNewer