Skip to content

Commit

Permalink
Add Go notebook, and update others
Browse files Browse the repository at this point in the history
  • Loading branch information
sualeh committed May 5, 2024
1 parent cc76cc3 commit e323e7a
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 16 deletions.
16 changes: 16 additions & 0 deletions Notebooks/1_c#_unicode_char_literals.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,24 @@
}
],
"metadata": {
"kernelspec": {
"display_name": ".NET (C#)",
"language": "C#",
"name": ".net-csharp"
},
"language_info": {
"name": "csharp"
},
"polyglot_notebook": {
"kernelInfo": {
"defaultKernelName": "csharp",
"items": [
{
"aliases": [],
"name": "csharp"
}
]
}
}
},
"nbformat": 4,
Expand Down
1 change: 1 addition & 0 deletions Notebooks/1_go_unicode_char_literals.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[{"file_id":"1vUd3SSoOm2K6UQLnkJQursZZx4CaIT_1","timestamp":1714945497637}]},"kernelspec":{"name":"gonb","display_name":"Go (gonb)"}},"cells":[{"cell_type":"markdown","source":["# Unicode Character Literals"],"metadata":{"id":"FWzjioUI63tT"}},{"cell_type":"markdown","source":["Run this notebook in Google Colab."],"metadata":{"id":"i-bezriyHDdD"}},{"cell_type":"code","execution_count":null,"metadata":{"id":"3PaXSu67xkrg","executionInfo":{"status":"ok","timestamp":1714945867744,"user_tz":240,"elapsed":102512,"user":{"displayName":"Sualeh Fatehi","userId":"04758152281280757291"}},"outputId":"7d5ee853-d919-442a-c2f1-742e82717f3d","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","I0505 21:51:07.403588 4366 install.go:121] \u001b[7;39;32m[b72d3c03]\u001b[0m Go (gonb) kernel configuration installed in \"/root/.local/share/jupyter/kernels/gonb/kernel.json\".\n","Done!\n"]}],"source":["#@title Install Go, `goimports` and GoNB code in Google Colab\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","source":["The cell above should be run only once, and then followed by a change of runtime to `Go (gonb)`. See detailed instructions above."],"metadata":{"id":"lbPHZ_rjOavo"}},{"cell_type":"markdown","source":["## Valid Character Literals"],"metadata":{"id":"HadGU80XudVz"}},{"cell_type":"code","source":["%%\n","ch1 := 'a'\n","ch2 := '東' // (Not an ASCII character!)\n","ch3 := '𐐀' // (Not a BMP character!)\n","// ch4 := '\\' // (Backslash is a syntax error in Go!)\n","\n","fmt.Printf(\"%c %c %c\\n\", ch1, ch2, ch3)"],"metadata":{"id":"FqH3tlqjsDpV","executionInfo":{"status":"ok","timestamp":1714946946017,"user_tz":240,"elapsed":481,"user":{"displayName":"Sualeh Fatehi","userId":"04758152281280757291"}},"outputId":"41d6db36-9726-49db-f332-b8917290a625","colab":{"base_uri":"https://localhost:8080/"}},"execution_count":1,"outputs":[{"output_type":"stream","name":"stdout","text":["a 東 𐐀\n"]}]},{"cell_type":"markdown","source":["## Unicode Notation in Strings\n","\n","- `\\uHHHH` - where H is a case-insensitive hexadecimal character\n","- Only supports the Basic Multilingual Plane"],"metadata":{"id":"FXz5BuqczgzZ"}},{"cell_type":"code","source":["%%\n","ch5 := '\\u00EA' // ‘ê’\n","str1 := \"a\\u00ea\\u00f1\\u00fcc\" // “aêñüc”\n","str2 := \"A\\u00EA\\u00F1\\u00FCC\" // “AêñüC”\n","\n","fmt.Printf(\"%c\\n\", ch5)\n","fmt.Println(str1)\n","fmt.Println(str2)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"aK16puWgzhsl","executionInfo":{"status":"ok","timestamp":1714947118452,"user_tz":240,"elapsed":616,"user":{"displayName":"Sualeh Fatehi","userId":"04758152281280757291"}},"outputId":"7a560cec-d4b4-4977-f026-05c2e3657f3b"},"execution_count":6,"outputs":[{"output_type":"stream","name":"stdout","text":["ê\n","aêñüc\n","AêñüC\n"]}]},{"cell_type":"markdown","source":["## Unicode Code Point Literals\n","\n","- `\\U00HHHHHH` for specifying code point plane and code point for characters outside the BMP"],"metadata":{"id":"prsKwd-m2nT_"}},{"cell_type":"code","source":["%%\n","str3 := \"\\U00010400\" // '𐐀'\n","\n","fmt.Println(str3)\n","fmt.Printf(\"length: %d\\n\", utf8.RuneCountInString(str3))"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"lVkkNx5S2oqi","executionInfo":{"status":"ok","timestamp":1714947868441,"user_tz":240,"elapsed":315,"user":{"displayName":"Sualeh Fatehi","userId":"04758152281280757291"}},"outputId":"febbed40-6623-4bfe-e6c4-4e9eba18ff6a"},"execution_count":10,"outputs":[{"output_type":"stream","name":"stdout","text":["𐐀\n","length: 1\n"]}]},{"cell_type":"markdown","source":["## Unicode Code Point Literals as Integers\n","\n","- `0xHHHHHH` for specifying code point plane and code point for characters outside the BMP\n","- Use the `chr()` function"],"metadata":{"id":"CtIvqiZy3C50"}},{"cell_type":"code","source":["%%\n","cp1 := '\\U00010400' // '𐐀'\n","str4 := string(cp1)\n","\n","fmt.Println(str4)\n","fmt.Printf(\"length: %d\\n\", utf8.RuneCountInString(str4))"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"mx9GXV4J3EtZ","executionInfo":{"status":"ok","timestamp":1714951765615,"user_tz":240,"elapsed":136,"user":{"displayName":"Sualeh Fatehi","userId":"04758152281280757291"}},"outputId":"8e98b5e4-e949-494e-f656-1a58ff1ae0b3"},"execution_count":13,"outputs":[{"output_type":"stream","name":"stdout","text":["𐐀\n","length: 1\n"]}]},{"cell_type":"markdown","source":["## Escape Sequences"],"metadata":{"id":"6nVgUBOTGmcY"}},{"cell_type":"code","source":["func printUnicode(ch rune) {\n"," fmt.Printf(\"\\\\u%04x\\n\", ch)\n","}\n","\n","%%\n","printUnicode('\\t')\n","printUnicode('\\b')\n","printUnicode('\\n')\n","printUnicode('\\r')\n","printUnicode('\\f')\n","printUnicode('\\'')\n","printUnicode('\"')\n","printUnicode('\\\\')"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"KMGAl1njGoJE","executionInfo":{"status":"ok","timestamp":1714952032909,"user_tz":240,"elapsed":657,"user":{"displayName":"Sualeh Fatehi","userId":"04758152281280757291"}},"outputId":"47be2164-bf77-4977-b215-8df2d084876b"},"execution_count":15,"outputs":[{"output_type":"stream","name":"stdout","text":["\\u0009\n","\\u0008\n","\\u000a\n","\\u000d\n","\\u000c\n","\\u0027\n","\\u0022\n","\\u005c\n"]}]}]}
4 changes: 3 additions & 1 deletion Notebooks/1_java_unicode_char_literals.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@
"String str1 = \"a\\u00ea\\u00f1\\u00fcc\"; // “aêñüc”\n",
"String str2 = \"A\\u00EA\\u00F1\\u00FCC\"; // “AêñüC”\n",
"\n",
"System.out.printf(\"%s%n%s%n%s%n\", ch5, str1, str2);"
"System.out.println(ch5);\n",
"System.out.println(str1);\n",
"System.out.println(str2);"
]
},
{
Expand Down
4 changes: 3 additions & 1 deletion Notebooks/1_javascript_unicode_char_literals.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@
"str1 = \"a\\u00ea\\u00f1\\u00fcc\"; // “aêñüc”\n",
"str2 = \"A\\u00EA\\u00F1\\u00FCC\"; // “AêñüC”\n",
"\n",
"console.log(ch5 + \"\\n\" + str1 + \"\\n\" + str2)"
"console.log(ch5)\n",
"console.log(str1)\n",
"console.log(str2)"
]
},
{
Expand Down
39 changes: 25 additions & 14 deletions Notebooks/1_python_unicode_char_literals.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,18 @@
"str1 = \"a\\u00ea\\u00f1\\u00fcc\" # “aêñüc”\n",
"str2 = \"A\\u00EA\\u00F1\\u00FCC\" # “AêñüC”\n",
"\n",
"print(f\"{ch5}\\n{str1}\\n{str2}\")"
"print(f\"{ch5}\")\n",
"print(f\"{str1}\")\n",
"print(f\"{str2}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Unicode Code Point Literals"
"## Unicode Code Point Literals\n",
"\n",
"- `\\U00HHHHHH` for specifying code point plane and code point for characters outside the BMP\n"
]
},
{
Expand All @@ -63,22 +67,29 @@
"metadata": {},
"outputs": [],
"source": [
"# \\U00HHHHHH\n",
"# specifying code point plane and code points\n",
"# for characters outside the BMP\n",
"\n",
"str3 = \"\\U00010400\" # '𐐀'\n",
"\n",
"print(str3)\n",
"print(f\"length: {len(str3)}\")\n",
"\n",
"# ----------------------------------------\n",
"# Code point notation\n",
"# 0xHHHHHH\n",
"# specifying code point plane and code point\n",
"# for characters outside the BMP\n",
"print(f\"length: {len(str3)}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Unicode Code Point Literals as Integers\n",
"\n",
"cp1 = 0x010400\n",
"- `0xHHHHHH` for specifying code point plane and code point for characters outside the BMP\n",
"- Use the `chr()` function"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"cp1 = 0x010400 # '𐐀'\n",
"str4 = chr(cp1)\n",
"\n",
"print(str4)\n",
Expand Down

0 comments on commit e323e7a

Please sign in to comment.