Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/python
import sys
import subprocess
import Queue
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
class QueuingEventHandler(FileSystemEventHandler):
def __init__(self, queue):
/*
* We should really look for the smallest 32bit integer type,
* but this will do for prototyping on a 32-bit OS
*/
typedef unsigned int gss_uint32;
typedef unsigned int OM_uint32;
/*
* Now define the three implementation-dependent types.
*/
import gevent
import socket
threadpool = gevent.get_hub().threadpool # this is the default gevent threadpool
urls = ['www.google.com', 'www.example.com', 'www.python.org']
results = threadpool.map(socket.gethostbyname, urls)
# >>> results
# ['173.194.34.179', '93.184.216.119', '185.31.18.175']
DEBUG:echo:3 is handling a request in <Greenlet at 0x110184550: uwsgi_gevent_request(4539005552L)>
[pid: 99684|app: 0|req: 2/3] 127.0.0.1 () {40 vars in 806 bytes} [Mon May 12 20:34:00 2014] GET / => generated 1383 bytes in 0 msecs (HTTP/1.1 200) 2 headers in 81 bytes (3 switches on core 999)
!!! uWSGI process 99686 got Segmentation Fault !!!
*** backtrace of 99686 ***
0 uwsgi 0x000000010c551ff0 uwsgi_backtrace + 48
1 uwsgi 0x000000010c552533 uwsgi_segfault + 51
2 libsystem_platform.dylib 0x00007fff8a5dc5aa _sigtramp + 26
3 ??? 0x000000010c888050 0x0 + 4505239632
4 Python 0x000000010c76401f PyEval_CallObjectWithKeywords + 93
5 uwsgi 0x000000010c56a4b7 python_call + 23
@sigmaris
sigmaris / echo.py
Created May 12, 2014 19:39
uwsgi websocket test
# Run this with: uwsgi --virtualenv venv --socket /tmp/uwsgi.sock --chmod-socket --plugin gevent --gevent 1000 --gevent-monkey-patch --module echo:application --master --processes 4 --enable-threads
from flask import Flask, request, render_template
import gevent
import logging
from uwsgi_websockets.middleware import ws_middleware
import uwsgi
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
@sigmaris
sigmaris / saslclient.py
Last active August 29, 2015 14:10
Example SASL code
import argparse
import base64
import struct
import sys
from gssapi import sec_contexts, names
from gssapi.raw.types import NameType, RequirementFlag
SEC_LAYER_NONE = 1
[vagrant@localhost python-gssapi]$ sudo tox
GLOB sdist-make: /home/vagrant/python-gssapi/setup.py
py27 create: /home/vagrant/python-gssapi/.tox/py27
py27 installdeps: nose, nose_parameterized, flake8, git+https://github.com/DirectXMan12/should_be.git, Cython, six
py27 inst: /home/vagrant/python-gssapi/.tox/dist/PythonGSSAPI-1.0.0.zip
ERROR: invocation failed, logfile: /home/vagrant/python-gssapi/.tox/py27/log/py27-2.log
ERROR: actionid=py27
msg=installpkg
cmdargs=[local('/home/vagrant/python-gssapi/.tox/py27/bin/pip'), 'install', '--pre', '/home/vagrant/python-gssapi/.tox/dist/PythonGSSAPI-1.0.0.zip']
env={'LANG': 'en_GB.UTF-8', 'USERNAME': 'root', 'TERM': 'xterm-256color', 'SHELL': '/bin/bash', 'SUDO_COMMAND': '/bin/tox', 'HOSTNAME': 'localhost.localdomain', 'SUDO_UID': '900', 'LC_CTYPE': 'en_GB.UTF-8', 'HISTSIZE': '1000', 'PYTHONIOENCODING': 'utf_8', 'PYTHONHASHSEED': '3968196433', 'LOGNAME': 'root', 'USER': 'root', 'MAIL': '/var/spool/mail/vagrant', 'PATH': '/home/vagrant/python-gssapi/.tox/py27/bin:/sbin:
/* Generated by Cython 0.21.1 */
#define PY_SSIZE_T_CLEAN
#ifndef CYTHON_USE_PYLONG_INTERNALS
#ifdef PYLONG_BITS_IN_DIGIT
#define CYTHON_USE_PYLONG_INTERNALS 0
#else
#include "pyconfig.h"
#ifdef PYLONG_BITS_IN_DIGIT
#define CYTHON_USE_PYLONG_INTERNALS 1
>>> def f1(y):
... return set(x for x in y)
...
>>> def f2(y):
... return {x for x in y}
...
>>> dis.dis(f1)
2 0 LOAD_GLOBAL 0 (set)
3 LOAD_CONST 1 (<code object <genexpr> at 0x10abecd30, file "<stdin>", line 2>)
6 MAKE_FUNCTION 0
@sigmaris
sigmaris / cookie.py
Created March 26, 2011 21:48 — forked from justquick/cookie.py
Use cookies for all session storage in Django. This version uses HMAC to verify the integrity of the cookie, and raises SessionTooBig if the session is too large to fit in a cookie.