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: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 / 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 / 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 / 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 / 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 / launcher.py
Created May 22, 2016 18:54
launcher ld48-desmadrestudio
import urllib2
import hashlib
import os
import json
download_base = "http://desmadrestudio.com/static/ld48/"
# obtain find images/* -exec md5sum {} +
j = urllib2.urlopen(download_base + 'update.json')
j_obj = json.load(j)
list_download = j_obj['files']
@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 / 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.py
Created September 23, 2016 09:21
test.py
import ipdb
class Clase2:
pass
class Clase1:
def __init__(self):
self.example = {}