Skip to content

Instantly share code, notes, and snippets.

View dunossauro's full-sized avatar
🟣

Eduardo Mendes dunossauro

🟣
View GitHub Profile
@dunossauro
dunossauro / methods.py
Last active May 26, 2018 00:01
Exemplo de como funcionam os decoradores de classe para o @rg3915
"""
Respondendo a questões feitas no grupo da live de Python.
"""
class Teste:
bananas_cls = 5 # Variável de classe
def __init__(self):
"""Método que inicia a instância."""
self.bananas_self = 10 # Variável de instância
@dunossauro
dunossauro / mqueue.py
Created May 30, 2018 20:06
Exemplo de como compartilhas uma queue com processos e threads
"""Exemplo de como compartilhas uma queue com processos e threads."""
from collections import namedtuple
from multiprocessing import Process, Queue
from threading import Thread
from os import getppid, getpid
q = Queue()
pstate = namedtuple('pstate', 'name ppid pid')
"""
Exemplo de classe e objeto.
Criado para rapidinha #7: https://youtu.be/SQXmC6PbZWk
"""
class Personagem:
"""Molde para o rato."""
def __init__(self, nome, cor):
@dunossauro
dunossauro / jokenpo.py
Created July 11, 2018 01:58
Jokenpo com dispatcher
from multipledispatch import dispatch # pip
class Pedra:
def __repr__(self):
return 'Pedra'
class Papel:
def __repr__(self):
return 'Papel'
@dunossauro
dunossauro / iterator_async.py
Last active July 30, 2018 13:08
Async iterator + singledipatcher
from asyncio import get_event_loop
from collections.abc import AsyncIterator
from typing import Iterator, Collection, Dict
from types import coroutine
from functools import singledispatch
@singledispatch
def aiter(iterator):
pass
from functools import wraps
class Dispatcher:
def __init__(self, func):
self.func = func
self.slots = []
def __call__(self, arg):
for func, arg_type in self.slots:
@dunossauro
dunossauro / regis.py
Created August 29, 2018 14:05
Dúvida do regis em relação a animanhento e tratativa de valores de diferentes tipos
"""
Alternativa ao multiplo aninhamento de código.
Problema proposto pelo @rg3915
Código antigo:
for k, v in variant_list.items():
if v:
try:
v = float(v)
@dunossauro
dunossauro / convert_string_types.py
Last active December 14, 2018 18:21
Conversão de strings em tipos válidos do python usando literal_eval
from ast import literal_eval
def convert_to_type(input_data):
try:
return literal_eval(input_data)
except (ValueError, SyntaxError):
return input_data
@dunossauro
dunossauro / envirounment.py
Last active October 14, 2018 23:49
Login com BDD usando tags
from module_login import POLogin
def before_tag(context, tag):
if tag == 'login':
POLogin.do_login(user, passw)
@dunossauro
dunossauro / drop_docker.sh
Created January 30, 2019 12:42
remove all images, containers and volumes
docker stop $(docker ps -q -a)
docker rm -f $(docker ps -q -a)
docker volume prune -f
docker rmi -f $(docker images -q -a)