-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
158 additions
and
113 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,115 +1,160 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"----------\n", | ||
"\n", | ||
"# Google Colab\n", | ||
"\n", | ||
"You can run this notebook in Google Colab. The cell below should be run only once, and then followed by a change of runtime to `Go (gonb)`. Ignore any loading errors. Refresh the browser before running any subsequent code. If you are not running the notebook in Google Colab, skip this section." | ||
] | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "view-in-github", | ||
"colab_type": "text" | ||
}, | ||
"source": [ | ||
"<a href=\"https://colab.research.google.com/github/sualeh/What-a-Character/blob/go/Notebooks/3_go_unicode_numbers.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "qqgDiO2uV2Uc" | ||
}, | ||
"source": [ | ||
"----------\n", | ||
"\n", | ||
"# Google Colab\n", | ||
"\n", | ||
"You can run this notebook in Google Colab. The cell below should be run only once, and then followed by a change of runtime to `Go (gonb)`. Ignore any loading errors. Refresh the browser before running any subsequent code. If you are not running the notebook in Google Colab, skip this section." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": { | ||
"cellView": "form", | ||
"id": "-cFeOCq_V2Ue", | ||
"outputId": "98f52646-a9ab-4277-a47f-a4090d9b8e9c", | ||
"colab": { | ||
"base_uri": "https://localhost:8080/" | ||
} | ||
}, | ||
"outputs": [ | ||
{ | ||
"output_type": "stream", | ||
"name": "stdout", | ||
"text": [ | ||
"Installing go ...env: GOROOT=/content/go\n", | ||
" done.\n", | ||
"go version go1.22.2 linux/amd64\n", | ||
"Installing gonb ... done.\n", | ||
"Installing goimports ... done.\n", | ||
"Installing gopls ... done.\n", | ||
"I0506 23:59:43.226480 4027 install.go:121] \u001b[7;39;32m[34fe7355]\u001b[0m Go (gonb) kernel configuration installed in \"/root/.local/share/jupyter/kernels/gonb/kernel.json\".\n", | ||
"Done!\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"#@title Prepare Google Colab for Go Kernel\n", | ||
"\n", | ||
"# Install Go and goimports.\n", | ||
"!echo -n \"Installing go ...\"\n", | ||
"!mkdir -p cache\n", | ||
"!wget -q -O cache/go.tar.gz 'https://go.dev/dl/go1.22.2.linux-amd64.tar.gz'\n", | ||
"!tar xzf cache/go.tar.gz\n", | ||
"%env GOROOT=/content/go\n", | ||
"!ln -sf \"/content/go/bin/go\" /usr/bin/go\n", | ||
"!echo \" done.\"\n", | ||
"!go version\n", | ||
"\n", | ||
"# Install gonb, goimports, gopls.\n", | ||
"!echo -n \"Installing gonb ...\"\n", | ||
"!go install github.com/janpfeifer/gonb@latest >& /tmp/output || cat /tmp/output\n", | ||
"!echo \" done.\"\n", | ||
"!ln -sf /root/go/bin/gonb /usr/bin/gonb\n", | ||
"\n", | ||
"!echo -n \"Installing goimports ...\"\n", | ||
"!go install golang.org/x/tools/cmd/goimports@latest >& /tmp/output || cat /tmp/output\n", | ||
"!echo \" done.\"\n", | ||
"!ln -sf /root/go/bin/goimports /usr/bin/goimports\n", | ||
"\n", | ||
"!echo -n \"Installing gopls ...\"\n", | ||
"!go install golang.org/x/tools/gopls@latest >& /tmp/output || cat /tmp/output\n", | ||
"!echo \" done.\"\n", | ||
"!ln -sf /root/go/bin/gopls /usr/bin/gopls\n", | ||
"\n", | ||
"# Install gonb kernel configuration.\n", | ||
"!gonb --install --logtostderr\n", | ||
"!echo \"Done!\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "nbGqpoHEV2Ue" | ||
}, | ||
"source": [ | ||
"----------" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "Sfqv-2qTV2Uf" | ||
}, | ||
"source": [ | ||
"# Parsing Numbers" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "o2vjDfgFV2Uf" | ||
}, | ||
"source": [ | ||
"## Handle Unicode Numbers\n", | ||
"\n", | ||
"Demonstrates number parsing functions can handle numeric values from other (non-English) languages." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": { | ||
"id": "LnAIU8XvV2Uf", | ||
"outputId": "5d61c7df-9858-4094-fb5b-167207af9068", | ||
"colab": { | ||
"base_uri": "https://localhost:8080/" | ||
} | ||
}, | ||
"outputs": [ | ||
{ | ||
"output_type": "stream", | ||
"name": "stdout", | ||
"text": [ | ||
"strconv.Atoi: parsing \"१२३४५६७८९०\": invalid syntax\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"%%\n", | ||
"hindiNumber := \"१२३४५६७८९०\"\n", | ||
"number, err := strconv.Atoi(hindiNumber)\n", | ||
"if err != nil {\n", | ||
" fmt.Println(err)\n", | ||
" return\n", | ||
"}\n", | ||
"\n", | ||
"fmt.Printf(\"%s = %d\\n\", hindiNumber, number)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Go (gonb)", | ||
"name": "gonb" | ||
}, | ||
"colab": { | ||
"provenance": [], | ||
"include_colab_link": true | ||
} | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"#@title Prepare Google Colab for Go Kernel\n", | ||
"\n", | ||
"# Install Go and goimports.\n", | ||
"!echo -n \"Installing go ...\"\n", | ||
"!mkdir -p cache\n", | ||
"!wget -q -O cache/go.tar.gz 'https://go.dev/dl/go1.22.2.linux-amd64.tar.gz'\n", | ||
"!tar xzf cache/go.tar.gz\n", | ||
"%env GOROOT=/content/go\n", | ||
"!ln -sf \"/content/go/bin/go\" /usr/bin/go\n", | ||
"!echo \" done.\"\n", | ||
"!go version\n", | ||
"\n", | ||
"# Install gonb, goimports, gopls.\n", | ||
"!echo -n \"Installing gonb ...\"\n", | ||
"!go install github.com/janpfeifer/gonb@latest >& /tmp/output || cat /tmp/output\n", | ||
"!echo \" done.\"\n", | ||
"!ln -sf /root/go/bin/gonb /usr/bin/gonb\n", | ||
"\n", | ||
"!echo -n \"Installing goimports ...\"\n", | ||
"!go install golang.org/x/tools/cmd/goimports@latest >& /tmp/output || cat /tmp/output\n", | ||
"!echo \" done.\"\n", | ||
"!ln -sf /root/go/bin/goimports /usr/bin/goimports\n", | ||
"\n", | ||
"!echo -n \"Installing gopls ...\"\n", | ||
"!go install golang.org/x/tools/gopls@latest >& /tmp/output || cat /tmp/output\n", | ||
"!echo \" done.\"\n", | ||
"!ln -sf /root/go/bin/gopls /usr/bin/gopls\n", | ||
"\n", | ||
"# Install gonb kernel configuration.\n", | ||
"!gonb --install --logtostderr\n", | ||
"!echo \"Done!\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"----------" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Parsing Numbers" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Handle Unicode Numbers\n", | ||
"\n", | ||
"Demonstrates number parsing functions can handle numeric values from other (non-English) languages." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"%%\n", | ||
"hindiNumber := \"१२३४५६७८९०\"\n", | ||
"number, err := strconv.Atoi(hindiNumber)\n", | ||
"if err != nil {\n", | ||
" fmt.Println(err)\n", | ||
" return\n", | ||
"}\n", | ||
"\n", | ||
"fmt.Printf(\"%s = %d\\n\", hindiNumber, number)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "base", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.5" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |