Skip to content

Instantly share code, notes, and snippets.

View felipecruz's full-sized avatar

Felipe Cruz felipecruz

  • Berlin, Germany
View GitHub Profile
@felipecruz
felipecruz / pyaio_example.py
Created October 21, 2010 20:18
experimental aio.h implementation for python
import pyaio
import time
def aio_callback(buf):
print 'python callback %s' % buf
#file name, offset, lenght, callback function
pyaio.aio_read('/tmp/b.txt', 10, 20, aio_callback)
static PyObject *
pyaio_write(PyObject *dummy, PyObject *args) {
const char *filename;
const char *buffer;
struct aiocb cb;
int ret, offset, numbytes;
Pyaio_cb *aio;
PyObject *result = NULL;
# Original WSGI application.
def application(environ, start_response):
...
# Logging WSGI middleware.
import pprint
class LoggingMiddleware:
@felipecruz
felipecruz / asyncsrv.py
Created March 23, 2011 21:07
python zmq async server example
import zmq
import threading
import time
from random import choice
class ClientTask(threading.Thread):
"""ClientTask"""
def __init__(self):
threading.Thread.__init__ (self)
# if you're on linux host, you need xvfb
sudo apt-get install xvfb
git clone git://github.com/felipecruz/jasmine-gem.git
cd jasmine-gem
git submodule init
git submodule update
gem install rails
gem install gem-release
gem install bundler
module Jasmine
class Config
# Add your overrides or custom config code here
def jasmine_xvfb
'xvfb-run --server-args="-screen 0 2000x1400x24"'
end
end
end
rake jasmine:phantomjsci
distolica = new ValueAnswer("Distolica");
sistolica = new ValueAnswer("Sistolica");
complex_rule = new ComplexRule( { distolica: distolica, sistolica: sistolica},
"context.Distolica > 14 && context.Sistolica > 8",
null,
function() { recomendations.push("Hipertensao! Marcar consulta"); });
complex_rule2 = new ComplexRule( { distolica: distolica, sistolica: sistolica},
"context.Distolica < 10 && context.Sistolica < 8",
//Domicilio
q = new DataQuestion("Registro da Família");
q2 = new DataQuestion("Familia");
q3 = new DataQuestion("Endereco");
q4 = new DataQuestion("Numero");
q5 = new DataQuestion("Complemento");
q6 = new DataQuestion("Procedencia");
q7 = new DataQuestion("Tempo de Moraria");
q8 = new DataQuestion("Bairro");
q9 = new DataQuestion("CEP");
@felipecruz
felipecruz / pypy_czmq_ctypes_experiment.py
Created July 8, 2011 20:33
pypy_czmq_ctypes_experiment.py
from ctypes import *
from ctypes.util import find_library
czmq = CDLL(find_library("czmq"),use_errno=True)
czmq.zctx_new.restype = c_void_p
czmq.zctx_new.argtypes = []
context = czmq.zctx_new()
czmq.zctx__socket_new.restype = c_void_p
czmq.zctx__socket_new.argtypes = [c_void_p,c_int]
socket = czmq.zctx__socket_new(context, c_int(3))