Skip to content

Commit

Permalink
Update cat meme
Browse files Browse the repository at this point in the history
  • Loading branch information
Crazy-Rich-Meghan committed Nov 28, 2023
1 parent ad2c2ff commit 9e9df49
Show file tree
Hide file tree
Showing 3 changed files with 261 additions and 93 deletions.
139 changes: 131 additions & 8 deletions notebooks/lecture2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2162,21 +2162,144 @@
" <li>If a class <span style=color:blue;>GaussRuleImproved</span> derived from <span style=color:blue;>GaussRule</span> tries to override the function <span style=color:blue;>factor</span> an error will be thrown</li>\n",
"</ul>"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dc1b07d9",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 3,
"id": "13ca9c86",
"metadata": {},
"outputs": [
{
"ename": "NetworkError",
"evalue": "Protocol error (Page.navigate): Cannot navigate to invalid URL",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNetworkError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[3], line 72\u001b[0m\n\u001b[1;32m 63\u001b[0m pdf_output_file \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mslides.pdf\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 65\u001b[0m pool \u001b[38;5;241m=\u001b[39m concurrent\u001b[38;5;241m.\u001b[39mfutures\u001b[38;5;241m.\u001b[39mThreadPoolExecutor()\n\u001b[1;32m 66\u001b[0m pool\u001b[38;5;241m.\u001b[39msubmit(\n\u001b[1;32m 67\u001b[0m asyncio\u001b[38;5;241m.\u001b[39mrun,\n\u001b[1;32m 68\u001b[0m html_to_pdf(\n\u001b[1;32m 69\u001b[0m html_input_file,\n\u001b[1;32m 70\u001b[0m pdf_output_file\n\u001b[1;32m 71\u001b[0m ),\n\u001b[0;32m---> 72\u001b[0m )\u001b[38;5;241m.\u001b[39mresult()\n",
"File \u001b[0;32m~/anaconda3/lib/python3.11/concurrent/futures/_base.py:456\u001b[0m, in \u001b[0;36mFuture.result\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 454\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m CancelledError()\n\u001b[1;32m 455\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_state \u001b[38;5;241m==\u001b[39m FINISHED:\n\u001b[0;32m--> 456\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m__get_result()\n\u001b[1;32m 457\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 458\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mTimeoutError\u001b[39;00m()\n",
"File \u001b[0;32m~/anaconda3/lib/python3.11/concurrent/futures/_base.py:401\u001b[0m, in \u001b[0;36mFuture.__get_result\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 399\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_exception:\n\u001b[1;32m 400\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 401\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_exception\n\u001b[1;32m 402\u001b[0m \u001b[38;5;28;01mfinally\u001b[39;00m:\n\u001b[1;32m 403\u001b[0m \u001b[38;5;66;03m# Break a reference cycle with the exception in self._exception\u001b[39;00m\n\u001b[1;32m 404\u001b[0m \u001b[38;5;28mself\u001b[39m \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m\n",
"File \u001b[0;32m~/anaconda3/lib/python3.11/concurrent/futures/thread.py:58\u001b[0m, in \u001b[0;36m_WorkItem.run\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 55\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m\n\u001b[1;32m 57\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m---> 58\u001b[0m result \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mfn(\u001b[38;5;241m*\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mkwargs)\n\u001b[1;32m 59\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mBaseException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m exc:\n\u001b[1;32m 60\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mfuture\u001b[38;5;241m.\u001b[39mset_exception(exc)\n",
"File \u001b[0;32m~/anaconda3/lib/python3.11/asyncio/runners.py:190\u001b[0m, in \u001b[0;36mrun\u001b[0;34m(main, debug)\u001b[0m\n\u001b[1;32m 186\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mRuntimeError\u001b[39;00m(\n\u001b[1;32m 187\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124masyncio.run() cannot be called from a running event loop\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 189\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m Runner(debug\u001b[38;5;241m=\u001b[39mdebug) \u001b[38;5;28;01mas\u001b[39;00m runner:\n\u001b[0;32m--> 190\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m runner\u001b[38;5;241m.\u001b[39mrun(main)\n",
"File \u001b[0;32m~/anaconda3/lib/python3.11/asyncio/runners.py:118\u001b[0m, in \u001b[0;36mRunner.run\u001b[0;34m(self, coro, context)\u001b[0m\n\u001b[1;32m 116\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_interrupt_count \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m0\u001b[39m\n\u001b[1;32m 117\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 118\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_loop\u001b[38;5;241m.\u001b[39mrun_until_complete(task)\n\u001b[1;32m 119\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m exceptions\u001b[38;5;241m.\u001b[39mCancelledError:\n\u001b[1;32m 120\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_interrupt_count \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m0\u001b[39m:\n",
"File \u001b[0;32m~/anaconda3/lib/python3.11/asyncio/base_events.py:650\u001b[0m, in \u001b[0;36mBaseEventLoop.run_until_complete\u001b[0;34m(self, future)\u001b[0m\n\u001b[1;32m 647\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m future\u001b[38;5;241m.\u001b[39mdone():\n\u001b[1;32m 648\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mRuntimeError\u001b[39;00m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mEvent loop stopped before Future completed.\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m--> 650\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m future\u001b[38;5;241m.\u001b[39mresult()\n",
"Cell \u001b[0;32mIn[3], line 24\u001b[0m, in \u001b[0;36mhtml_to_pdf\u001b[0;34m(html_file, pdf_file, pyppeteer_args)\u001b[0m\n\u001b[1;32m 21\u001b[0m \u001b[38;5;28;01mawait\u001b[39;00m page\u001b[38;5;241m.\u001b[39msetViewport(\u001b[38;5;28mdict\u001b[39m(width\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m994\u001b[39m, height\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m768\u001b[39m))\n\u001b[1;32m 22\u001b[0m \u001b[38;5;28;01mawait\u001b[39;00m page\u001b[38;5;241m.\u001b[39memulateMedia(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mscreen\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m---> 24\u001b[0m \u001b[38;5;28;01mawait\u001b[39;00m page\u001b[38;5;241m.\u001b[39mgoto(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mfile://\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mhtml_file\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m, {\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mwaitUntil\u001b[39m\u001b[38;5;124m\"\u001b[39m: [\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mnetworkidle2\u001b[39m\u001b[38;5;124m\"\u001b[39m]})\n\u001b[1;32m 26\u001b[0m page_margins \u001b[38;5;241m=\u001b[39m {\n\u001b[1;32m 27\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mleft\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m20px\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m 28\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mright\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m20px\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m 29\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtop\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m30px\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m 30\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mbottom\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m30px\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m 31\u001b[0m }\n\u001b[1;32m 33\u001b[0m dimensions \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mawait\u001b[39;00m page\u001b[38;5;241m.\u001b[39mevaluate(\n\u001b[1;32m 34\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"() => {\u001b[39;00m\n\u001b[1;32m 35\u001b[0m \u001b[38;5;124;03m return {\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 42\u001b[0m \u001b[38;5;124;03m}\"\"\"\u001b[39;00m\n\u001b[1;32m 43\u001b[0m )\n",
"File \u001b[0;32m~/anaconda3/lib/python3.11/site-packages/pyppeteer/page.py:829\u001b[0m, in \u001b[0;36mPage.goto\u001b[0;34m(self, url, options, **kwargs)\u001b[0m\n\u001b[1;32m 826\u001b[0m timeout \u001b[38;5;241m=\u001b[39m options\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mtimeout\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_defaultNavigationTimeout)\n\u001b[1;32m 827\u001b[0m watcher \u001b[38;5;241m=\u001b[39m NavigatorWatcher(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_frameManager, mainFrame, timeout, options)\n\u001b[0;32m--> 829\u001b[0m result \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mawait\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_navigate(url, referrer)\n\u001b[1;32m 830\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m result \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 831\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m PageError(result)\n",
"File \u001b[0;32m~/anaconda3/lib/python3.11/site-packages/pyppeteer/page.py:843\u001b[0m, in \u001b[0;36mPage._navigate\u001b[0;34m(self, url, referrer)\u001b[0m\n\u001b[1;32m 842\u001b[0m \u001b[38;5;28;01masync\u001b[39;00m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_navigate\u001b[39m(\u001b[38;5;28mself\u001b[39m, url: \u001b[38;5;28mstr\u001b[39m, referrer: \u001b[38;5;28mstr\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Optional[\u001b[38;5;28mstr\u001b[39m]:\n\u001b[0;32m--> 843\u001b[0m response \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mawait\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_client\u001b[38;5;241m.\u001b[39msend(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mPage.navigate\u001b[39m\u001b[38;5;124m'\u001b[39m, {\u001b[38;5;124m'\u001b[39m\u001b[38;5;124murl\u001b[39m\u001b[38;5;124m'\u001b[39m: url, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mreferrer\u001b[39m\u001b[38;5;124m'\u001b[39m: referrer})\n\u001b[1;32m 844\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m response\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124merrorText\u001b[39m\u001b[38;5;124m'\u001b[39m):\n\u001b[1;32m 845\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mresponse[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124merrorText\u001b[39m\u001b[38;5;124m\"\u001b[39m]\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m at \u001b[39m\u001b[38;5;132;01m{\u001b[39;00murl\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m\n",
"\u001b[0;31mNetworkError\u001b[0m: Protocol error (Page.navigate): Cannot navigate to invalid URL"
]
}
],
"source": [
"import asyncio\n",
"import os\n",
"import tempfile\n",
"\n",
"from subprocess import PIPE, Popen\n",
"from pyppeteer import launch\n",
"\n",
"import concurrent.futures\n",
"\n",
"async def html_to_pdf(html_file, pdf_file, pyppeteer_args=None):\n",
" \"\"\"Convert a HTML file to a PDF\"\"\"\n",
" browser = await launch(\n",
" handleSIGINT=False,\n",
" handleSIGTERM=False,\n",
" handleSIGHUP=False,\n",
" headless=True,\n",
" args=[\"--no-sandbox\"],\n",
" )\n",
"\n",
" page = await browser.newPage()\n",
" await page.setViewport(dict(width=994, height=768))\n",
" await page.emulateMedia(\"screen\")\n",
"\n",
" await page.goto(f\"file://{html_file}\", {\"waitUntil\": [\"networkidle2\"]})\n",
"\n",
" page_margins = {\n",
" \"left\": \"20px\",\n",
" \"right\": \"20px\",\n",
" \"top\": \"30px\",\n",
" \"bottom\": \"30px\",\n",
" }\n",
"\n",
" dimensions = await page.evaluate(\n",
" \"\"\"() => {\n",
" return {\n",
" width: document.body.scrollWidth,\n",
" height: document.body.scrollHeight,\n",
" offsetWidth: document.body.offsetWidth,\n",
" offsetHeight: document.body.offsetHeight,\n",
" deviceScaleFactor: window.devicePixelRatio,\n",
" }\n",
" }\"\"\"\n",
" )\n",
" width = dimensions[\"width\"]\n",
" height = dimensions[\"height\"]\n",
"\n",
" await page.pdf(\n",
" {\n",
" \"path\": pdf_file,\n",
" \"format\": \"A4\",\n",
" \"printBackground\": True,\n",
" \"margin\": page_margins,\n",
" }\n",
" )\n",
"\n",
" await browser.close()\n",
"\n",
"\n",
"\n",
"if __name__ == \"__main__\":\n",
" \n",
" html_input_file = \"http://localhost:8888/notebooks/Desktop/Cpp-slides/OospCpp/notebooks/lecture2.ipynb#/slide-0-0?print-pdf\"\n",
" pdf_output_file = \"slides.pdf\"\n",
"\n",
" pool = concurrent.futures.ThreadPoolExecutor()\n",
" pool.submit(\n",
" asyncio.run,\n",
" html_to_pdf(\n",
" html_input_file,\n",
" pdf_output_file\n",
" ),\n",
" ).result()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2da6778b",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"celltoolbar": "Slideshow",
"kernelspec": {
"display_name": "C++17",
"language": "C++17",
"name": "xcpp17"
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": "text/x-c++src",
"file_extension": ".cpp",
"mimetype": "text/x-c++src",
"name": "c++",
"version": "17"
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.0"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 9e9df49

Please sign in to comment.