Wednesday, October 16, 2019

nbgitpuller bookmarklet

We use nbgitpuller with JupyterHub to distribute notebooks from GitHub. Nbgitpuller is a tool for copying a code repository from GitHub to your own Jupyter server.

Instead of manually formatting the nbgitpuller URLs or using a link generator, I wanted to automate the process. So here's a basic bookmarklet that automatically generates nbgitpuller links for our Callysto Hub:

javascript:(function(){var url=location.href;var res=url.split("/");var site=res[2];var user=res[3];var repo=res[4];var treeBlob=res[5];var branch=res[6];var nbgitputllerUrl="";if(site==""){if(treeBlob){var subPath=url.substring(url.indexOf(branch)+branch.length+1);nbgitputllerUrl+=encodeURIComponent(""+user+"/")+repo+"&branch="+branch+"&subPath="+subPath+"&depth=1";}else{nbgitputllerUrl+=url;}}window.prompt("Callysto nbgitpuller link",nbgitputllerUrl);})();

If you're not familiar with bookmarklets, they're basically bits of Javascript in the URL portion of a browser bookmark. To set one up, drag this link to your bookmark bar/menu:


Then when you are on a GitHub page you can click that bookmark and it will pop up a prompt with an nbgitpuller link to open that GitHub notebook or repository in CallystoHub.

Here is the code as a GitHub gist if you'd like to make your own and perhaps use JavaScript Cruncher to condense it to a single URL-encoded link.


I've also posted about a similar bookmarklet to open notebooks in Colab.

No comments: