forked from jakevdp/PythonDataScienceHandbook
-
Notifications
You must be signed in to change notification settings - Fork 7
Multi-language Syntax highlighting PR #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
amit1rrr
wants to merge
4
commits into
syntax_highlighting_pr
Choose a base branch
from
sql_cell_example
base: syntax_highlighting_pr
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
"source": [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
"%%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": [ | ||
"<IPython.core.display.Javascript object>" | ||
] | ||
}, | ||
"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 | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment on a long shell script
Reply via ReviewNB