Skip to content

Instantly share code, notes, and snippets.

View ikatson's full-sized avatar

Igor Katson ikatson

  • Facebook
  • London
  • 18:30 (UTC +01:00)
View GitHub Profile
import os
import uwsgi
import gevent
import gevent.select
import gevent.socket
class ProxyMiddleware(object):
@ikatson
ikatson / profiling.py
Last active December 28, 2015 02:19
Simple django profiling
# coding: utf-8
# Profiling middleware and decorator, that allows to profile any django
# view easily for superusers.
__author__ = 'igor.katson@gmail.com'
import cProfile
import pstats
import tempfile
*** Starting uWSGI 1.9.18.2 (64bit) on [Tue Nov 19 20:44:14 2013] ***
compiled with version: 4.6.3 on 23 October 2013 03:45:04
os: Linux-3.2.0-23-generic #36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012
nodename: precise64
machine: x86_64
clock source: unix
detected number of CPU cores: 2
current working directory: /src/uwsgi_includes
detected binary path: /usr/src/uwsgi-1.9.18.2/uwsgi
@ikatson
ikatson / gist:7686087
Created November 28, 2013 01:45
pandas bug: Series become empty somehow.
import pandas
class AggregatedValue(object):
def __init__(self, aggfunc, value=None, original=None):
self.aggfunc = aggfunc
self.value = value
self.original = original
def __repr__(self):
def get_or_create_contact_from_phones(phones_list):
return load_json(request(
'POST /api/v1/contact/get_or_create_from_phones/',
as_json({'phone': phones_list})
))
def find_contact_by_email(email):
for contact in load_json(request('GET /api/v1/contact/?q=' + email)):
if email in contact['emails']:
return contact
@ikatson
ikatson / uwsgi.ini
Created February 5, 2014 04:48
The work of process 13041 is done. Seeya!
[uwsgi]
##### Basic requried config for app to work ####
home = /home/trip/.virtualenvs/trip/
chdir = /home/trip/trip/
pythonpath = /home/trip/trip/
env = LANG=en_US.UTF-8
env = SERVER_SOFTWARE=gevent
env = DJANGO_SETTINGS_MODULE=settings
# Gevent is our execution model of choice :) Required for many features
@ikatson
ikatson / websockets_test.py
Last active June 23, 2016 23:44
uwsgi websocket gevent
uwsgi.websocket_handshake(...)
user_id = get_user_id_from_environ(environ)
ready = gevent.event.Event()
dead = gevent.event.Event()
def ws_socket_waiter():
while not dead.is_set():
gevent.socket.wait_read(websocket_fd)
@ikatson
ikatson / index.html
Last active August 29, 2015 13:57
uwsgi + harakiri + websockets bug
<html>
<head>
<script>
var polling = (function () {
var poll_error_timeout = 1;
var default_error_timeout = poll_error_timeout + 0;
var poll_error_max_timeout = 15;
function pollForEventsWebsockets() {
var s = new WebSocket('ws://localhost:8000/ws');
@ikatson
ikatson / README.md
Last active August 29, 2015 14:02
uwsgi debian build test

Playing with debian packages

  1. Place the original archive into parent directory and rename, in my case to

uwsgi_2.0.5.orig.tar.gz


2. This one will update the changelog, it contains the version.
   ```bash
dch --create -v 2.0.5-1 --package uwsgi
@ikatson
ikatson / gist:21e80a7e0b3e99a78ef6
Last active August 29, 2015 14:03
fpm install native python packages
# Cython can increase the performance of some packages
apt-get install build-essential cython rubygems python-dev python-pip python-setuptools libpcre3-dev
get install fpm
# Build uwsgi
fpm --verbose -s python -t deb --python-install-bin /usr/bin --name uwsgi \
--architecture amd64 -d libpython2.7 -d libpcre3 -d zlib1g -d libssl1.0.0 -d libxml2 uwsgi
# Build gevent debian package