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
#!/usr/bin/env python | |
import select | |
import time | |
import psycopg2 | |
import psycopg2.extensions | |
import sys | |
def get_cursor(): | |
conn = psycopg2.connect("dbname=pgpubsub") |
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
class DynamicInheritance(type): | |
""" | |
Dinamicaly modify class with some extra mixins. | |
""" | |
def __call__(cls, *args, **kwargs): | |
_mixins = kwargs.pop("_mixins", None) | |
if _mixins: | |
assert isinstance(_mixins, tuple), "_mixin patemeter must be a tuple" |
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
// Compile with: | |
// clang++ -std=c++11 -shared -l boost_python3 -I /usr/include/python3.2mu -fPIC -o bptuple.so tuple-test.cpp | |
#include <tuple> | |
#include <string> | |
#include <boost/python.hpp> | |
namespace py = boost::python; | |
using std::string; |
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 functools | |
import pdb | |
def debug_on(*exceptions): | |
if not exceptions: | |
exceptions = (AssertionError, ) | |
def decorator(f): | |
@functools.wraps(f) | |
def wrapper(*args, **kwargs): | |
try: |
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 __future__ import print_function | |
import timeit | |
import array | |
import struct | |
import psycopg2 as pg | |
connection = pg.connect(host="localhost", dbname="test") |
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
[3/5.0.0]niwi@vaio:~/wrk> ab -n 10000 -c 2 http://127.0.0.1:8000/section0/feature0 | |
This is ApacheBench, Version 2.3 <$Revision: 655654 $> | |
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ | |
Licensed to The Apache Software Foundation, http://www.apache.org/ | |
Benchmarking 127.0.0.1 (be patient) | |
Completed 1000 requests | |
Completed 2000 requests | |
Completed 3000 requests | |
Completed 4000 requests |
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
(env)[3/5.0.0]niwi@vaio:~/helloworld/02-routing> python benchmark.py | |
[...] | |
static[-1] msec rps tcalls funcs | |
bottle 8056 12413 64 34 | |
django 263270 380 1733 70 | |
[...] | |
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
CREATE OR REPLACE FUNCTION idx(anyarray, anyelement) | |
RETURNS int AS | |
$$ | |
SELECT i FROM ( | |
SELECT generate_series(array_lower($1,1),array_upper($1,1)) | |
) g(i) | |
WHERE $1[i] = $2 | |
LIMIT 1; | |
$$ LANGUAGE sql IMMUTABLE; |
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
# -*- coding: utf-8 -*- | |
from __future__ import unicode_literals, print_function | |
import io | |
SEGMENT_SEPARATOR = b'\r' | |
SECTION_SEPARATOR = b'^' | |
FIELD_SEPARATOR = b'|' | |
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 django.conf import settings | |
from django.conf.urls import patterns, include, url | |
from django.contrib.staticfiles.urls import staticfiles_urlpatterns | |
urlpatterns = patterns('', | |
[...] # main urls | |
) | |
def mediafiles_urlpatterns(): |