Skip to content

Instantly share code, notes, and snippets.

View dunossauro's full-sized avatar
🟣

Eduardo Mendes dunossauro

🟣
View GitHub Profile
@dunossauro
dunossauro / declarative.py
Created December 18, 2017 03:35
Rapidinha #3 - programação declarativa com python
from collections.abc import MutableSequence
from itertools import islice
from functools import reduce
class List(MutableSequence):
def __init__(self, seq):
self._d = list(seq)
def __delitem__(self, pos):
@dunossauro
dunossauro / stack.py
Last active January 2, 2018 18:16
Implementação simples de uma pilha em python
"""
Auxilio a pergunta feita no facebook.
https://www.facebook.com/groups/python.brasil/permalink/1289629901141877/
"""
class Stack(object):
def __init__(self):
"""Inicializa a pilha vazia."""
self.p = [] # Aqui P vai ser a lista interna
"""
Minhas considerações a pergunta no facebook:
https://www.facebook.com/groups/python.brasil/permalink/1296198200485047/
"""
def is_digit(func):
def inner(string):
if string.isdigit():
return func(string)
return False
@dunossauro
dunossauro / mock_stdout.py
Created January 12, 2018 03:15
Rapidinha de Python #5
"""
Gist para rapidinha #5: https://youtu.be/95_tm5jh5Gc
"""
from io import StringIO
from unittest import main, TestCase
from unittest.mock import patch
def stdout(string):
print(string)
@dunossauro
dunossauro / Revisão_lógica.ipynb
Created March 8, 2018 21:19
Revisão teoria dos conjuntos
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dunossauro
dunossauro / singleton_example.py
Created March 15, 2018 02:16
singleton decorator python
# copied from:
# https://stackoverflow.com/questions/31875/is-there-a-simple-elegant-way-to-define-singletons
class Singleton:
"""
A non-thread-safe helper class to ease implementing singletons.
This should be used as a decorator -- not a metaclass -- to the
class that should be a singleton.
The decorated class can define one `__init__` function that
@dunossauro
dunossauro / download_agendas.py
Last active March 21, 2018 02:20
Exemplo do download das agendas do www.mdic.gov.br
"""Exemplo agendas.
Não mencionar PEP8, feito em 5m
"""
from re import sub
from bs4 import BeautifulSoup as bs
from selenium import webdriver
from requests import get
browser = webdriver.Firefox()
@dunossauro
dunossauro / fn.py
Last active April 11, 2018 18:33
random par ou impar (functional example)
"""
Exemplo para ajudar a responder o problema de aninhamento em https://gist.github.com/AndersonFirmino/b0300923094a5a8450018c5bd32c9de8
"""
from itertools import filterfalse
from functools import partial
from random import choice, random
def pipe(*funcs):
def inner(data, funcs=funcs):
result = data
@dunossauro
dunossauro / app_1.py
Created May 4, 2018 14:58
Bottle merge route example
from bottle import Bottle
app = Bottle()
@app.get('/api/v1/test_route1')
def get_route1():
return '42'
"""
Minha contribuição ao buzzfizz funcional.
https://www.facebook.com/groups/python.brasil/permalink/1411831415588391/
"""
from functools import partial
from operator import mod, eq
def pipeline(*funcs):