This file contains hidden or 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
import sys, uuid | |
import math | |
from struct import * | |
file_for_import = sys.argv[1] | |
layer = sys.argv[2] | |
y_offset = float(sys.argv[3]) | |
x_offset = float(sys.argv[4]) | |
z_offset = float(sys.argv[5]) | |
scale_multiplier = 1.0 |
This file contains hidden or 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
s = gevent.socket.socket(gevent.socket.AF_INET6, gevent.socket.SOCK_STREAM) | |
s.bind(('::', 0)) | |
s.listen(2048) |
This file contains hidden or 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
from netifaces import ifaddresses, AF_INET | |
def ip4_addresses(): | |
for interface in ['eth0', 'eth1', 'wlan0']: | |
try: | |
link = ifaddresses(interface) | |
if AF_INET in link: | |
return link[AF_INET][0]['addr'] | |
except ValueError: | |
pass |
This file contains hidden or 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
from functools import partial | |
import gevent | |
def kazoo_callback(zk, func, event): | |
""" | |
usage example | |
zk.get_children("/redis/providers", partial(kazoo_callback, zk, provider_changed)) | |
""" | |
def watcher(e): | |
print "### watcher called", event |
This file contains hidden or 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
import logging | |
import logging.handlers | |
def get_logger(name=None, address='/dev/log', level=logging.DEBUG): | |
my_logger = logging.getLogger(name) | |
my_logger.setLevel(logging.DEBUG) | |
handler = logging.handlers.SysLogHandler(address = address) | |
formatter = logging.Formatter('%(module)s[%(process)s]: %(levelname)s %(message)r') | |
handler.setFormatter(formatter) | |
my_logger.addHandler(handler) |
This file contains hidden or 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
>>> from gevent_zeromq import zmq | |
>>> context = zmq.Context() | |
>>> internal_socket = context.socket(zmq.PULL) | |
>>> internal_socket.bind_to_random_port("tcp://*") | |
59994 | |
>>> internal_socket.bind_to_random_port("tcp://localhost") | |
Traceback (most recent call last): | |
File "<input>", line 1, in <module> | |
File "/usr/local/lib/python2.7/dist-packages/zmq/core/pysocket.py", line 148, in bind_to_random_port | |
raise ZMQBindError("Could not bind socket to random port.") |
This file contains hidden or 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
# from www.musicfilmcomedy.com | |
def setup_redis_session(app): | |
redis_pool = redis.ConnectionPool(host='localhost', port=6379, db=0) | |
return SessionMiddleware(app, type="redis", url="localhost:6379", key="musicfilmcomedy", connection_pool=redis_pool) |
This file contains hidden or 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
# get all langs from db | |
all_available_languages = [a['lang'] for a in cur.fetchall()] | |
def get_lang(lang): | |
default = 'en' | |
mo_dir = os.path.join(os.path.abspath(os.curdir), 'locale') | |
domain = 'musicfilmcomedy' | |
langs = [lang.replace('-', '_')] | |
langs.append(default) |
This file contains hidden or 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
from beaker.middleware import CacheMiddleware, SessionMiddleware | |
def setup_redis_session(app): | |
return SessionMiddleware(app, type="redis", url="localhost:6379", key="appname") | |
application = cherrypy.Application(Root(all_available_languages), '', config='musicfilmcomedy.conf') | |
application.wsgiapp.pipeline.append(('beaker', setup_redis_session)) |