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 / 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 / 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 / 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 / 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: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: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"