Code Visualizer

Step through Java, C++ or Python code line by line and watch the data change. I built it for explaining LeetCode and HackerRank solutions.

React · Python · Java (JDI) · GDB · Docker

Paste in a solution and step forward or back through it. The line about to run is highlighted, anything that just changed is marked, and the data is drawn the way you would sketch it on a whiteboard:

  • Arrays and strings with index pointers such as i, left and mid drawn above the cells, and 2D grids with the current cell outlined.
  • Hash maps, sets, stacks, queues and heaps, plus linked lists and binary trees labeled with the variables that point at each node.
  • The call stack, so recursion is visible frame by frame along with return values.

It also takes program input for HackerRank-style problems, can re-run as you type, and makes shareable links that carry the code.

  • Java runs on the server and is traced through the JVM's debugger interface (JDI).
  • C++ runs on the server and is traced with GDB and the libstdc++ pretty printers.
  • Python runs in your browser through Pyodide, so it works even when the server is down.

Anyone who opens the page can run Java and C++ on my server, so the container that runs it is locked down. It has no network access and a read-only filesystem, and Caddy reaches it through a Unix socket instead of a port. Each program runs as its own unprivileged user with no Linux capabilities, under limits of 10 seconds, 3,000 steps and 100 KB of output, and everything it started is killed when the run ends. Visitors get 30 server runs per 10 minutes.

The container is capped at one CPU, so a visitor running something heavy can't slow down this site or the other services on the same server.

  • React
  • Vite
  • Monaco
  • Python
  • Java
  • C++
  • GDB
  • Pyodide
  • Docker