Created
October 5, 2022 21:01
-
-
Save kirisakow/16b77a236b9f7aca9d9801350a2ce1b1 to your computer and use it in GitHub Desktop.
Run Go in Google Colab with Gophernotes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "nbformat": 4, | |
| "nbformat_minor": 0, | |
| "metadata": { | |
| "colab": { | |
| "provenance": [], | |
| "collapsed_sections": [], | |
| "toc_visible": true, | |
| "include_colab_link": true | |
| }, | |
| "kernelspec": { | |
| "name": "gophernotes", | |
| "display_name": "Go" | |
| } | |
| }, | |
| "cells": [ | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "view-in-github", | |
| "colab_type": "text" | |
| }, | |
| "source": [ | |
| "<a href=\"https://colab.research.google.com/gist/kirisakow/16b77a236b9f7aca9d9801350a2ce1b1/run_golang_in_colab_with_gophernote.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "source": [ | |
| "# Run Go in Google Colab with Gophernotes" | |
| ], | |
| "metadata": { | |
| "id": "tnRm0YwmdLhl" | |
| } | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "source": [ | |
| "## Important prerequisite 1 / 3\n", | |
| "\n", | |
| "Open your Colab Notebook with a text editor and make sure the `kernelspec` key is set to work with Go, like so:\n", | |
| "\n", | |
| "```json\n", | |
| "{\n", | |
| " ⋮\n", | |
| " \"kernelspec\": {\n", | |
| " \"name\": \"gophernotes\",\n", | |
| " \"display_name\": \"Go\"\n", | |
| " }\n", | |
| " ⋮\n", | |
| "}\n", | |
| "```" | |
| ], | |
| "metadata": { | |
| "id": "UMudsO4-dQ03" | |
| } | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "QVJoUDPtb9gX" | |
| }, | |
| "source": [ | |
| "## Important prerequisite 2 / 3\n", | |
| "\n", | |
| "Run the cell below to install the Gophernotes kernel into the global Jupyter kernels:" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "metadata": { | |
| "id": "caT1iMfshw62" | |
| }, | |
| "source": [ | |
| "! add-apt-repository ppa:longsleep/golang-backports -y > /dev/null 2>&1\n", | |
| "! apt update > /dev/null 2>&1\n", | |
| "! apt install golang-go > /dev/null 2>&1\n", | |
| "! source <(go env)\n", | |
| "! go install github.com/gopherdata/gophernotes@latest > /dev/null 2>&1\n", | |
| "! cp ~/go/bin/gophernotes /usr/bin/\n", | |
| "path_to_gophernote_src_dir=\"~/go/pkg/mod/github.com/gopherdata/gophernotes*\"\n", | |
| "path_to_gophernote_kernel_target_dir=\"/usr/local/share/jupyter/kernels/gophernotes\"\n", | |
| "! [ ! -d \"$path_to_gophernote_kernel_target_dir\" ] && mkdir $path_to_gophernote_kernel_target_dir\n", | |
| "! [ -z \"$(ls -A $path_to_gophernote_kernel_target_dir)\" ] && cp $path_to_gophernote_src_dir/kernel/* $path_to_gophernote_kernel_target_dir" | |
| ], | |
| "execution_count": null, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "source": [ | |
| "## Important prerequisite 3 / 3\n", | |
| "\n", | |
| "Reload the page with Google Colab for Go to activate." | |
| ], | |
| "metadata": { | |
| "id": "wyH-FiPgxfIL" | |
| } | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "source": [ | |
| "Now you can work in Go:" | |
| ], | |
| "metadata": { | |
| "id": "5hDyl5WedYRK" | |
| } | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "package main\n", | |
| "\n", | |
| "import \"fmt\"\n", | |
| "\n", | |
| "func main() {\n", | |
| " fmt.Println(\"hello world\")\n", | |
| "}\n", | |
| "\n", | |
| "main()" | |
| ], | |
| "metadata": { | |
| "id": "Tee_e8-oaK7e", | |
| "outputId": "12548d17-9e10-406c-f555-2309716a1f7b", | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| } | |
| }, | |
| "execution_count": null, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stdout", | |
| "text": [ | |
| "hello world\n" | |
| ] | |
| } | |
| ] | |
| } | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment