~sgeisenh/personal_site

76c354ec75384ccbf80e19156c3860d99bdc34da — Sam Eisenhandler 1 year, 4 months ago 2fc86a2
More progress toward revamp
M config.toml => config.toml +1 -24
@@ 1,40 1,17 @@
# The URL the site will be built for
base_url = "https://samgeo.codes"

title = "samgeo.codes"

# Whether to automatically compile all Sass files in the sass directory
compile_sass = true

taxonomies = [
  {name = "tags"}
]

# Whether to build a search index to be used later on by a JavaScript library
build_search_index = false

# Generate an XML feed file (for blog posts or anything with a date)
generate_feed = true

[markdown]
# Whether to do syntax highlighting
# Theme can be customised by setting the `highlight_theme` variable to a theme supported by Zola
highlight_code = true

[extra]
author = "Samuel Eisenhandler"
accent_color = "orange"
logo_text = "samgeo.codes"
copyright_html = "<span>© 2023 Samuel Eisenhandler </span>"

menu_items = [
  {name = "blog", url = "$BASE_URL"},
  {name = "tags", url = "$BASE_URL/tags"},
  {name = "archive", url = "$BASE_URL/archive"},
  {name = "series", url = "$BASE_URL/series"},
  {name = "about", url = "$BASE_URL/about"},
  {name = "projects", url = "$BASE_URL/projects"},
  {name = "recordings", url = "$BASE_URL/recordings"},
  {name = "uses", url = "$BASE_URL/uses"},
  {name = "feed", url = "$BASE_URL/atom.xml"},
]
highlight_theme = "gruvbox-light"
\ No newline at end of file

M content/_index.md => content/_index.md +2 -2
@@ 1,6 1,6 @@
+++
sort_by = "date"
paginate_by = 2
paginate_by = 5

aliases = ["/blog"]
+++
+++
\ No newline at end of file

M content/pages/archive.md => content/pages/archive.md +1 -0
@@ 2,4 2,5 @@
template = "archive.html"
title = "blog archive (all posts)"
path = "archive"
draft = true
+++

M content/pages/projects.md => content/pages/projects.md +0 -2
@@ 3,8 3,6 @@ title = "Projects"
path = "projects"
+++

# Projects

Some personal projects I've been working on.

## Crafting Interpreters

M content/series/aoc2022/day01.md => content/series/aoc2022/day01.md +7 -10
@@ 385,25 385,22 @@ Huzzah!
Now, let's see if we can identify some common ground between parts 1 and 2 and maybe
improve our runtime performance.

> **_NOTE:_** I'll be using code literals for math until I figure out a nice way to
> use KaTeX with Zola (or another SSG).

Let's consider the runtime complexity of the solution that we currently have. We'll
say that `I` is the length of our input and `N` is the number of elves in the input.
say that \\(I\\) is the length of our input and \\(N\\) is the number of elves in the input.

Our part 1 boils down to a linear scan over our input, so it runs in `O(I + N)`
time (and `N` is bounded by `I`, so it's really `O(I)`). Our part 2 sorts the collection of elves, so it runs in `O(I + N log N)` time.
Our part 1 boils down to a linear scan over our input, so it runs in \\(O(I + N)\\)
time (and \\(N\\) is bounded by \\(I\\), so it's really \\(O(I)\\)). Our part 2 sorts the collection of elves, so it runs in \\(O(I + N \log N)\\) time.

Can we do better? Well, when we fetch the top 3 elves, we are discarding a bunch of
information that we spent time assembling when we sorted the entire collection of elves.
Maybe we can avoid doing all that work when we only really care about the top 3
elves. Heaps are a wonderful data structure that work perfectly for this kind of
operation (and they're great to be aware of for all sorts of interview problems).
In particular, we can heapify a list of `N` elements in `O(N)` time. And then fetching
`K` elements from that heap costs `O(K log N)` time. Since we want to fetch a constant number of
elements (3), the cost of fetching becomes `O(log N)`.
In particular, we can heapify a list of \\(N\\) elements in \\(O(N)\\) time. And then fetching
\\(K\\) elements from that heap takes \\(O(K \log N)\\) time. Since we want to fetch a constant number of
elements (\\(3\\)), the cost of fetching becomes \\(O(\log N)\\).

So if we can leverage a heap to solve the problem, we will have an `O(I)` solution!
So if we can leverage a heap to solve the problem, we will have an \\(O(I)\\) solution!

There is a very handy module in the standard library called [`heapq`](https://docs.python.org/3/library/heapq.html).
This library maintains the heap invariant (for a min-heap) atop a vanilla

M sass/style.scss => sass/style.scss +13 -2
@@ 76,12 76,11 @@ a {
  padding: 0 1rem;
}

.menu {
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 0;
  list-style: none;
}

.footer {


@@ 94,4 93,16 @@ a {

  /* Make text slightly lighter. */
  color: var(--highlighted-color);
}

.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 0;
}

/* Always display the next page on the right. */
.pagination .next {
  margin-left: auto;
}
\ No newline at end of file

M templates/index.html => templates/index.html +71 -43
@@ 8,12 8,37 @@
    />
    <meta name="robots" content="noodp" />

    <link rel="stylesheet" href="{{ get_url(path="style.css", trailing_slash=false) | safe }}" />
    <link rel="alternate" type="application/rss+xml" href="{{ get_url(path="rss.xml") | safe }}" />
    <link rel="stylesheet" href="{{ get_url(path="style.css",
    trailing_slash=false) | safe }}" /> <link rel="alternate"
    type="application/rss+xml" href="{{ get_url(path="rss.xml") | safe }}" />
    <link
      rel="icon"
      href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🎺</text></svg>"
    />
    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/katex.min.css"
      integrity="sha384-vKruj+a13U8yHIkAyGgK1J3ArTLzrFGBbBc0tDp4ad/EyewESeXE/Iv67Aj8gKZ0"
      crossorigin="anonymous"
    />
    <script
      defer
      src="https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/katex.min.js"
      integrity="sha384-PwRUT/YqbnEjkZO0zZxNqcxACrXe+j766U2amXcgMg5457rve2Y7I6ZJSm2A0mS4"
      crossorigin="anonymous"
    ></script>
    <script
      defer
      src="https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/contrib/auto-render.min.js"
      integrity="sha384-+VBxd3r6XgURycqtZ117nYw44OOcIax56Z4dCRWbxyPt0Koah1uHoK0o4+/RRE05"
      crossorigin="anonymous"
      onload="renderMathInElement(document.body);"
    ></script>
    <script
      async
      defer
      src="https://www.recurse-scout.com/loader.js?t=6728fa76fc43b8203165af6bcc28a021"
    ></script>
    <title>{%- block title %}{{ config.title }}{% endblock title -%}</title>
  </head>
  <body class="">


@@ 23,56 48,59 @@
        <h1 class="header-title">
          <a href="{{ config.base_url | safe }}">{{ config.title }}</a>
        </h1>
        <div class="header-menu">
          {% block header_menu %}
          <ul class="menu">
            <li>
              <a href="{{ config.base_url | safe }}">blog</a>
            </li>
            <li>
              <a href="{{ config.base_url | safe }}/tags">tags</a>
            </li>
            <li>
              <a href="{{ config.base_url | safe }}/archive">archive</a>
            </li>
            <li>
              <a href="{{ config.base_url | safe }}/series">series</a>
            </li>
            <li>
              <a href="{{ config.base_url | safe }}/about">about</a>
            </li>
            <li>
              <a href="{{ config.base_url | safe }}/projects">projects</a>
            </li>
            <li>
              <a href="{{ config.base_url | safe }}/recordings">recordings</a>
            </li>
            <li>
              <a href="{{ config.base_url | safe }}/uses">uses</a>
            </li>
            <li>
              <a href="{{ config.base_url | safe }}/atom.xml">feed</a>
            </li>
          </ul>
          {% endblock header_menu %}
        </div>
        <ul class="menu">
          <li>
            <a href="{{ config.base_url | safe }}">blog</a>
          </li>
          <li>
            <a href="{{ config.base_url | safe }}/series">series</a>
          </li>
          <li>
            <a href="{{ config.base_url | safe }}/atom.xml">feed</a>
          </li>
          <li>
            <a href="{{ config.base_url | safe }}/about">about</a>
          </li>
        </ul>
        <ul class="right-menu">
          <li>
            <a href="{{ config.base_url | safe }}/projects">projects</a>
          </li>
          <li>
            <a href="{{ config.base_url | safe }}/recordings">recordings</a>
          </li>
          <li>
            <a href="{{ config.base_url | safe }}/uses">uses</a>
          </li>
        </ul>
      </header>
      {% endblock header %}

      <div class="content">
        {% block content %}
        TODO: Default content
        {% block content %} {% for page in paginator.pages %}
        <article class="post">
          <h1 class="post-title">
            <a href="{{ page.permalink | safe }}">{{ page.title }}</a>
          </h1>
          <div class="post__summary">{{ page.summary | safe }}</div>
          <div class="read-more">
            <a href="{{ page.permalink | safe }}">Read more...</a>
          </div>
        </article>
        {% endfor %}
        <nav class="pagination">
          {% if paginator.previous %}
          <a class="previous" href="{{ paginator.previous }}">‹ Previous</a>
          {% endif %} {% if paginator.next %}
          <a class="next" href="{{ paginator.next }}">Next ›</a>
          {% endif %}
        </nav>
        {% endblock content %}
      </div>

      {% block footer %}
      <footer class="footer">
        <div class="copyright">
          © 2023 Samuel Eisenhandler
        </div>
        <div class="scout">
          <script async defer src="https://www.recurse-scout.com/loader.js?t=6728fa76fc43b8203165af6bcc28a021"></script>
        </div>
        <div class="rc-scout"></div>
      </footer>
      {% endblock footer %}
    </div>

D templates/macros/date.html => templates/macros/date.html +0 -3
@@ 1,3 0,0 @@
{% macro now_year() %}
    {{ now() | date(format="%Y") }}
{% endmacro %}

D templates/macros/post.html => templates/macros/post.html +0 -103
@@ 1,103 0,0 @@
{% macro content(page, summary) %}
    {%- if summary and page.summary %}
        <div class="post-content">
            {{ page.summary | safe }}
        </div>
        <div>
            <!-- &#xFE0E; -- force text style - some devices render this as emoji -->
            <a class="read-more button" href="{{ page.permalink | safe }}">
                <span class="button__text">Read more</span>&nbsp;
                <span class="button__icon">&#8617;&#xFE0E;</span>
            </a>
        </div>
    {% else %}
        <div class="post-content">
            {{ page.content | safe }}
        </div>
    {%- endif %}
{% endmacro content %}


{% macro date(page) %}
    <span class="post-date">
        {%- if page.date %}
            {{ page.date | date(format="%Y-%m-%d") }}
        {% endif -%}
    </span>
{% endmacro post_date %}


{% macro earlier_later(page) %}
    {%- if config.extra.enable_post_view_navigation and page.earlier or page.later %}
        <div class="pagination">
            <div class="pagination__title">
                <span class="pagination__title-h">{{ config.extra.post_view_navigation_prompt }}</span>
                <hr />
            </div>
            <div class="pagination__buttons">
                {%- if page.later %}
                    <span class="button previous">
                        <a href="{{ page.later.permalink | safe }}">
                            <span class="button__icon">←</span>&nbsp;
                            <span class="button__text">{{ page.later.title }}</span>
                        </a>
                    </span>
                {% endif %}
                {% if page.earlier %}
                    <span class="button next">
                        <a href="{{ page.earlier.permalink | safe }}">
                            <span class="button__text">{{ page.earlier.title }}</span>&nbsp;
                            <span class="button__icon">→</span>
                        </a>
                    </span>
                {% endif -%}
            </div>
        </div>
    {% endif -%}
{% endmacro earlier_later %}


{% macro header(page) %}
    <h1 class="post-title"><a href="{{ page.permalink | safe }}">{{ page.title }}</a></h1>
    <div class="post-meta-inline">
        {{ post_macros::date(page=page) }}
    </div>

    {{ post_macros::tags(page=page) }}
{% endmacro header %}


{% macro list_posts(pages) %}
    <ul>
    {%- for page in pages %}
        {%- if page.draft %}
            {% continue %}
        {% endif -%}
        <li class="post-list">
            <a href="{{ page.permalink | safe }}">
                <span class="post-date">{{ page.date }}</span>
                :: <span class="post-list-title">{{ page.title }}</span></a>
            {{ post_macros::tags(page=page, short=true) }}
        </li>
    {% endfor -%}
    </ul>
{% endmacro list_posts %}


{% macro tags(page, short=false) %}
    {%- if page.taxonomies and page.taxonomies.tags %}
        <span class="post-tags-inline">
            {%- if short %}
                ::
                {%- set sep = "," -%}
            {% else %}
                :: tags:&nbsp;
                {%- set sep = "&nbsp;" -%}
            {% endif -%}
            {%- for tag in page.taxonomies.tags %}
                <a class="post-tag" href="{{ get_taxonomy_url(kind='tags', name=tag) | safe }}">#{{ tag }}</a>
                {%- if not loop.last %}{{ sep | safe }}{% endif -%}
            {% endfor -%}
        </span>
    {% endif -%}
{% endmacro tags %}

M templates/page.html => templates/page.html +3 -4
@@ 1,9 1,8 @@
{% import "macros/post.html" as post_macros %}
{% extends "index.html" %}

{% block content %}
<h1>{{ page.title }}</h1>
<div class="post">
  {{ post_macros::header(page=page) }}
  {{ post_macros::content(page=page, summary=false) }}
  {{ post_macros::earlier_later(page=page) }}
  {{ page.content | safe }}
</div>
{% endblock content %}
\ No newline at end of file

M templates/series.html => templates/series.html +7 -2
@@ 1,4 1,3 @@
{% import "macros/post.html" as post_macros %}
{% extends "index.html" %}

{% block content %}


@@ 6,6 5,12 @@
    <h1 class="post-title">{{ section.title }}</h1>
    {{ section.content | safe }}

    {{ post_macros::list_posts(pages=section.pages) }}
    <ul>
      {% for page in section.pages %}
        <li class="series-pages">
          <a href="{{ page.permalink | safe }}">{{ page.title }}</a>
        </li>
      {% endfor %}
    </ul>
  </div>
{% endblock content %}

M templates/tags/list.html => templates/tags/list.html +8 -10
@@ 1,16 1,14 @@
{% extends "index.html" %} {% block content %}
<div class="post">
  <h1 class="post-title">all tags</h1>
{% extends "index.html" %}

{% block content %}
<article class="post">
  <h1 class="post-title">Tags</h1>
  <ul>
    {% for term in terms %}
    <li class="tag-list">
      <a href="{{ term.permalink | safe }}">
        {{ term.name }} ({{ term.pages | length }} post{{ term.pages | length |
        pluralize }})
      </a>
    </li>
      <li class="tag">
        <a href="{{ term.permalink | safe }}">{{ term.name }}</a>({{ term.page_count }})
      </li>
    {% endfor %}
  </ul>
</div>
</article>
{% endblock content %}

M templates/tags/single.html => templates/tags/single.html +10 -11
@@ 1,14 1,13 @@
{% import "macros/post.html" as post_macros %}
{% extends "index.html" %}
{% block content %}
<div class="post">
  <h1 class="post-title">
    tag: #{{ term.name }} ({{ term.pages | length }}
    post {{ term.pages | length | pluralize }})
  </h1>

  <a href="{{ config.base_url | safe }}/tags"> Show all tags </a>

  {{ post_macros::list_posts(pages=term.pages) }}
</div>
  <div class="post">
    <h1 class="post-title">#{{ term.name }}</h1>
    <ul>
      {% for page in term.pages %}
        <li class="tag-pages">
          <a href="{{ page.permalink | safe }}">{{ page.title }}</a>
        </li>
      {% endfor %}
    </ul>
  </div>
{% endblock content %}