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
| """Async retry decorator with exponential backoff + jitter. | |
| @retry(tries=5, base=0.5) | |
| async def fetch_price(symbol: str) -> float: | |
| async with aiohttp.ClientSession() as s: | |
| async with s.get(url) as r: | |
| r.raise_for_status() | |
| return (await r.json())["price"] | |
| """ | |
| import asyncio |
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
| /** | |
| * useDebounce — delays a value update until input settles. | |
| * Perfect for search boxes, API calls, expensive re-renders. | |
| * | |
| * const [q, setQ] = useState(""); | |
| * const debounced = useDebounce(q, 300); | |
| * useEffect(() => { search(debounced); }, [debounced]); | |
| */ | |
| import { useEffect, useState } from "react"; |
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
| """Minimal FastAPI JWT auth — login + protected route + dependency.""" | |
| from datetime import datetime, timedelta, timezone | |
| import jwt | |
| from fastapi import Depends, FastAPI, HTTPException, status | |
| from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm | |
| from passlib.hash import bcrypt | |
| SECRET = "change-me-in-prod" | |
| ALGO = "HS256" |
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
| """RSI (Relative Strength Index) — pure pandas, vectorized, no loops. | |
| Usage: | |
| import pandas as pd | |
| df = pd.read_csv("btc.csv") | |
| df["rsi"] = rsi(df["close"], period=14) | |
| """ | |
| import pandas as pd |