Skip to content

Instantly share code, notes, and snippets.

View eferro's full-sized avatar

Eduardo Ferro Aldama eferro

View GitHub Profile
@eferro
eferro / concatenator.js
Created August 17, 2011 14:31
ejercicio1 jornada 3 grupo estudio java script
// Crear una funcion que dado un array, que puede contener strings o arrays,
// concatene todos los strings y los separe por comas. Ej. Si el array que
// entra es:
// ["hola", ["soy", ["juan", "fernandez"]], "y", ["no", "tengo", ["dinero"]]]
// Devolvera la cadena "hola,soy,juan,fernandez,y,no,tengo,dinero"
function concatenator(initialArray, separator){
separator = separator || ",";
var elem,
i,
@eferro
eferro / about.md
Created August 18, 2011 06:54 — forked from jasonrudolph/about.md
Programming Achievements: How to Level Up as a Developer
@eferro
eferro / import_from_file.py
Created July 28, 2012 22:34
Import a python file as module
#!/usr/bin/python
import sys
import imp
import os.path
def import_pythonfile_as_module(python_file_path):
file_name = os.path.basename(python_file_path)
module_name = os.path.splitext(file_name)[0]
new_module = imp.load_source(module_name,
@eferro
eferro / inspect_example.py
Created July 28, 2012 22:55
Get classes, functions, etc... using instrospection (inspect module)
#!/usr/bin/python
import sys
import inspect
import os.path
import os
def get_symbols_from_module(python_module, filter_func):
members = inspect.getmembers(python_module)
@eferro
eferro / gist:3265056
Created August 5, 2012 14:15
Python 2.7.3 for old gnu/linux systems (test debian/ubuntu)
# Install minimal development tools
apt-get install build-essential
# Get python from official python ftp
cd /tmp
wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2
tar jxvf Python-2.7.3.tar.bz2
cd Python-2.7.3/
# Configure, compile and install python to /opt/py2.7
@eferro
eferro / gist:3265121
Created August 5, 2012 14:30
setuptools, pip and virtualenv installation
# python installed at /opt/py2.7
# Install setuptools
cd /tmp
wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
tar zxvf setuptools-0.6c11.tar.gz
cd setuptools-0.6c11/
/opt/py2.7/bin/python setup.py install
# Install pip
cd /tmp
@eferro
eferro / importer.py
Created October 21, 2012 18:31
Import module and/or symbol dynamically from name (string)
import importlib
class Importer(object):
@staticmethod
def import_module(module_name):
return importlib.import_module(module_name)
@staticmethod
def get_symbol(symbol_name):
module_name = Importer._extract_module_name(symbol_name)
@eferro
eferro / func_introspection.py
Created November 14, 2012 22:38
Introspection for functions/methods using inspect modules
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import inspect
def func1(arg1, arg2, arg3):
pass
def func2(arg1, arg2, arg3='arg3_default'):
pass
@eferro
eferro / proxy.py
Created January 28, 2013 16:50
dynamic proxy... inject args and kwargs to all the methods of the target
# -*- coding: utf-8 -*-
import unittest
from doublex import *
class Proxy(object):
class Method(object):
def __init__(self, target, method_name, *aditional_args, **aditional_kwargs):
self.target = target
@eferro
eferro / gist:11fd8352d5defdeee3c9
Created June 8, 2014 20:50
spec example using mamba
with description('CPE status'):
with before.each:
self.ppg_service = Stub(ppg_services.ProductPackageGroupService)
self.sip_credentials = Stub(sip_credentials_module.SipCredentials)
self.cpe_status_repository = InMemoryCPEStatusRepository()
self.cpe_status_event_history_repository = InMemoryCPEStatusEventHistoryRepository()
self.clock = Stub(clock.Clock)
self.cpe_status_service = cpe_status_service(self.cpe_status_repository,
self.ppg_service,