This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """Single-file Pyodide exercise starter. | |
| Run: | |
| python pyodide_starter.py | |
| Writes index.html next to this file and serves it on http://localhost:8765. | |
| Open the URL, hit "Run tests", and watch pytest run inside the browser | |
| against a small stdlib Pybites Bite (anagrams). Edit the HTML to swap in | |
| your own exercises. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # /// script | |
| # requires-python = ">=3.12" | |
| # dependencies = [ | |
| # "anthropic>=0.40", | |
| # "httpx>=0.27", | |
| # "openai>=1.50", | |
| # "python-decouple>=3.8", | |
| # ] | |
| # /// | |
| # AI trend digest: fetch HN + Reddit concurrently, rank with an LLM, print markdown. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Finite State Machine — GitHub PR workflow | |
| Full implementation + tests from: https://belderbos.dev/blog/build-finite-state-machine-python | |
| Run: uvx pytest fsm.py -v | |
| """ | |
| import pytest | |
| # --- Implementation --- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import asyncio | |
| import random | |
| from datastar_py import ServerSentEventGenerator as SSE | |
| from datastar_py.fastapi import DatastarResponse | |
| from fastapi import FastAPI, Request | |
| from fastapi.responses import HTMLResponse | |
| from fastapi.templating import Jinja2Templates | |
| app = FastAPI(title="Datastar Stock Ticker") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # /// script | |
| # dependencies = [ | |
| # "python-decouple", | |
| # "requests", | |
| # ] | |
| # /// | |
| import argparse | |
| import json | |
| import sys |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 1) Literal patterns: Cleanly dispatch on exact values (great for status codes and enums). | |
| def handle_response(status: int) -> str: | |
| match status: | |
| case 200: | |
| return "OK" | |
| case 404: | |
| return "Not Found" | |
| case 500: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from collections import defaultdict | |
| from graphlib import TopologicalSorter | |
| from heapq import heappush, heappop, heapify | |
| def topo_lex(pairs): | |
| deps = defaultdict(set) # node -> set(dependencies) | |
| for a, b in pairs: | |
| deps.setdefault(a, set()) | |
| deps[b].add(a) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| from pathlib import Path | |
| import sys | |
| from urllib.request import urlretrieve | |
| API = "https://rustplatform.com/api/" | |
| DOWNLOAD_FILE = "exercises.json" | |
| if not Path(DOWNLOAD_FILE).exists(): | |
| urlretrieve(API, DOWNLOAD_FILE) | |
| print(f"Saved to {DOWNLOAD_FILE}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function vid { | |
| uvx --from pybites-search search video "$@" | |
| } | |
| function tip { | |
| uvx --from pybites-search search tip "$@" | |
| } | |
| function pod { | |
| uvx --from pybites-search search podcast "$@" | |
| } | |
| function bite { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # start rust alarm app script/process when opening terminal, but only one time | |
| function run_alarm_if_not_running { | |
| if ! pgrep -f "alarm -m 45 -M" > /dev/null; then | |
| echo "Starting alarm..." | |
| alarm -m 45 -M "stand up" -t 2 -r & | |
| fi | |
| } | |
| run_alarm_if_not_running |
NewerOlder