Skip to content

Instantly share code, notes, and snippets.

Avatar

Eduardo Ferro Aldama eferro

View GitHub Profile
@eferro
eferro / proxy.py
Created Jan 28, 2013
dynamic proxy... inject args and kwargs to all the methods of the target
View proxy.py
# -*- 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 / func_introspection.py
Created Nov 14, 2012
Introspection for functions/methods using inspect modules
View func_introspection.py
#!/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 / importer.py
Created Oct 21, 2012
Import module and/or symbol dynamically from name (string)
View importer.py
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 / gist:3265121
Created Aug 5, 2012
setuptools, pip and virtualenv installation
View gist:3265121
# 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 / gist:3265056
Created Aug 5, 2012
Python 2.7.3 for old gnu/linux systems (test debian/ubuntu)
View gist:3265056
# 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 / inspect_example.py
Created Jul 28, 2012
Get classes, functions, etc... using instrospection (inspect module)
View inspect_example.py
#!/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 / import_from_file.py
Created Jul 28, 2012
Import a python file as module
View import_from_file.py
#!/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 / about.md
Created Aug 18, 2011 — forked from jasonrudolph/about.md
Programming Achievements: How to Level Up as a Developer
View about.md
@eferro
eferro / concatenator.js
Created Aug 17, 2011
ejercicio1 jornada 3 grupo estudio java script
View concatenator.js
// 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,