The following script will generate a simple markdown worklog in the format listed below. It correctly handles the partial weeks at the beginning and the end of the year.
# Worklog
## Week 1 [2025-01-01 - 2025-01-03]| export async function runConcurrentAsync<T, A extends IterableIterator<unknown>>(tasks: Task<T>[], argsList: A[] = [], concurrency = 5): Promise<T[]> { | |
| const semaphore = new Semaphore(concurrency); | |
| const promises = tasks.map(async (task, index) => { | |
| await semaphore.acquire(); | |
| try { | |
| const args = argsList[index] || []; | |
| return await task(...args); | |
| } finally { | |
| semaphore.release(); | |
| } |
| # This is running on an aws lambda instance with a CloudWatch trigger: | |
| # Trigger is cron(0 17 * * ? *) | |
| # CSV is from https://www.mlb.com/cubs/schedule/downloadable-schedule | |
| import json | |
| from urllib.request import urlopen, Request | |
| from urllib.parse import urlencode | |
| from os import getenv | |
| from csv import DictReader | |
| from datetime import datetime |
| import trio | |
| async def main(): | |
| async with ws_connect("ws://127.0.0.1:8765") as websockets: | |
| await websockets.send("Hello, world.") | |
| message = await websockets.recv() | |
| print(message) | |
| trio.run(main) |
| from fastapi import APIRouter, FastAPI | |
| from utils import create_versioning_docs | |
| app = FastAPI(docs_url=None, redoc_url=None) | |
| v1_router = APIRouter(prefix="/v1") | |
| v2_router = APIRouter(prefix="/v2") |
| """ Snippet that demonstrates how to use Gunicorn with Uvicorn workers in code. | |
| Feel free to run: | |
| - `python main.py` - to use uvicorn. | |
| - `ENV=prod python main.py` - to use gunicorn with uvicorn workers. | |
| Reference: https://docs.gunicorn.org/en/stable/custom.html | |
| """ |
| from typing import Type, TypeVar | |
| class Base: | |
| common: str = "Data" | |
| class ImportModel(Base): | |
| pass |