LiveTypeScriptStable
Coding Challenges
A practice site for programming classes. Students solve problems in an in-browser editor and their code is checked against tests right away.
Result
The Java class I mentor practices on it during class. They like that the problems target what they learn in class and what's on their quizzes and exams, instead of broad LeetCode questions. The sandbox costs about $6 a month because it only runs while someone is coding.
Built with
- TypeScript
- Java
- Python
- JavaScript
- Next.js
- React
- Express
- Azure
- CodeMirror
- Piston
The problem
Students in the Java class I mentor needed practice that matches the course, with instant feedback instead of waiting for me to check their code. Paid code-runner APIs charge per run, which does not work for a whole class running code.
What I built
Solo. I wrote the problems and their tests, built the editor page and test runner, and set up the sandbox on Azure that runs Java and Python.
How it works
- 16 problems: 11 algorithm problems that each come in JavaScript and Python, plus 5 Java problems that follow the course.
- JavaScript tests run in the browser. Java and Python code goes to the backend, which runs it on Piston and checks the output of each test.
- Opening a Java or Python problem starts the sandbox VM. It turns off after 30 minutes without a run, and a daily limit plus a timer on the VM itself stop it from running all night.
- While the sandbox is starting, the API answers "not ready" instead of an error, so the page can tell students to wait a moment.
- Progress is saved per problem and language in the browser.
Key decisions
- 01
Self-hosted Piston
Paid code-runner APIs charge per run, so Java and Python run on a Piston sandbox I host on an Azure VM.
- 02
One VM that is off by default
An always-on scale set and load balancer cost about $60 a month sitting idle. One VM that starts on demand costs $0.22 for each hour it runs.
- 03
JavaScript in the browser
JavaScript problems run locally, so only Java and Python need the sandbox.
