Skip to content

Instantly share code, notes, and snippets.

View bbelderbos's full-sized avatar

Bob Belderbos bbelderbos

View GitHub Profile
# /// script
# dependencies = [
# "marvin",
# ]
# ///
import os
import sys
import argparse
import marvin
from pydantic import BaseModel, Field
# /// script
# dependencies = [
# "marvin",
# ]
# ///
import os
import sys
import argparse
from pydantic import BaseModel, Field
# /// script
# dependencies = [
# "bs4",
# "httpx",
# "typer"
# ]
# ///
import textwrap
from bs4 import BeautifulSoup
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.