All code examples now come with a “View on GitHub” button:
This was previously present only if the user had published their solution to GitHub. Now it’s available on all code examples.
All code examples now come with a “View on GitHub” button:
This was previously present only if the user had published their solution to GitHub. Now it’s available on all code examples.
Our goal here was to address one of the common complaints with code examples: since code examples only highlight specific files, it’s impossible to view files that aren’t highlighted.
We initially thought of just adding all files to the code examples UI but realized that there’d be a ton of cases to handle to offer good UX:
These cases pretty much ruled out rolling our own UI. We decided to use GitHub for this instead since (a) GitHub has already solved these problems well and (b) it’s a UI that users are comfortable with.
Most of the engineering work here was around ensuring we stay within GitHub’s per-org repository limits. GitHub enforces a maximum of 100k repositories per organization. We’ve got thousands of users viewing code examples on a given day so we’d run into that limit pretty quickly if we created a repository for each code example.
We decided to use something like a LRU cache:
Our primary worry here is cache misses – each miss could cause a wait for ~5-10 seconds while we create a repository and push new code to it. We’ll monitor these closely. There could be some opportunities to improve our cache hit rate by pre-empting user clicks, for example by creating a github repository when a user “expands” a code example and not only when then click on the “view on github” link.