Skip to content

Instantly share code, notes, and snippets.

View bbelderbos's full-sized avatar

Bob Belderbos bbelderbos

View GitHub Profile
from pathlib import Path
import csv
# set MARVIN_OPENAI_API_KEY in your environment variables
import marvin
from pydantic import BaseModel
import folium
class Location(BaseModel):
# initial code
def process_data(name, age, address, phone, email):
print(f"Processing data for {name}, {age}, living at {address}. Contact info: {phone}, {email}")
process_data("Alice", 30, "123 Main St", "555-1234", "[email protected]")
# refactored using dataclass
from dataclasses import dataclass
import os
from flask import Flask
import sentry_sdk
from dotenv import load_dotenv
load_dotenv()
SENTRY_DSN = os.getenv("SENTRY_DSN")
sentry_sdk.init(SENTRY_DSN)
repos:
- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
args: [--line-length, "79"]
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
class TransactionLimitExceededError(Exception):
"""Raised when a transaction exceeds the allowed limit."""
def __init__(self, amount, limit):
self.amount = amount
self.limit = limit
super().__init__(f"Transaction amount of {amount} exceeds the limit of {limit}.")
try:
# ok
def create_person(*args):
first_name, last_name, age = args
return {
'First Name': first_name,
'Last Name': last_name,
'Age': age
}
# Caller assumes the order: first name, last name, age.
import random
import pytest
from script import get_random_emails
@pytest.fixture(autouse=True)
def set_random_seed():
random.seed(123)
import csv
import random
DATA = "MOCK_DATA.csv"
def get_emails(data=DATA):
with open(data) as f:
reader = csv.reader(f)
next(reader)
>>> class Dog:
... def __init__(self, breed, color):
... self.breed = breed
... self.color = color
...
>>> dog1 = Dog("bulldog", "brown")
>>>
>>> dog1
<__main__.Dog object at 0x7fe114d36580>
>>> dog1.attr