Skip to content

Instantly share code, notes, and snippets.

View agalera's full-sized avatar
🐍
Good luck! 👍

Alberto Galera agalera

🐍
Good luck! 👍
View GitHub Profile
@agalera
agalera / gist:571630e36a6b6bb550b5
Created August 19, 2014 08:00
Example bottle and gunicorn + gevent
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from bottle import run, get
@get('/test')
def test():
return "test"
@agalera
agalera / gist:aa10199ba96d0d4009c6
Last active August 29, 2015 14:13
default values in python
#default values in ruby https://gist.github.com/kianxineki/8b13ebc8816623f4a650
def append_values(new_value, a=[]):
a.append(new_value)
return a
append_values("n1") # result ['n1']
rlist = append_values("n2") # result ['n1', 'n2']
rlist.append("n3")
print(rlist) # result ['n1', 'n2', 'n3']
append_values("n4") # result ['n1', 'n2', 'n3', 'n4']
@agalera
agalera / gist:8b13ebc8816623f4a650
Last active August 29, 2015 14:13
default values in ruby
#check python https://gist.github.com/kianxineki/aa10199ba96d0d4009c6
def append_values(new_value,a=[])
a.push(new_value)
return a
end
append_values("n1") # result ['n1']
rlist = append_values("n2") # result ['n2']
rlist.push("n3")
print rlist # result ['n2', 'n3']
@agalera
agalera / gist:05bd63db33f83068863d
Created February 25, 2015 08:42
middleware mongodb
class middleware_mongodb(object):
def __init__(self, db=None):
self.db = db
def __getattr__(self, attr):
if attr in dir(self.db):
return getattr(self.db, attr)
return middleware_mongodb(self.db.__getattr__(attr))
# rewrite methods
@agalera
agalera / speed_structures_in_python
Created August 5, 2015 12:02
Speed structures in python
%timeit [0, 1, 2, 3, 4, 5]
10000000 loops, best of 3: 113 ns per loop
%timeit (0, 1, 2, 3, 4, 5)
100000000 loops, best of 3: 17.4 ns per loop
%timeit {0:0, 1:1, 2:2, 3:3, 4:4, 5:5}
1000000 loops, best of 3: 410 ns per loop
lista = [0, 1, 2, 3, 4, 5]
@agalera
agalera / sqlite_permissions.py
Last active June 28, 2016 09:03
sqlite permissions
import sqlite3 as lite
from random import randint
def real_random(total):
result = []
while True:
new_value = randint(1, 10000)
if new_value not in result:
result.append(new_value)
@agalera
agalera / test.c
Created February 1, 2016 10:42
Test threads in C
#include <stdio.h>
#include <pthread.h>
void* calculate()
{
int i = 0;
int b = 0;
for(i=0; i<100000000; i++){
b = i+b;
}
@agalera
agalera / product.c
Last active June 28, 2016 08:59
Product.c
#include <Python.h>
#include <stdio.h>
#include <string.h>
typedef struct {
PyObject_HEAD
char* trans;
int len_letters;
char* letters;
int repeat;
@agalera
agalera / many_connection.py
Last active March 9, 2016 07:28
Many connection
from threading import Thread
import sys
import socket
host, port = sys.argv[1], int(sys.argv[2])
connect_per_thread = int(sys.argv[4])
def many_connection():
while True:
sockets = []
@agalera
agalera / tornado_upload.py
Created May 3, 2016 07:34
tornado upload
from tornado.httpserver import HTTPServer
import tornado.ioloop
import tornado.web
import uuid
from tornado.concurrent import run_on_executor
from concurrent.futures import ThreadPoolExecutor
@tornado.web.stream_request_body
class MainHandler(tornado.web.RequestHandler):
executor = ThreadPoolExecutor(max_workers=400)