Skip to content

Instantly share code, notes, and snippets.

@alexdlaird
Last active December 27, 2023 17:41
Show Gist options
  • Save alexdlaird/995876c7089c87f21418540ae216aa5c to your computer and use it in GitHub Desktop.
Save alexdlaird/995876c7089c87f21418540ae216aa5c to your computer and use it in GitHub Desktop.
hookee - Colab Example.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "hookee - Colab Example.ipynb",
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
},
"cells": [
{
"cell_type": "code",
"metadata": {
"id": "15FGYusaCg2s"
},
"source": [
"!pip install hookee"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "3Hrn3IwCfb85"
},
"source": [
"import random\n",
"\n",
"def colab_response_callback(request, response):\n",
" \"\"\"\n",
" This function illustrates how to get get arbitrary or dynamic data out of\n",
" Colab using the `response_callback` in `hookee`.\n",
" \"\"\"\n",
" random_number = random.randint(0, 1000)\n",
"\n",
" response.data = f\"<Colab><Number>{random_number}</Number></Colab>\"\n",
" response.headers[\"Content-Type\"] = \"application/xml\"\n",
" return response"
],
"execution_count": 2,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "vPc_bodwBQmM",
"cellView": "code"
},
"source": [
"import getpass\n",
"import logging\n",
"\n",
"from hookee import HookeeManager\n",
"from hookee.conf import Config\n",
"\n",
"print(\"Enter your authtoken, which can be copied from https://dashboard.ngrok.com/get-started/your-authtoken\")\n",
"auth_token = getpass.getpass()\n",
"\n",
"config = Config(auth_token=auth_token,\n",
" response_callback=colab_response_callback,\n",
" click_logging=True)\n",
"hookee_manager = HookeeManager(config=config)\n",
"hookee_manager.run()"
],
"execution_count": null,
"outputs": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment