Automatically convert images to base64

This commit is contained in:
Gelieza K 2023-08-04 17:01:07 +02:00
parent 9b563c984e
commit 13ee7880e7
18 changed files with 33825 additions and 100 deletions

View File

@ -35,12 +35,28 @@ EditURL = "https://github.com/fverdugo/XM_40017/blob/main/docs/src/notebooks/SCR
```
"""
function convert_embedded_img_to_base64(notebook_path)
doc = open(io->read(io, String), notebook_path)
# Regex matching: extract filename and base64 code
regex = r"attachments\\\":\s*\{\s*\\\"(?<filename>.*).png\\\":\s*\{\s*\\\"image/png\\\":\s*\\\"(?<base64code>.*)\\\""
res = eachmatch(regex, doc)
matches = collect(res)
# Replace img src with base64 code
for m in matches
filename = m[:filename]
base64 = m[:base64code]
doc = replace(doc, "attachment:$filename.png" => "data:image/png;base64,$base64")
end
write(notebook_path, doc);
end
# Write markdown file that includes notebook html
function create_md_nb_file( notebook_path )
global md_nb_template;
script_file = splitpath(notebook_path)[end]
script_name = splitext(script_file)[1]
content = replace( md_nb_template, "SCRIPT_NAME" => script_name)
content = replace(md_nb_template, "SCRIPT_NAME" => script_name)
md_path = joinpath(@__DIR__, "src", script_name * ".md" )
open(md_path, "w") do md_file
write(md_file, content)
@ -87,6 +103,7 @@ end
# Loop over notebooks and generate html and markdown
notebook_files = glob("*.ipynb", "docs/src/notebooks/")
for filepath in notebook_files
convert_embedded_img_to_base64(filepath)
create_md_nb_file(filepath)
filename_with_ext = splitpath(filepath)[end]
filename = splitext(filename_with_ext)[1]
@ -109,7 +126,7 @@ makedocs(;
"Julia Basics" => "julia_basics.md",
"Julia Asynchronous" => "julia_async.md",
"Julia Distributed" => "julia_distributed.md",
"Matrix Multiplication"=>"matrix_matrix.md",
"Matrix Multiplication"=>["Matrix Multiplication" => "matrix_matrix.md", "Solutions" => "sol_matrix_matrix.md"],
"Jacobi/SOR" => "julia_jacobi.md"
]],
)

View File

@ -0,0 +1,17 @@
function convert_embedded_img_to_base64(notebook_path)
doc = open(io->read(io, String), notebook_path)
# Regex matching: extract filename and base64 code
regex = r"attachments\\\":\s*\{\s*\\\"(?<filename>.*).png\\\":\s*\{\s*\\\"image/png\\\":\s*\\\"(?<base64code>.*)\\\""
res = eachmatch(regex, doc)
matches = collect(res)
# Replace img src with base64 code
for m in matches
global doc;
filename = m[:filename]
base64 = m[:base64code]
doc = replace(doc, "attachment:$filename.png" => "data:image/png;base64,$base64")
end
write(notebook_path, doc);
end

View File

@ -0,0 +1,30 @@
```@meta
EditURL = "https://github.com/fverdugo/XM_40017/blob/main/docs/src/notebooks/julia_distributed_test.ipynb"
```
```@raw html
<div class="admonition is-success">
<header class="admonition-header">Tip</header>
<div class="admonition-body">
<ul>
<li>
Download this notebook and run it locally on your machine [recommended]. Click <a href="notebooks/julia_distributed_test.ipynb" download>here</a>.
</li>
<li>
You can also run this notebook in the cloud using Binder. Click <a href="https://mybinder.org/v2/gh/fverdugo/XM_40017/gh-pages?filepath=dev/notebooks/julia_distributed_test.ipynb">here</a>
.
</li>
</ul>
</div>
</div>
```
```@raw html
<iframe id="notebook" src="../notebook-output/julia_distributed_test.html" style="width:100%"></iframe>
<script>
document.addEventListener('DOMContentLoaded', function(){
var myIframe = document.getElementById("notebook");
iFrameResize({log:true}, myIframe);
});
</script>
```

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,60 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "d6d12733",
"metadata": {},
"source": [
"# Solution to Matrix Multiplication Exercises\n",
"\n",
"## Implementation of Algorithm 3"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "be73e87a",
"metadata": {},
"outputs": [],
"source": [
"function matmul_dist_3!(C,A,B)\n",
" m = size(C,1)\n",
" n = size(C,2)\n",
" l = size(A,2)\n",
" @assert size(A,1) == m\n",
" @assert size(B,2) == n\n",
" @assert size(B,1) == l\n",
" @assert mod(m,nworkers()) == 0\n",
" # Implement here\n",
" nrows_w = div(m,nworkers())\n",
" @sync for (i,w) in enumerate(workers())\n",
" rows_w = (1:nrows_w) .+ (i-1)*nrows_w\n",
" Aw = A[rows_w,:]\n",
" ftr = @spawnat w begin\n",
" Cw = similar(Aw,nrows_w,n)\n",
" matmul_seq!(Cw,Aw,B)\n",
" Cw\n",
" end\n",
" @async C[rows_w,:] = fetch(ftr)\n",
" end\n",
" C\n",
"end"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.9.1",
"language": "julia",
"name": "julia-1.9"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.9.1"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

View File

@ -0,0 +1,30 @@
```@meta
EditURL = "https://github.com/fverdugo/XM_40017/blob/main/docs/src/notebooks/sol_matrix_matrix.ipynb"
```
```@raw html
<div class="admonition is-success">
<header class="admonition-header">Tip</header>
<div class="admonition-body">
<ul>
<li>
Download this notebook and run it locally on your machine [recommended]. Click <a href="notebooks/sol_matrix_matrix.ipynb" download>here</a>.
</li>
<li>
You can also run this notebook in the cloud using Binder. Click <a href="https://mybinder.org/v2/gh/fverdugo/XM_40017/gh-pages?filepath=dev/notebooks/sol_matrix_matrix.ipynb">here</a>
.
</li>
</ul>
</div>
</div>
```
```@raw html
<iframe id="notebook" src="../notebook-output/sol_matrix_matrix.html" style="width:100%"></iframe>
<script>
document.addEventListener('DOMContentLoaded', function(){
var myIframe = document.getElementById("notebook");
iFrameResize({log:true}, myIframe);
});
</script>
```