This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ipdb; ipdb.set_trace() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def flat_keys(dictionary, out): | |
""" | |
Flatten keys from a nested dictionary | |
out should be an empty list | |
""" | |
for key in dictionary.keys(): | |
out.append(key) | |
if isinstance(dictionary[key], dict): | |
flat_keys(dictionary[key], out) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def flat_dict(dictionary, out, pre=''): | |
""" | |
Create a flat dictionary from a nested dictionary | |
out should be an empty dictionary | |
Currently I don't really know what to do with nested dict keys... | |
""" | |
for key, value in dictionary.iteritems(): | |
out[pre + key] = value | |
if isinstance(value, dict): | |
flat_dict(value, out, pre + key + ':') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Create Private REPO for PIP on Ubuntu | |
1º Instalar https://github.com/wolever/pip2pi | |
#apt-get install pip | |
#pip install pip2pi | |
2º Create folder to host packages | |
#mkdir /var/www/pip | |
#copy foo-1.2.tar.gz in /var/www/pip | |
#dir2pi /var/www/pip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
from functools32 import lru_cache | |
NUMBER = 40 | |
def fibonacci_iterative(pos): | |
first = 0 | |
second = 1 | |
number = 0 | |
counter = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Singleton: | |
__instance = None | |
value = None | |
def __new__(cls): | |
if Singleton.__instance is None: | |
Singleton.__instance = object.__new__(cls) | |
return Singleton.__instance | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from copy import deepcopy | |
class Prototype: | |
def __init__(self): | |
self._objects = {} | |
def register_object(self, name, obj): | |
'''Store an object so it can be cloned later''' | |
self._objects[name] = obj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class VehicleDirector: | |
__builder = None | |
def set_builder(self, builder): | |
self.__builder = builder | |
def build(self): | |
vehicle = Vehicle() | |
vehicle.set_body(self.__builder.get_body()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Computer: | |
@staticmethod | |
def factory(type): | |
computers = { | |
'Macbook': Macbook, | |
'Surface': Surface, | |
'Desktop': Desktop | |
} | |
try: | |
return computers[type]() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Dog(object): | |
'''A representation of a dog''' | |
def __init__(self, name): | |
self.name = name | |
def bark(self): | |
return 'Woof!!' | |
class Person: |
OlderNewer