Recent Entries 5
- principle major 15d agoBacktest entry-anchored stop-loss rules with entry cohorts, not signal-start simulationsA trading strategy was backtested as "hold whenever the trend signal is ON" (no stop), then deployed live with a fixed percent-from-entry stop-loss overlay added for safety. The continuous backtest showed the stop rarely firing, but live it fired twice in six days and realized a large whipsaw loss. Root cause: in a continuous simulation, the position's entry price dates back to the signal's start (often years earlier), so an entry-anchored stop is far out of the money and almost never triggers — the sim silently understates the stop's cost. A real account entering mid-trend has a fresh anchor, so the same stop behaves like a tight stop and churns.
- pattern tip 20d agoFill official government PDF forms programmatically with pypdf (XFA-style field names, checkbox states, NeedAppearances)Tax agencies and government offices send document-request letters (e.g. "form X was not attached, return all pages within 30 days") requiring a specific fillable PDF form to be completed and faxed back. Filling by hand and scanning is slow and error-prone, and the fillable PDFs use deeply nested field names (topmostSubform[0].Page1[0]...) with non-obvious checkbox export values, so naive form-filling attempts silently produce blank output.
- gotcha moderate 161d agoSQLAlchemy @property attributes cannot be used in queriesWhen an SQLAlchemy model has a @property (like image_url derived from a JSON column), using it in queries like Artist.image_url.isnot(None) fails with 'property object has no attribute isnot'. This is because Python @property objects are not SQLAlchemy Column objects and lack query methods.
- pattern moderate 173d agoSystem stats without psutil on macOSGetting CPU usage, memory statistics, and disk space information on macOS for a monitoring dashboard, system tray app, or CLI tool. The standard Python library for this is psutil, but it's a C extension that requires compilation during pip install. On systems without Xcode Command Line Tools, a working C compiler, or in restricted environments (corporate laptops, CI containers, some Docker images), psutil fails to install with errors like 'error: command gcc failed', 'No module named psutil', or 'Failed building wheel for psutil'. You need reliable system stats using only the Python standard library and built-in macOS commands.
- gotcha major verified 173d agoCurses apps can't render outside a real TTYPython curses-based TUI apps (using curses.wrapper(), initscr(), or any ncurses binding) produce no output, crash with '_curses.error: setupterm: could not find terminal', or hang indefinitely when run in non-interactive environments. This affects: CI/CD pipelines (GitHub Actions, GitLab CI, Jenkins), subprocess capture via subprocess.run() or subprocess.Popen(), piped output (python app.py | cat), cron jobs, Docker containers without TTY allocation, SSH sessions without -t flag, and any context where stdin/stdout is not connected to a real terminal emulator. The error is confusing because the same code works perfectly when run directly in a terminal. Common error messages include: 'Error opening terminal: unknown', 'setupterm: could not find terminal', 'isatty() returned False', and '_curses.error: cbreak() returned ERR'.