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
# The definitive guide to setup my Python workspace | |
# Author: Henrique Bastos <henrique@bastos.net> | |
# Updated: 2022-07-14 for reference. | |
PY3=3.10.4 | |
PY3TOOLS="youtube-dl s3cmd fabric pytest poetry requests" | |
VENVS=~/.ve | |
PROJS=~/workspace |
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 wordcount.cli import cli | |
from wordcount.gui import gui | |
if len(sys.argv) >= 2: | |
cli() | |
else: | |
gui() |
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 requests_futures.sessions import FuturesSession | |
def response_for_urls(urls): | |
"""Asynchronously get response for many urls.""" | |
with FuturesSession() as session: | |
futures = [ | |
session.get(url) for url in urls | |
] |
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
#!/usr/bin/env python | |
""" | |
Django SECRET_KEY generator. | |
""" | |
from django.utils.crypto import get_random_string | |
chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)' | |
print(get_random_string(50, chars)) |
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
""" | |
13. wordcount | |
Este desafio é um programa que conta palavras de um arquivo qualquer de duas | |
formas diferentes. | |
A. Lista todas as palavras por ordem alfabética indicando suas ocorrências. | |
Ou seja... |
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
"""Geometry""" | |
class Point: | |
def __init__(self, x, y): | |
self.x = x | |
self.y = y | |
def __eq__(self, other): | |
return self.x == other.x and self.y == other.y |
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 pytest | |
from abc import ABC, abstractmethod | |
class Animal(ABC): | |
@abstractmethod | |
def emit_sound(self): | |
pass | |
@abstractmethod |
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
""" | |
Write a function that determines if all alpha characters in a string | |
are surrounded (the characters immediately before and after) by a plus sign. | |
Function should return false if any alpha character present in the string isn't | |
surrounded by a plus sign. Otherwise the function should return true. | |
""" | |
def symbols(input_str: str) -> bool: | |
"""Fill your code bellow to make all tests pass.""" |
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 decimal import Decimal, ROUND_HALF_UP | |
class Money(Decimal): | |
def __new__(cls, value=0, decimal_precision=2): | |
number = super().__new__(cls, value) | |
if not number._is_precise(decimal_precision): | |
number = number._round(decimal_precision) | |
return number |
NewerOlder