Skip to content

Instantly share code, notes, and snippets.

View copocaneta's full-sized avatar

Thiago Bernardi copocaneta

View GitHub Profile
@copocaneta
copocaneta / 05-optimizing-data-flow.py
Last active December 9, 2024 23:06
Improve this code by optimizing data flow
# Loading all lines of a file into memory
with open("large_data.txt", "r") as file:
lines = file.readlines()
for line in lines:
# Processing each line
pass
@copocaneta
copocaneta / 04-uncluttering-methods.py
Last active December 9, 2024 23:12
Improve this code by uncluttering methods
def function():
print("Start of the function")
try:
# ... main code of the function ...
except Exception as e:
print(f"Error in function: {e}")
def another_function():
print("Start of the function")
try:
@copocaneta
copocaneta / 03-managing-complexity.py
Last active December 9, 2024 23:03
Improve this code by managing complexity
# Global variables for a product
product_name = "Product X"
product_price = 100
def display_product():
print(f"{product_name} costs ${product_price}")
def apply_discount(discount):
global product_price
product_price -= discount
@copocaneta
copocaneta / 02-eliminating-duplication.py
Last active December 9, 2024 23:02
Improve this code by eliminating duplication
# Repetitive code without functions
print("Processing data for client A")
# ... specific processing for client A ...
print("Saving results for client A")
print("Processing data for client B")
# ... specific processing for client B ...
print("Saving results for client B")
@copocaneta
copocaneta / 01-reducing-verbosity.py
Created December 9, 2024 22:25
Improve this code by reducing verbosity
# Calculating squares of even numbers with an imperative loop
numbers = [1, 2, 3, 4, 5]
even_squares = []
for n in numbers:
if n % 2 == 0:
square = n * n
even_squares.append(square)

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

@copocaneta
copocaneta / flask-sqlite.py
Created June 2, 2021 08:35 — forked from asyd/flask-sqlite.py
Enforce FK constraint for SQLite with when using flask-sqlalchemy
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
def create_app(config: str=None):
app = Flask(__name__, instance_relative_config=True)
if config is None:
app.config.from_pyfile('dev.py')
else:
logger.debug('Using %s as configuration', config)
app.config.from_pyfile(config)