Skip to content

Instantly share code, notes, and snippets.

View estevaofon's full-sized avatar
🐍
Python powered

Estevao Fonseca estevaofon

🐍
Python powered
View GitHub Profile
{
"security.workspace.trust.untrustedFiles": "open",
"editor.unicodeHighlight.nonBasicASCII": false,
"python.linting.flake8Enabled": false,
"python.linting.enabled": false,
"python.linting.pylintEnabled": true,
"terminal.integrated.shellArgs.windows": [
"-ExecutionPolicy",
"Bypass"
],
import os
import shutil
from PIL import Image
def is_image(file_path):
try:
with Image.open(file_path) as img:
return True
except (IOError, FileNotFoundError):
import pygments
from pygments.lexers import PythonLexer
from pygments.formatters import HtmlFormatter
import sys
def python_to_html(input_file, output_file):
# Read the Python code from the input file
with open(input_file, 'r', encoding='utf-8') as f:
code = f.read()
@dataclass
class Pessoa:
nome: str
idade: int
skills: list = field(default_factory=list)
data: datetime = field(default_factory=datetime.now)
contador: int = field(default=0, init=False, repr=False)
def __post_init__(self):
Pessoa.contador += 1
@estevaofon
estevaofon / timer_decorator.py
Created April 12, 2024 18:24
Decorator to log execution time of functions
import time
import functools
def log_time(func):
"""Decorator to log the execution time of a function."""
@functools.wraps(func)
def wrapper(*args, **kwargs):
start_time = time.time() # Capture the start time
result = func(*args, **kwargs) # Execute the function
@estevaofon
estevaofon / mega_sena_zuera.py
Last active January 13, 2024 20:28
mega_sena_zuera
import random
from tqdm import tqdm # instale com pip install tqdm
import time
def digitar_mensagem(mensagem):
for char in mensagem:
print(char, end='', flush=True)
time.sleep(0.05)
print()
def gen_random(a, c, m):
seed = 4
def make_random():
nonlocal seed, a, c, m
seed = ((seed * a)+c) % m
return seed
return make_random
my_random = gen_random(5, 8, 7)
import os
import shutil
def main():
# Diretório a ser analisado
directory = '.'
# Nome do script atual
current_script = os.path.basename(__file__)
__author__ = "Nicholas White"
# Copyright (c) 2012 Nicholas White -- see LICENSE for details
# https://github.com/nickwah
import random
from PIL import Image
# Color mapping gleefully stolen from:
# https://github.com/rendro/vintageJS/ by Robert Fleischmann
import curses
import time
class Tamagoshi:
def __init__(self):
self.life = 100
self.evolved = False
tamagoshi = Tamagoshi()
fed = time.time()
born = time.time()