Skip to content

Instantly share code, notes, and snippets.

@joefaron
Last active January 10, 2025 18:55
Show Gist options
  • Save joefaron/6950882a997d9785107f6088b33af918 to your computer and use it in GitHub Desktop.
Save joefaron/6950882a997d9785107f6088b33af918 to your computer and use it in GitHub Desktop.
@echo off
setlocal
:: ===================================================================
:: STREAMLIT HEALTH CHECK FOR CURSOR AI IDE YOLO MODE
:: DON’T PANIC EDITION v42
:: ===================================================================
:: Description:
:: ------------
:: This batch script runs a specified Streamlit application,
:: captures its output, detects any exceptions, and ensures that
:: the Streamlit process is terminated gracefully. YOLO mode allows cmd: health-check.bat
::
:: Author: Joe Faron
:: X: @joefaron
:: GitHub: https://github.com/joefaron
::
:: Example Prompt for Cursor Composer YOLO Mode:
:: ---------------------------------------------
:: fix @store.py based on:
::
:: Write simple, single-purpose functions.
:: Avoid repeating code; use loops and reusable modules instead.
:: Group related code into clearly named files (e.g., scraper_validation.py, data_analysis.py).
:: Avoid complex or deeply nested logic.
:: Stick to simple, readable patterns—avoid classes unless necessary.
:: Prioritize clarity over performance.
::
:: Start with small changes, recursively checking that the Streamlit code runs.
::
:: After code changes, verify it passes health check without an exception.
::
:: Steps:
:: 1. Run the powershell cmd: (YOLO MODE!)
:: .\health-check.bat
:: 2. Wait 3 seconds to verify Output:
:: Check if output contains:
:: "Exception: ____"
:: 3. If found, debug the issue and retry from Step 1.
::
:: CREATE MECE TASK LIST. DON'T STOP UNTIL YOU'VE MADE 10 GOOD FIXES.
::
:: Notes:
:: ------
:: - Ensure that Streamlit is installed and accessible in your PATH.
:: - Customize the `index-streamlit-with-exception.py` to point to your Streamlit script.
::
:: ===================================================================
::
:: __ _____
:: |__| ____ _____/ ____\____ _______ ____ ____
:: | |/ _ \_/ __ \ __\\__ \\_ __ \/ _ \ / \
:: | ( <_> ) ___/| | / __ \| | \( <_> ) | \
:: /\__| |\____/ \___ >__| (____ /__| \____/|___| /
:: \______| \/ \/ \/
::
:: ===================================================================
:: Remove temp_output.txt if it exists at the start
if exist temp_output.txt del temp_output.txt
echo CURSOR: Wait 3 seconds to check for exceptions below...
:: Run the Streamlit command and redirect output
start /b cmd /c "streamlit run can_scraper.py" > temp_output.txt 2>&1
:: Wait for 2 seconds to allow Streamlit to start
timeout /t 2 > nul
:: Determine if PowerShell is available
powershell -Command "exit 0" >nul 2>&1
if %errorlevel% equ 0 (
:: Use PowerShell to find the Streamlit (Python) process
for /f "usebackq tokens=*" %%i in (`powershell -Command "Get-Process | Where-Object { $_.Path -like '*streamlit*' } | Select-Object -First 1 -ExpandProperty Id"`) do set pid=%%i
) else (
:: Use WMIC as a fallback (if PowerShell is unavailable)
for /f "tokens=2 delims=," %%i in ('wmic process where "CommandLine like '%%streamlit%%'" get ProcessId /format:csv ^| findstr /r [0-9]') do set pid=%%i
)
:: Kill the Streamlit process if found
if defined pid (
taskkill /pid %pid% /f > nul
echo Process with PID %pid% terminated. > nul
:: Ensure the process is fully terminated
powershell -Command "Start-Sleep -Seconds 2" > nul 2>&1
) else (
echo Process not found. > nul
)
:: Attempt to access the output file
:retry
set /a retry_count+=1
type temp_output.txt > nul 2>&1
if %errorlevel% neq 0 (
if %retry_count% lss 5 (
timeout /t 1 > nul
goto retry
) else (
echo Failed to access output file. > nul
goto cleanup
)
)
:: Display the output of the Streamlit command
echo.
echo Output from Streamlit command:
echo -----------------------------
type temp_output.txt
:cleanup
:: Clean up temporary files
if exist temp_output.txt del temp_output.txt
endlocal
@joefaron
Copy link
Author

joefaron commented Jan 10, 2025

orig prompt was:

fix @store.py  based on: 

Write simple, single-purpose functions.
Avoid repeating code; use loops and reusable modules instead.
Group related code into clearly named files (e.g., scraper_validation.py, data_analysis.py).
Avoid complex or deeply nested logic.
Stick to simple, readable patterns—avoid classes unless necessary.
Prioritize clarity over performance.

start with small changes, recursively checking that the streamlit code runs.


After code changes, verify it passes health check without an exception.
Steps:
1. Run the cmd:  (YOLO MODE!)
   health-check.bat
2. Verify Output:  
   Check if output contains:
   "Exception: ____"
   If found, debug the issue and retry from Step 1.

CREATE MECE TASK LIST. DON'T STOP UNTIL YOU'VE MADE 10 GOOD FIXES.

first go at it.. works well.. big issue was cursor breaking streamlit.. would be nicer to simplify the exception checking somehow.. as it'll open up many windows in chrome, or whatever your default is for cursor ide terminal cmds.

it'll still do stuff like this tho:
image

and get perma stuck like this: :\

image

@joefaron
Copy link
Author

posted question for improvement on cursor forum and streamlit forums.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment