January 1, 2022
I’ve been using GitHub’s advanced search for quite some time now and am now shoehorning my own usage of it in as a Today I Learned post. Sue me. My most common use case is to search for a keyword or really small snippet of code to find more examples on how other people are getting by with the surrounding language, API, etc.
Recently I had to use the ‘virtualenv’ Python package to create a virtual environment in a piece of code. Looking at the User Guide section of the documentation there is a Programmatic API page, but for me it’s somewhat inadequate as there are no working examples aside from the paltry:
from virtualenv import cli_run
cli_run(["venv"])
This provides no real value as any surrounding operations, such as activating the virtual environment, installing packages to it, and deactivating the virtual environment, are left up to the end user to figure out. GitHub’s advanced search to the rescue!
Set virtualenv.cli_run language:Python
as the search input1 and it’s off to the races. From there, depending on the ambiguity of the search term, you might have to do a bit of trawling to find the bits that are most useful, but there’s a high degree of certainty that something is bound to come up. For example, here are some of the ones that ended up being valuable to me:
Theoretically the same value could be leveraged from GitLab’s search functionality, but my go-to is still GitHub for the time being as it’s just more popular and because of that has more examples I can use2.