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 sys | |
from collections import namedtuple | |
from unittest import TestCase, main as runtests | |
from enum import Enum | |
from pprint import pprint | |
Aluno = namedtuple('Aluno', 'nome notas media conceito') | |
class Conceito(Enum): |
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
#!/usr/bin/python -tt | |
import argparse | |
import re | |
from collections import Counter | |
def read(f): | |
return re.split(r'\W+', f.read().lower()) | |
def asc(counter): |
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
# models.py | |
CREDIT = 'C' | |
DEBIT = 'D' | |
class CategoryStatementQuerySet(QuerySet): | |
def credit(): | |
return self.filter(operacao__exact=CREDIT) | |
def debit(): |
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 decomp(num): | |
"""decomp(120) == (100, 20)""" | |
base = 10 ** (len(str(num))-1) | |
divisor, resto = divmod(num, base) | |
return divisor * base, resto | |
def radicais(resto): | |
while resto > 0: | |
base, resto = decomp(resto) |
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
# coding: utf-8 | |
# Código do Coding Dojo p/ Calouros do turno da manhã na Unilasalle | |
# 21/03/2017 | |
def robo(num): | |
msg=num | |
if num==3: | |
msg='fizz' | |
if num==5: |
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
# coding: utf-8 | |
# Código do Coding Dojo p/ Calouros do turno da noite na Unilasalle | |
# 21/03/2017 | |
def robo(x): | |
msg = x | |
if x == 3 or x == 6: | |
msg = 'fizz' | |
return msg |
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
"""IPython startup script to detect and inject VIRTUAL_ENV's site-packages dirs. | |
IPython can detect virtualenv's path and injects it's site-packages dirs into sys.path. | |
But it can go wrong if IPython's python version differs from VIRTUAL_ENV's. | |
This module fixes it looking for the actual directories. We use only old stdlib | |
resources so it can work with as many Python versions as possible. | |
References: | |
http://stackoverflow.com/a/30650831/443564 |
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
""" | |
This is a simple proof of concept demonstrating how I like to handle files during tests. | |
Setup | |
----- | |
wget http://hbn.link/1NoLHf0 | |
virtualenv .venv | |
source .venv/bin/activate | |
pip install django django-inmemorystorage |
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 test_html(self): | |
expectations = [('<form', 1), | |
('<input', 6), | |
('type="text"', 3), | |
('type="email"', 1), | |
('type="submit"', 1)] | |
with self.subTest(): | |
for text, count in expectations: | |
self.assertContains(self.resp, text, count) |
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
#!/usr/bin/env python | |
""" | |
Django SECRET_KEY generator. | |
""" | |
from django.utils.crypto import get_random_string | |
chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)' | |
print(get_random_string(50, chars)) |