Skip to content

Commit

Permalink
Deploy to GitHub pages
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Nov 19, 2023
0 parents commit b34332a
Show file tree
Hide file tree
Showing 9 changed files with 449 additions and 0 deletions.
1 change: 1 addition & 0 deletions CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
emilsadek.com
76 changes: 76 additions & 0 deletions blog/learn-ml/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<!DOCTYPE html>
<html lang="en"><head>
<title>Learn Machine Learning</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="author" content="Emil Sadek">
<meta name="description" content="Emil Sadek is a software developer with a profound interest in programming, design, data, and machine learning.">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
<link rel="stylesheet" href="/static/style.css">
<link rel="icon" type="image/png" href="/static/favicon.png">
<script type="text/javascript">
(function(c,l,a,r,i,t,y){
c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
})(window, document, "clarity", "script", "jsroqq3khc");
</script>
</head>
<body>
<nav class="navbar navbar-expand-md navbar-dark">
<div class="container">
<a class="navbar-brand mb-0 fs-4" href="/">Emil Sadek</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div id="navbarText" class="collapse navbar-collapse justify-content-end">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="https://www.linkedin.com/in/emil-sadek/" target="_blank"><i class="bi bi-linkedin"></i> LinkedIn</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://github.com/esadek" target="_blank"><i class="bi bi-github"></i> GitHub</a>
</li>
<li class="nav-item">
<a id="contact" class="nav-link" href="mailto:[email protected]"><i class="bi bi-envelope-fill"></i> Contact</a>
</li>
</ul>
</div>
</div>
</nav>
<main>
<div class="mx-2">
<div id="post" class="container my-5">
<h2>Learn Machine Learning</h2>
<p class="text-muted mb-5">July 3rd, 2023</p>
<h4>Math</h4>
<ul>
<li><a href="https://www.youtube.com/playlist?list=PLD80i8An1OEGZ2tYimemzwC3xqkU0jKUg">Math for Machine Learning</a> - Weights &amp; Biases</li>
<li><a href="https://mml-book.github.io/book/mml-book.pdf">Mathematics for Machine Learning</a> - Marc Peter Deisenroth, A. Aldo Faisal and Cheng Soon Ong</li>
</ul>
<h4>Machine Learning</h4>
<ul>
<li><a href="https://www.youtube.com/playlist?list=PLkDaE6sCZn6FNC6YRfRQc_FbeQrF8BwGI">Machine Learning Course</a> - Andrew Ng</li>
<li><a href="https://www.statlearning.com/">An Introduction to Statistical Learning</a> - Gareth James, Daniela Witten, Trevor Hastie and Robert Tibshirani</li>
</ul>
<h4>Deep Learning</h4>
<ul>
<li><a href="http://introtodeeplearning.com">Introduction to Deep Learning</a> - MIT</li>
<li><a href="https://www.youtube.com/playlist?list=PLqYmG7hTraZCDxZ44o4p3N5Anz3lLRVZF">Deep Learning Lecture Series</a> - DeepMind x UCL</li>
<li><a href="https://www.deeplearningbook.org">Deep Learning</a> - Ian Goodfellow, Yoshua Bengio and Aaron Courville</li>
</ul>
<h4>Reinforcement Learning</h4>
<ul>
<li><a href="https://www.youtube.com/playlist?list=PLqYmG7hTraZDVH599EItlEWsUOsJbAodm">Reinforcement Learning Lecture Series</a> - DeepMind x UCL</li>
<li><a href="http://incompleteideas.net/book/RLbook2020.pdf">Reinforcement Learning</a> - Richard S. Sutton and Andrew G. Barto</li>
</ul>

</div>

</div>
</main>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>


</body></html>
89 changes: 89 additions & 0 deletions blog/markdoc-deno/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<!DOCTYPE html>
<html lang="en"><head>
<title>Running Markdoc on Deno</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="author" content="Emil Sadek">
<meta name="description" content="Emil Sadek is a software developer with a profound interest in programming, design, data, and machine learning.">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
<link rel="stylesheet" href="/static/style.css">
<link rel="icon" type="image/png" href="/static/favicon.png">
<script type="text/javascript">
(function(c,l,a,r,i,t,y){
c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
})(window, document, "clarity", "script", "jsroqq3khc");
</script>
</head>
<body>
<nav class="navbar navbar-expand-md navbar-dark">
<div class="container">
<a class="navbar-brand mb-0 fs-4" href="/">Emil Sadek</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div id="navbarText" class="collapse navbar-collapse justify-content-end">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="https://www.linkedin.com/in/emil-sadek/" target="_blank"><i class="bi bi-linkedin"></i> LinkedIn</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://github.com/esadek" target="_blank"><i class="bi bi-github"></i> GitHub</a>
</li>
<li class="nav-item">
<a id="contact" class="nav-link" href="mailto:[email protected]"><i class="bi bi-envelope-fill"></i> Contact</a>
</li>
</ul>
</div>
</div>
</nav>
<main>
<div class="mx-2">
<div id="post" class="container my-5">
<h2>Running Markdoc on Deno</h2>
<p class="text-muted mb-5">January 25th, 2023</p>
<p><a href="https://markdoc.dev">Markdoc</a> is a Markdown-based authoring framework developed
at Stripe to power their renowned documentation site. Now that npm compatibility
has been stabilized in <a href="https://deno.land">Deno</a>, a JavaScript runtime developed
by Node.js creator Ryan Dahl, running Markdoc is easier than ever before. And
since Markdoc is written in TypeScript and Deno supports TypeScript out of the
box, you get all of the benefits that come with TypeScript, such as an enhanced
IDE experience.</p>
<p>Markdoc is imported using an <code>import</code> statement with a
<a href="https://deno.land/[email protected]/node/npm_specifiers">npm specifier</a>:</p>
<pre><code class="language-typescript hljs"><span class="hljs-keyword">import</span> <span class="hljs-title class_">Markdoc</span> <span class="hljs-keyword">from</span> <span class="hljs-string">"npm:@markdoc/markdoc"</span>;
</code></pre>
<p>Deno's file system API is used to read and write files, while Markdoc is used to
render the content:</p>
<pre><code class="language-typescript hljs"><span class="hljs-keyword">const</span> source = <span class="hljs-keyword">await</span> <span class="hljs-title class_">Deno</span>.<span class="hljs-title function_">readTextFile</span>(<span class="hljs-string">"./index.md"</span>);

<span class="hljs-keyword">const</span> ast = <span class="hljs-title class_">Markdoc</span>.<span class="hljs-title function_">parse</span>(source);
<span class="hljs-keyword">const</span> content = <span class="hljs-title class_">Markdoc</span>.<span class="hljs-title function_">transform</span>(ast);
<span class="hljs-keyword">const</span> html = <span class="hljs-title class_">Markdoc</span>.<span class="hljs-property">renderers</span>.<span class="hljs-title function_">html</span>(content);

<span class="hljs-keyword">await</span> <span class="hljs-title class_">Deno</span>.<span class="hljs-title function_">writeTextFile</span>(<span class="hljs-string">"./index.html"</span>, html);
</code></pre>
<p>Here's a breakdown of the code above:</p>
<ol>
<li>Read a Markdown file with
<a href="https://deno.land/api?s=Deno.readTextFile">Deno.readTextFile</a>.</li>
<li>Parse the string into an abstract syntax tree with
<a href="https://markdoc.dev/docs/render#parse">Markdoc.parse</a>.</li>
<li>Transform the abstract syntax tree into a renderable tree with
<a href="https://markdoc.dev/docs/render#transform">Markdoc.transform</a>.</li>
<li>Render the renderable tree into a HTML document as a string with
<a href="https://markdoc.dev/docs/render#html">Markdoc.html</a>.</li>
<li>Output to a HTML file with
<a href="https://deno.land/[email protected]?s=Deno.writeTextFile">Deno.writeTextFile</a>.</li>
</ol>

</div>

</div>
</main>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>


</body></html>
120 changes: 120 additions & 0 deletions blog/python-memoization/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<!DOCTYPE html>
<html lang="en"><head>
<title>Memoization in Python 3</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="author" content="Emil Sadek">
<meta name="description" content="Emil Sadek is a software developer with a profound interest in programming, design, data, and machine learning.">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
<link rel="stylesheet" href="/static/style.css">
<link rel="icon" type="image/png" href="/static/favicon.png">
<script type="text/javascript">
(function(c,l,a,r,i,t,y){
c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
})(window, document, "clarity", "script", "jsroqq3khc");
</script>
</head>
<body>
<nav class="navbar navbar-expand-md navbar-dark">
<div class="container">
<a class="navbar-brand mb-0 fs-4" href="/">Emil Sadek</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div id="navbarText" class="collapse navbar-collapse justify-content-end">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="https://www.linkedin.com/in/emil-sadek/" target="_blank"><i class="bi bi-linkedin"></i> LinkedIn</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://github.com/esadek" target="_blank"><i class="bi bi-github"></i> GitHub</a>
</li>
<li class="nav-item">
<a id="contact" class="nav-link" href="mailto:[email protected]"><i class="bi bi-envelope-fill"></i> Contact</a>
</li>
</ul>
</div>
</div>
</nav>
<main>
<div class="mx-2">
<div id="post" class="container my-5">
<h2>Memoization in Python 3</h2>
<p class="text-muted mb-5">May 23rd, 2021</p>
<p><a href="https://en.wikipedia.org/wiki/Memoization">Memoization</a> is an optimization
technique that speeds up programs by
<a href="https://en.wikipedia.org/wiki/Cache_(computing)">caching</a> the results of
previous function calls. This allows subsequent calls to reuse the cached
results, avoiding time-consuming recalculation. Memoization is commonly used in
<a href="https://en.wikipedia.org/wiki/Dynamic_programming">dynamic programming</a>, where
problems can be broken down into simpler sub-problems. One such dynamic
programming problem is calculating the nth Fibonacci number.</p>
<p>The <a href="https://en.wikipedia.org/wiki/Fibonacci_number">Fibonacci numbers</a> are a
sequence of integers where each number is the sum of the two preceding numbers,
starting with the numbers 0 and 1. A function that calculates the nth Fibonacci
number is often implemented
<a href="https://en.wikipedia.org/wiki/Recursion_(computer_science)">recursively</a>.</p>
<pre><code class="language-python hljs"><span class="hljs-keyword">def</span> <span class="hljs-title function_">fibonacci</span>(<span class="hljs-params">n</span>):
<span class="hljs-keyword">if</span> n &lt;= <span class="hljs-number">1</span>:
<span class="hljs-keyword">return</span> n
<span class="hljs-keyword">return</span> fibonacci(n - <span class="hljs-number">1</span>) + fibonacci(n - <span class="hljs-number">2</span>)
</code></pre>
<p>The function calls of <code>fibonacci(4)</code> can be visualized with a recursion tree.</p>
<img src="/static/fibonacci_without_cache.svg">
<p>Notice that the function is called with the same input multiple times.
Particularly, <code>fibonacci(2)</code> is calculated from scratch twice. As the input
increases, the running time grows exponentially. This is suboptimal and can be
improved significantly using memoization.</p>
<p>Python 3 makes it incredibly easy to memorize functions. The
<a href="https://docs.python.org/3/library/functools.html">functools</a> module included in
Python's standard library provides two useful
<a href="https://docs.python.org/3/glossary.html#term-decorator">decorators</a> for
memoization:
<a href="https://docs.python.org/3/library/functools.html#functools.lru_cache"><code>lru_cache</code></a>
(new in Python 3.2) and
<a href="https://docs.python.org/3/library/functools.html#functools.cache"><code>cache</code></a> (new
in Python 3.9). These decorators use a
<a href="https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_recently_used_(LRU)">least recently used (LRU)</a>
cache, which stores items in order of use, discarding the least recently used
items to make room for new items.</p>
<p>To avoid costly repeated function calls, <code>fibonacci</code> can be wrapped by
<code>lru_cache</code>, which saves and returns values that have already been calculated.
The size limit of <code>lru_cache</code> can be specified with <code>maxsize</code>, which has a
default value of 128.</p>
<pre><code class="language-python hljs"><span class="hljs-keyword">from</span> functools <span class="hljs-keyword">import</span> lru_cache

<span class="hljs-meta">@lru_cache(<span class="hljs-params">maxsize=<span class="hljs-number">64</span></span>)</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">fibonacci</span>(<span class="hljs-params">n</span>):
<span class="hljs-keyword">if</span> n &lt;= <span class="hljs-number">1</span>:
<span class="hljs-keyword">return</span> n
<span class="hljs-keyword">return</span> fibonacci(n - <span class="hljs-number">1</span>) + fibonacci(n - <span class="hljs-number">2</span>)
</code></pre>
<p>The newer <code>cache</code> decorator is equivalent to <code>lru_cache(maxsize=None)</code>.</p>
<pre><code class="language-python hljs"><span class="hljs-keyword">from</span> functools <span class="hljs-keyword">import</span> cache

<span class="hljs-meta">@cache</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">fibonacci</span>(<span class="hljs-params">n</span>):
<span class="hljs-keyword">if</span> n &lt;= <span class="hljs-number">1</span>:
<span class="hljs-keyword">return</span> n
<span class="hljs-keyword">return</span> fibonacci(n - <span class="hljs-number">1</span>) + fibonacci(n - <span class="hljs-number">2</span>)
</code></pre>
<p>Since it does not need to discard least recently used items, <code>cache</code> is both
smaller and faster than <code>lru_cache</code> with a size limit.</p>
<p>With memoization implemented, the recursion tree for <code>fibonacci(4)</code> does not
have any nodes that occur more than twice. The running time now grows linearly,
which is much faster than the previous exponential growth.</p>
<img src="/static/fibonacci_with_cache.svg">
<p>On my 2020 M1 MacBook Air, running <code>fibonacci(40)</code> without memoization takes
18.158 seconds. With the <code>cache</code> decorator added it takes only 0.039 seconds.</p>

</div>

</div>
</main>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>


</body></html>
Loading

0 comments on commit b34332a

Please sign in to comment.