diff --git a/multi_language_notebook.ipynb b/multi_language_notebook.ipynb index e1d5ba809..24cf21f7b 100644 --- a/multi_language_notebook.ipynb +++ b/multi_language_notebook.ipynb @@ -31,6 +31,7 @@ "source": [ "%%bash\n", "echo 'Hello from Bash!'\n", + "pwd\n", "ls -l" ] }, @@ -43,9 +44,53 @@ "source": [ "%%sh\n", "pwd\n", + "ls -l\n", "whoami" ] }, + { + "cell_type": "code", + "execution_count": 3, + "id": "9487d9b3-ad64-4b9f-931f-f28de866b679", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "UsageError: %%script is a cell magic, but the cell body is empty.\n" + ] + } + ], + "source": [ + "%%script bash\n", + "#!/bin/bash\n", + "\n", + "# clone the repository\n", + "git clone http://github.com/garden/tree\n", + "\n", + "# generate HTTPS credentials\n", + "cd tree\n", + "openssl genrsa -aes256 -out https.key 1024\n", + "openssl req -new -nodes -key https.key -out https.csr\n", + "openssl x509 -req -days 365 -in https.csr -signkey https.key -out https.crt\n", + "cp https.key{,.orig}\n", + "openssl rsa -in https.key.orig -out https.key\n", + "\n", + "# start the server in HTTPS mode\n", + "cd web\n", + "sudo node ../server.js 443 'yes' >> ../node.log &\n", + "\n", + "# here is how to stop the server\n", + "for pid in `ps aux | grep 'node ../server.js' | awk '{print $2}'` ; do\n", + " sudo kill -9 $pid 2> /dev/null\n", + "done\n", + "\n", + "exit 0" + ] + }, { "cell_type": "code", "execution_count": null, @@ -68,6 +113,122 @@ "console.log('Hello from JavaScript');" ] }, + { + "cell_type": "code", + "execution_count": 1, + "id": "91a6781a-0dfd-4dd9-8257-fe68d7184662", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "data": { + "application/javascript": [ + "\n", + "function StringStream(string) {\n", + " this.pos = 0;\n", + " this.string = string;\n", + "}\n", + "\n", + "StringStream.prototype = {\n", + " done: function() {return this.pos >= this.string.length;},\n", + " peek: function() {return this.string.charAt(this.pos);},\n", + " next: function() {\n", + " if (this.pos < this.string.length)\n", + " return this.string.charAt(this.pos++);\n", + " },\n", + " eat: function(match) {\n", + " var ch = this.string.charAt(this.pos);\n", + " if (typeof match == \"string\") var ok = ch == match;\n", + " else var ok = ch && match.test ? match.test(ch) : match(ch);\n", + " if (ok) {this.pos++; return ch;}\n", + " },\n", + " eatWhile: function(match) {\n", + " var start = this.pos;\n", + " while (this.eat(match));\n", + " if (this.pos > start) return this.string.slice(start, this.pos);\n", + " },\n", + " backUp: function(n) {this.pos -= n;},\n", + " column: function() {return this.pos;},\n", + " eatSpace: function() {\n", + " var start = this.pos;\n", + " while (/\\s/.test(this.string.charAt(this.pos))) this.pos++;\n", + " return this.pos - start;\n", + " },\n", + " match: function(pattern, consume, caseInsensitive) {\n", + " if (typeof pattern == \"string\") {\n", + " function cased(str) {return caseInsensitive ? str.toLowerCase() : str;}\n", + " if (cased(this.string).indexOf(cased(pattern), this.pos) == this.pos) {\n", + " if (consume !== false) this.pos += str.length;\n", + " return true;\n", + " }\n", + " }\n", + " else {\n", + " var match = this.string.slice(this.pos).match(pattern);\n", + " if (match && consume !== false) this.pos += match[0].length;\n", + " return match;\n", + " }\n", + " }\n", + "};\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "%%javascript\n", + "\n", + "function StringStream(string) {\n", + " this.pos = 0;\n", + " this.string = string;\n", + "}\n", + "\n", + "StringStream.prototype = {\n", + " done: function() {return this.pos >= this.string.length;},\n", + " peek: function() {return this.string.charAt(this.pos);},\n", + " next: function() {\n", + " if (this.pos < this.string.length)\n", + " return this.string.charAt(this.pos++);\n", + " },\n", + " eat: function(match) {\n", + " var ch = this.string.charAt(this.pos);\n", + " if (typeof match == \"string\") var ok = ch == match;\n", + " else var ok = ch && match.test ? match.test(ch) : match(ch);\n", + " if (ok) {this.pos++; return ch;}\n", + " },\n", + " eatWhile: function(match) {\n", + " var start = this.pos;\n", + " while (this.eat(match));\n", + " if (this.pos > start) return this.string.slice(start, this.pos);\n", + " },\n", + " backUp: function(n) {this.pos -= n;},\n", + " column: function() {return this.pos;},\n", + " eatSpace: function() {\n", + " var start = this.pos;\n", + " while (/\\s/.test(this.string.charAt(this.pos))) this.pos++;\n", + " return this.pos - start;\n", + " },\n", + " match: function(pattern, consume, caseInsensitive) {\n", + " if (typeof pattern == \"string\") {\n", + " function cased(str) {return caseInsensitive ? str.toLowerCase() : str;}\n", + " if (cased(this.string).indexOf(cased(pattern), this.pos) == this.pos) {\n", + " if (consume !== false) this.pos += str.length;\n", + " return true;\n", + " }\n", + " }\n", + " else {\n", + " var match = this.string.slice(this.pos).match(pattern);\n", + " if (match && consume !== false) this.pos += match[0].length;\n", + " return match;\n", + " }\n", + " }\n", + "};\n" + ] + }, { "cell_type": "code", "execution_count": null, @@ -145,9 +306,100 @@ "%%r\n", "hist(c(1,2,3,3,2,1,4,5,6), col='blue', main='Sample Histogram')" ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "ae5219a6-9d02-41f0-acd2-577c16afec09", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "UsageError: Cell magic `%%r` not found.\n" + ] + } + ], + "source": [ + "%%r\n", + "\n", + "X <- list(height = 5.4, weight = 54)\n", + "cat(\"Printing objects: \"); print(X)\n", + "print(\"Accessing individual elements:\")\n", + "cat(sprintf(\"Your height is %s and your weight is %s\\n\", X$height, X$weight))\n", + "\n", + "# Functions:\n", + "square <- function(x) {\n", + " return(x * x)\n", + "}\n", + "cat(sprintf(\"The square of 3 is %s\\n\", square(3)))\n", + "\n", + "# In R, the last expression in a function is, by default, what is\n", + "# returned. The idiomatic way to write the function is:\n", + "square <- function(x) {\n", + " x * x\n", + "}\n", + "# or, for functions with short content:\n", + "square <- function(x) x * x\n", + "\n", + "# Function arguments with default values:\n", + "cube <- function(x = 5) x * x * x\n", + "cat(sprintf(\"Calling cube with 2 : %s\\n\", cube(2)) # will give 2^3\n", + "cat(sprintf(\"Calling cube : %s\\n\", cube()) # will default to 5^3.\n", + "\n", + "powers <- function(x) list(x2 = x*x, x3 = x*x*x, x4 = x*x*x*x)\n", + "\n", + "cat(\"Powers of 3: \"); print(powers(3))\n", + "\n", + "# Data frames\n", + "df <- data.frame(letters = letters[1:5], '#letter' = 1:5)\n", + "print(df$letters)\n", + "print(df$`#letter`)\n", + "\n", + "# Operators:\n", + "m1 <- matrix(1:6, 2, 3)\n", + "m2 <- m1 %*% t(m1)\n", + "cat(\"Matrix product: \"); print(m2)\n", + "\n", + "# Assignments:\n", + "a <- 1\n", + "b <<- 2\n", + "c = 3\n", + "4 -> d\n", + "5 ->> e\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d999404a-768d-4b69-ae22-27b600a2e151", + "metadata": {}, + "outputs": [], + "source": [] } ], - "metadata": {}, + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.8.13" + } + }, "nbformat": 4, "nbformat_minor": 5 }