<?xml version="1.0" encoding="utf-8" standalone="yes"?><?xml-stylesheet href="https://brandonrozek.com/css/pretty-feed-v3.xsl" type="text/xsl"?>
<rss version="2.0"
    xmlns:atom="http://www.w3.org/2005/Atom"
    xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Brandon Rozek</title>
    <link>https://brandonrozek.com/</link>
    <image>
      <title>Brandon Rozek</title>
      <link>https://brandonrozek.com/</link>
      <url>https://brandonrozek.com/img/avatar.jpg</url>
    </image>
    <description>Software Developer, Researcher, and Linux Enthusiast.</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <managingEditor>brozek@brandonrozek.com (Brandon Rozek)</managingEditor>
    <webMaster>brozek@brandonrozek.com (Brandon Rozek)</webMaster>
    
	<atom:link href="https://brandonrozek.com/index.xml" rel="self" type="application/rss+xml" />
    
  
  <item>
  <title>Postroll: Benchmark in Milliseconds</title>
  <link>https://matklad.github.io/2026/10/05/benchmark-milliseconds.html</link>
  <pubDate>Sun, 18 Oct 2026 00:00:00 +0000</pubDate>
  <author>Alex Kladov</author>
  <guid>https://matklad.github.io/2026/10/05/benchmark-milliseconds.html</guid>
  <description><![CDATA[<p><strong>Brandon's Comment:</strong></p><p>This is good advice. When your test suite starts taking minutes then we enter this <a href="https://xkcd.com/303/">territory</a>.</p>]]></description>
  <content:encoded><![CDATA[<p><strong>Brandon's Comment:</strong></p><p>This is good advice. When your test suite starts taking minutes then we enter this <a href="https://xkcd.com/303/">territory</a>.</p>
]]></content:encoded>
</item>
  
  <item>
  <title>Postroll: How I use Home Assistant to help with my cats</title>
  <link>https://michaelharley.net/posts/2026/08/08/how-i-use-home-assistant-to-help-with-my-cats/</link>
  <pubDate>Sun, 18 Oct 2026 00:00:00 +0000</pubDate>
  <author>Michael Harley</author>
  <guid>https://michaelharley.net/posts/2026/08/08/how-i-use-home-assistant-to-help-with-my-cats/</guid>
  <description><![CDATA[<p><strong>Brandon's Comment:</strong></p><p>As a home assistant user myself, I&rsquo;m always very impressed when I see someone really customize the dashboard to their life. I, on the other hand, rarely use the dashboard ever since I discovered <a href="/blog/praise-smart-button/">smart buttons</a>.</p>]]></description>
  <content:encoded><![CDATA[<p><strong>Brandon's Comment:</strong></p><p>As a home assistant user myself, I&rsquo;m always very impressed when I see someone really customize the dashboard to their life. I, on the other hand, rarely use the dashboard ever since I discovered <a href="/blog/praise-smart-button/">smart buttons</a>.</p>
]]></content:encoded>
</item>
  
  <item>
  <title>Postroll: My Failed Tech Predictions</title>
  <link>https://rldane.space/my-failed-tech-predictions.html</link>
  <pubDate>Sun, 18 Oct 2026 00:00:00 +0000</pubDate>
  <author>R.L. Dane</author>
  <guid>https://rldane.space/my-failed-tech-predictions.html</guid>
  <description><![CDATA[<p><strong>Brandon's Comment:</strong></p><p>It&rsquo;s always fun looking back to how people viewed the future. Where&rsquo;s my flying cars?!? This is a good reminder that we may feel like we can predict the future, but it often evades our foresight.</p>]]></description>
  <content:encoded><![CDATA[<p><strong>Brandon's Comment:</strong></p><p>It&rsquo;s always fun looking back to how people viewed the future. Where&rsquo;s my flying cars?!? This is a good reminder that we may feel like we can predict the future, but it often evades our foresight.</p>
]]></content:encoded>
</item>
  
  <item>
  <title>Postroll: Recently</title>
  <link>https://macwright.com/2026/10/01/recently.html</link>
  <pubDate>Sun, 18 Oct 2026 00:00:00 +0000</pubDate>
  <author>Tom MacWright</author>
  <guid>https://macwright.com/2026/10/01/recently.html</guid>
  <description><![CDATA[<p><strong>Brandon's Comment:</strong></p><blockquote>
<p>Dump trash to combine islands, dump water from the sky to divide them. That&rsquo;s just how life is.</p></blockquote>
<p>Haha, sounds about right.</p>]]></description>
  <content:encoded><![CDATA[<p><strong>Brandon's Comment:</strong></p><blockquote>
<p>Dump trash to combine islands, dump water from the sky to divide them. That&rsquo;s just how life is.</p></blockquote>
<p>Haha, sounds about right.</p>
]]></content:encoded>
</item>
  
  <item>
  <title>Postroll: Spamming notifications is counterproductive</title>
  <link>https://www.rubenerd.au/spamming-notifications-is-counterproductive/</link>
  <pubDate>Sun, 18 Oct 2026 00:00:00 +0000</pubDate>
  <author>Ruben Schade</author>
  <guid>https://www.rubenerd.au/spamming-notifications-is-counterproductive/</guid>
  <description><![CDATA[<p><strong>Brandon's Comment:</strong></p><p>Unfortunately with any app I download, I assume that if they want to send me notifications that it&rsquo;ll ultimately be spam, advertising, engagement-farming, etc. Therefore, most of the time I click deny on those requests. I appreciate that some apps let me control what type of notifications get sent (somewhat like how some services sign you up for multiple email lists). Though most of the time I really don&rsquo;t want notifications. I don&rsquo;t want the top of my phone to be full of little icons.</p>]]></description>
  <content:encoded><![CDATA[<p><strong>Brandon's Comment:</strong></p><p>Unfortunately with any app I download, I assume that if they want to send me notifications that it&rsquo;ll ultimately be spam, advertising, engagement-farming, etc. Therefore, most of the time I click deny on those requests. I appreciate that some apps let me control what type of notifications get sent (somewhat like how some services sign you up for multiple email lists). Though most of the time I really don&rsquo;t want notifications. I don&rsquo;t want the top of my phone to be full of little icons.</p>
]]></content:encoded>
</item>
  
  <item>
  <title>Postroll: WIld Ride to Earth - A Game</title>
  <link>https://sheep.horse/2026/10/wild_ride_to_earth_-_a_game.html</link>
  <pubDate>Sun, 18 Oct 2026 00:00:00 +0000</pubDate>
  <author>Andrew Stephens</author>
  <guid>https://sheep.horse/2026/10/wild_ride_to_earth_-_a_game.html</guid>
  <description><![CDATA[<p><strong>Brandon's Comment:</strong></p><p>Thanks for sharing this game! I spent an evening after work having a good time trying to figure out how to get home.</p>]]></description>
  <content:encoded><![CDATA[<p><strong>Brandon's Comment:</strong></p><p>Thanks for sharing this game! I spent an evening after work having a good time trying to figure out how to get home.</p>
]]></content:encoded>
</item>
  
  <item>
  <title>Postroll: Local Reasoning for Global Properties</title>
  <link>https://tratt.net/laurie/blog/2026/local_reasoning_for_global_properties.html</link>
  <pubDate>Sat, 12 Sep 2026 00:00:00 +0000</pubDate>
  <author>Laurence Tratt</author>
  <guid>https://tratt.net/laurie/blog/2026/local_reasoning_for_global_properties.html</guid>
  <description><![CDATA[<p><strong>Brandon's Comment:</strong></p><p>Reducing the number of possible states at a program point simplies what the coder needs to reason about during runtime. It doesn&rsquo;t come for free though, as the type-based techinques presented here puts the onus on the developer during the creation of the program. In many cases, I think it&rsquo;s worth it.</p>]]></description>
  <content:encoded><![CDATA[<p><strong>Brandon's Comment:</strong></p><p>Reducing the number of possible states at a program point simplies what the coder needs to reason about during runtime. It doesn&rsquo;t come for free though, as the type-based techinques presented here puts the onus on the developer during the creation of the program. In many cases, I think it&rsquo;s worth it.</p>
]]></content:encoded>
</item>
  
  <item>
  <title>Postroll: Everyone Should Know SIMD</title>
  <link>https://mitchellh.com/writing/everyone-should-know-simd</link>
  <pubDate>Tue, 08 Sep 2026 00:00:00 +0000</pubDate>
  <author>Mitchell Hashimoto</author>
  <guid>https://mitchellh.com/writing/everyone-should-know-simd</guid>
  <description><![CDATA[<p><strong>Brandon's Comment:</strong></p><p>After reading this, I agree! If you&rsquo;re facing any performance problems at work, then this is worth a look. SIMD is supported by the majority of modern CPUs.</p>]]></description>
  <content:encoded><![CDATA[<p><strong>Brandon's Comment:</strong></p><p>After reading this, I agree! If you&rsquo;re facing any performance problems at work, then this is worth a look. SIMD is supported by the majority of modern CPUs.</p>
]]></content:encoded>
</item>
  
  <item>
  <title>Postroll: royal tasmanian botanical gardens in redscale</title>
  <link>https://life.drsh.io/royal-tasmanian-botanical-gardens-in-redscale/</link>
  <pubDate>Tue, 08 Sep 2026 00:00:00 +0000</pubDate>
  <author>Darsh</author>
  <guid>https://life.drsh.io/royal-tasmanian-botanical-gardens-in-redscale/</guid>
  <description><![CDATA[<p><strong>Brandon's Comment:</strong></p><p>I need to figure out how to apply an artificial redscale filter on my photos. I haven&rsquo;t heard of this film technique before; it&rsquo;s awe-striking.</p>]]></description>
  <content:encoded><![CDATA[<p><strong>Brandon's Comment:</strong></p><p>I need to figure out how to apply an artificial redscale filter on my photos. I haven&rsquo;t heard of this film technique before; it&rsquo;s awe-striking.</p>
]]></content:encoded>
</item>
  
  <item>
  <title>Postroll: The Night Feeling</title>
  <link>https://cleberg.net/blog/the-night-feeling.html</link>
  <pubDate>Tue, 08 Sep 2026 00:00:00 +0000</pubDate>
  <author>Christian Cleberg</author>
  <guid>https://cleberg.net/blog/the-night-feeling.html</guid>
  <description><![CDATA[<p><strong>Brandon's Comment:</strong></p><p>I&rsquo;m reading this at night as my world slows down and prepares for the next day.</p>]]></description>
  <content:encoded><![CDATA[<p><strong>Brandon's Comment:</strong></p><p>I&rsquo;m reading this at night as my world slows down and prepares for the next day.</p>
]]></content:encoded>
</item>
  
  <item>
  <title>On Post-Quantum Security Adoption</title>
  <link>https://brandonrozek.com/blog/post-quantum-security-adoption/</link>
  <pubDate>Mon, 15 Jun 2026 12:44:12 -0400</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid>https://brandonrozek.com/blog/post-quantum-security-adoption/</guid>
  <description><![CDATA[<p>From Alex&rsquo;s <a href="https://alexwlchan.net/2026/post-quantum-blog/">blog post</a>, I&rsquo;ve learned that there are enough recent breakthroughs in quantum computing that I should take post-quantum cryptography seriously. <a href="https://blog.google/innovation-and-ai/technology/safety-security/cryptography-migration-timeline/">Google</a> and <a href="https://blog.cloudflare.com/post-quantum-roadmap/">Cloudflare</a> both set a target of 2029 for having their systems secure against quantum computers. Similarly, the <a href="https://www.ncsc.gov.uk/guidance/pqc-migration-timelines">UK government</a> is targeting 2035.</p>
<p>The issue is that cryptography is built upon math problems that are difficult to solve. Quantum computers make solving some of these problems such as integer factorization and discrete logs easier. If someone has a quantum computer that can sufficiently solve those two problems, then they can likely decrypt many ciphertexts that were produced using <a href="https://en.wikipedia.org/wiki/Public-key_cryptography">asymmetric cryptography</a> techniques (think public/private key-pairs). Wikipedia has a great article discussing <a href="https://en.wikipedia.org/wiki/Post-quantum_cryptography">post-quantum cryptography</a> if you want to read more.</p>]]></description>
  <content:encoded><![CDATA[<p>From Alex&rsquo;s <a href="https://alexwlchan.net/2026/post-quantum-blog/">blog post</a>, I&rsquo;ve learned that there are enough recent breakthroughs in quantum computing that I should take post-quantum cryptography seriously. <a href="https://blog.google/innovation-and-ai/technology/safety-security/cryptography-migration-timeline/">Google</a> and <a href="https://blog.cloudflare.com/post-quantum-roadmap/">Cloudflare</a> both set a target of 2029 for having their systems secure against quantum computers. Similarly, the <a href="https://www.ncsc.gov.uk/guidance/pqc-migration-timelines">UK government</a> is targeting 2035.</p>
<p>The issue is that cryptography is built upon math problems that are difficult to solve. Quantum computers make solving some of these problems such as integer factorization and discrete logs easier. If someone has a quantum computer that can sufficiently solve those two problems, then they can likely decrypt many ciphertexts that were produced using <a href="https://en.wikipedia.org/wiki/Public-key_cryptography">asymmetric cryptography</a> techniques (think public/private key-pairs). Wikipedia has a great article discussing <a href="https://en.wikipedia.org/wiki/Post-quantum_cryptography">post-quantum cryptography</a> if you want to read more.</p>
<p>Given all that, if the cost isn&rsquo;t too high then it&rsquo;s not a bad idea to look at our current systems and see what we can make quantum-resistant today. Otherwise, we risk being vulnerable to <a href="https://en.wikipedia.org/wiki/Harvest_now,_decrypt_later">harvest now, decrypt later</a> attacks. This is where an adversary stores encrypted packets until they have a computer powerful enough to break the encryption. You might wonder if encrypted packets from 5 years ago matter. Though if you&rsquo;re like me, chances are you had to transmit personally identifiable information over the internet for jobs, housing, etc. In the US, it is <a href="https://www.ssa.gov/faqs/en/questions/KA-02220.html">really difficult</a> to change your social security number.</p>
<p>We&rsquo;ll explore three different protocols I rely on and how we can make them post-quantum resistant.</p>
<h2 id="ssh">SSH</h2>
<p>OpenSSH implemented and made default post-quantum key agreement <a href="https://www.openssh.org/pq.html">back in April 2022</a>. At the time of writing, the <code>mlkem768x25519-sha256</code> scheme is used. That&rsquo;s a mouthful but it essentially describes what the scheme is:</p>
<ul>
<li><code>mlkem</code>: <a href="https://en.wikipedia.org/wiki/Lattice-based_cryptography">Module lattices</a> <a href="https://en.wikipedia.org/wiki/Key_encapsulation_mechanism">key encapsulation mechanism</a> (also known as key-exchange)</li>
<li><code>768</code>: Not sure what this means, sorry.</li>
<li><code>x25519</code>: <a href="https://en.wikipedia.org/wiki/Curve25519">Elliptic curve</a> used in the classical Diffie-Hellman key-exchange.</li>
<li><code>sha256</code>: The hash function used to <a href="https://datatracker.ietf.org/doc/draft-ietf-sshm-mlkem-hybrid-kex/">combine the keys</a> generated from ML-KEM and x25519 (see Section 2.4 of previous link).</li>
</ul>
<p>As you might notice, this is a hybrid quantum/classical algorithm. This is a hedge. If quantum computers arrive which break the classical algorithm, then we&rsquo;re safe. Similarly if we find out that the post-quantum algorithms are insecure, then we still have the well-developed classical ones. We can only hope that they&rsquo;re both not found to be insecure.</p>
<p>If you are using a client released after October 2025, then you&rsquo;ll receive a warning if you&rsquo;re connecting to a server that doesn&rsquo;t support post-quantum encryption.</p>
<pre tabindex="0"><code>** WARNING: connection is not using a post-quantum key exchange algorithm.
** This session may be vulnerable to &#34;store now, decrypt later&#34; attacks.
** The server may need to be upgraded. See https://openssh.com/pq.html
</code></pre><h2 id="tls">TLS</h2>
<p><a href="https://en.wikipedia.org/wiki/Transport_Layer_Security">Transport Layer Security</a> is a cryptographic protocol that underlies HTTPS and many other applications. You&rsquo;re likely using it to connect to this website! Similar to OpenSSH, they introduced the hybrid scheme <code>X25519MLKEM768</code> for post-quantum security. The main difference that I can spot (as a non-cryptographer) is that this scheme does not hash the combined key. If you&rsquo;re interested, you can read more at this <a href="https://datatracker.ietf.org/doc/draft-ietf-tls-ecdhe-mlkem/">IETF draft</a>.</p>
<p>In terms of major browsers, Firefox has supported this since <a href="https://www.firefox.com/en-US/firefox/132.0/releasenotes/">October 2024</a> and Chrome since <a href="https://developer.chrome.com/release-notes/131">November 2024</a>. To use this scheme, however, both sides need to handle it. At the time of writing, <a href="https://radar.cloudflare.com/post-quantum">Cloudflare</a> estimates that 70.1% of Internet traffic is post-quantum encrypted. You can even use that link to check whether your own website supports post-quantum key exchange.</p>
<p>If you find that your website is not post-quantum secure, then check out the <a href="https://configurator.tlsref.org/">TLSRef TLS Configurator</a>. This provides the configuration options needed to support modern cryptographic protocols for a variety of popular web servers.</p>
<h2 id="wireguard">WireGuard</h2>
<p>WireGuard is a popular VPN technology that is known for being efficient and simple. By default, it is <a href="https://www.wireguard.com/known-limitations/">not post-quantum secure</a>. However, we can use the <code>PresharedKey</code> field to mix a symmetric key whose underlying mathematical problems are not as impacted as asymmetric cryptography.</p>
<p>The simplest solution here then is to run</p>
<pre tabindex="0"><code>wg genpsk
</code></pre><p>and then <em>securely</em> add the key into the <code>PresharedKey</code> field.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ini" data-lang="ini"><span style="display:flex;"><span><span style="color:#66d9ef">[Interface]</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">Address</span> <span style="color:#f92672">=</span> <span style="color:#e6db74">...</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">...</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">PrivateKey</span> <span style="color:#f92672">=</span> <span style="color:#e6db74">...</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">[Peer]</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">PublicKey</span> <span style="color:#f92672">=</span> <span style="color:#e6db74">...</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">...</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">PresharedKey</span> <span style="color:#f92672">=</span> <span style="color:#e6db74">...</span>
</span></span></code></pre></div><p>Both sides of the connection need to use the same <code>PresharedKey</code> in order for the connection to work.</p>
<p>I&rsquo;ll reiterate that we need to figure out a way to transfer the key <em>securely</em> for this to work. WireGuard doesn&rsquo;t have a built-in way to share these keys. If you want to go with this simpler static preshared key route, then I suggest that you use a post-quantum secure channel (like a modern SSH setup) to distribute the keys.</p>
<p>The downside of setting the preshared key on both sides once and then moving on is that the tunnel is then not post-quantum forward secret. This means that if an adversary with access to a sufficiently powerful quantum computer additionally gets access to the preshared key, they can then decrypt all future ciphertexts.</p>
<p>If we want to protect against this, then we&rsquo;ll need to run a post-quantum key exchange protocol on top of WireGuard. At the time of writing, <a href="https://github.com/rosenpass/rosenpass">Rosenpass</a> seems to be the simplest way to set this up. They automatically update the preshared key securely within WireGuard every two minutes.</p>
<p>While that is one solution, the space here seems fragmented. Another approach <a href="https://ieeexplore.ieee.org/abstract/document/9519445">updates the protocol itself</a> and many VPN providers <a href="https://prod-assets-cms.mtech.xvservice.net/files/xv/Post-Quantum-WireGuard_-A-Practical-Implementation-Guide.pdf">handle it their own way as well</a>.</p>
<h2 id="conclusion">Conclusion</h2>
<p>Even though we&rsquo;re not at <a href="https://en.wikipedia.org/wiki/Harvest_now,_decrypt_later">Y2Q or Q-day</a>, we can still take steps to make sure that we&rsquo;re transmitting information over the Internet in a quantum-resistant way. In the meantime, I&rsquo;ll dream about the day when I can run a quantum computer in my pocket.</p>
]]></content:encoded>
  
</item>
  
  <item>
  <title>Synchronizing my Static Website with Object Storage</title>
  <link>https://brandonrozek.com/blog/synchronizing-static-website-object-storage/</link>
  <pubDate>Sat, 13 Jun 2026 17:51:08 -0400</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid>https://brandonrozek.com/blog/synchronizing-static-website-object-storage/</guid>
  <description><![CDATA[<p>I recently updated all my <a href="/blog/implementing-cdn-geodns/">geo-distributed</a> web servers to run on Fedora CoreOS (<a href="/blog/fedora-coreos-first-impressions/">yes, I still love it</a>). This gave me an opportunity to revisit how I handle synchronization. Before, I used <a href="https://syncthing.net/">Syncthing</a> which while awesome is a pain to configure. I don&rsquo;t update my website or certs too frequently so having an always online setup seemed overkill.</p>
<p>So this time I went with an object storage setup.</p>
<p><img src="/files/images/blog/website-object-store.svg" alt=""></p>
<p>I created a bucket (e.g <code>my-website</code>) and within it I have the following directories</p>]]></description>
  <content:encoded><![CDATA[<p>I recently updated all my <a href="/blog/implementing-cdn-geodns/">geo-distributed</a> web servers to run on Fedora CoreOS (<a href="/blog/fedora-coreos-first-impressions/">yes, I still love it</a>). This gave me an opportunity to revisit how I handle synchronization. Before, I used <a href="https://syncthing.net/">Syncthing</a> which while awesome is a pain to configure. I don&rsquo;t update my website or certs too frequently so having an always online setup seemed overkill.</p>
<p>So this time I went with an object storage setup.</p>
<p><img src="/files/images/blog/website-object-store.svg" alt=""></p>
<p>I created a bucket (e.g <code>my-website</code>) and within it I have the following directories</p>
<pre tabindex="0"><code>my-website
├── etc
    └── letsencrypt
        └── live
            └── example.com
                ├── cert.pem
                ├── chain.pem
                ├── fullchain.pem
                └── privkey.pem
└── var
    └── www
        ├── website1
        ├── website2
        └── websiten
</code></pre><p>The core idea is that the webservers will read from this object store to stay up to date with my SSL certificates and my static website files. The rest of the post will go over how I 1) modified my deployment pipeline to push to the object store, 2) push the SSL certificates which are renewed, and 3) pull both the SSL certificates and the website files.</p>
<h2 id="deploying-my-website-files">Deploying my website files</h2>
<p>Currently, I use <a href="https://brandonrozek.com/blog/deploying-hugo-website-through-gh-actions/">Github Actions</a> (labeled as <code>CI/CD</code> in the diagram) to build and deploy my website. Beforehand, I had to create a special SSH key-pair and lock it down in case it leaked. For this new setup, we can instead use application keys to authenticate with our object store.</p>
<p>To lower the threat surface further, we can limit the buckets the application key has access to, whether it has read/write permissions, and what file prefixes the application can access.</p>
<p>For my Github action, I created an application key which has read/write permissions to the prefix <code>var/www/website</code>. We need both permissions if we want to delete files that don&rsquo;t exist in the build anymore. Here&rsquo;s the script that I use within the GitHub action to synchronize with the object store after I built the website.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e">#!/usr/bin/env sh
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>set -e
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Environmental variables we need to set within the runner</span>
</span></span><span style="display:flex;"><span>: <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>AWS_ACCESS_KEY_ID:?AWS_ACCESS_KEY_ID is not set<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span>: <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>AWS_SECRET_ACCESS_KEY:?AWS_SECRET_ACCESS_KEY is not set<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span>: <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>AWS_ENDPOINT_URL:?AWS_ENDPOINT_URL is not set<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span>: <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>S3_BUCKET:?S3_BUCKET is not set<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span>: <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>S3_PATH:?S3_PATH is not set<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Safety check so we don&#39;t wipe our website!</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">if</span> <span style="color:#f92672">[</span> ! -d <span style="color:#e6db74">&#34;public&#34;</span> <span style="color:#f92672">]</span> <span style="color:#f92672">||</span> <span style="color:#f92672">[</span> -z <span style="color:#e6db74">&#34;</span><span style="color:#66d9ef">$(</span>ls -A public<span style="color:#66d9ef">)</span><span style="color:#e6db74">&#34;</span> <span style="color:#f92672">]</span>; <span style="color:#66d9ef">then</span>
</span></span><span style="display:flex;"><span>  echo <span style="color:#e6db74">&#34;public/ is empty or missing&#34;</span>
</span></span><span style="display:flex;"><span>  exit <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">fi</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>aws s3 sync public/ <span style="color:#e6db74">&#34;s3://</span><span style="color:#e6db74">${</span>S3_BUCKET<span style="color:#e6db74">}</span><span style="color:#e6db74">/</span><span style="color:#e6db74">${</span>S3_PATH<span style="color:#e6db74">}</span><span style="color:#e6db74">/&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>  --delete <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>  --exclude <span style="color:#e6db74">&#34;*.bak&#34;</span>
</span></span></code></pre></div><p>Summarizing how the script works:</p>
<ul>
<li>The environmental variables at the beginning are used to authenticate with the object store.</li>
<li>We sanity check that the <code>public</code> folder exists after running <code>hugo</code> and that it&rsquo;s non-empty so that we don&rsquo;t accidentally wipe the object store&rsquo;s files.</li>
<li>We use the <code>aws</code> command to perform the sync. Note that this command is <a href="https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2404-Readme.md">baked into</a> the default Ubuntu image used by GitHub&rsquo;s runners, so no installation step is required.</li>
</ul>
<h2 id="pushing-ssl-certificates">Pushing SSL Certificates</h2>
<p>I use <a href="https://certbot.eff.org/">Certbot</a> to request SSL certificates from Let&rsquo;s Encrypt. After a renewal certificate is issued, the client will run any scripts located within <code>/etc/letsencrypt/renewal-hooks/deploy</code> (<a href="https://eff-certbot.readthedocs.io/en/stable/using.html#renewing-certificates">documentation</a>). In that case, we want to add a <code>push-certs-to-object-store.sh</code> file which does just that.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e">#!/bin/bash
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>set -u
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>S3_BUCKET<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;INSERT_BUCKET_NAME&#34;</span>
</span></span><span style="display:flex;"><span>ENDPOINT<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;INSERT_ENDPOINT_URL&#34;</span>
</span></span><span style="display:flex;"><span>AWS_ACCESS_KEY_ID<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;INSERT_KEY_ID_HERE&#34;</span>
</span></span><span style="display:flex;"><span>AWS_SECRET_ACCESS_KEY<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;INSERT_SECRET_KEY_HERE&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>podman run --rm <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>  -e AWS_ACCESS_KEY_ID<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>AWS_ACCESS_KEY_ID<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>  -e AWS_SECRET_ACCESS_KEY<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>AWS_SECRET_ACCESS_KEY<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>  -v <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>RENEWED_LINEAGE<span style="color:#e6db74">}</span><span style="color:#e6db74">:</span><span style="color:#e6db74">${</span>RENEWED_LINEAGE<span style="color:#e6db74">}</span><span style="color:#e6db74">:ro,z&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>  -v <span style="color:#e6db74">&#34;/etc/letsencrypt/archive:/etc/letsencrypt/archive:ro,z&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>  docker.io/amazon/aws-cli s3 cp <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>RENEWED_LINEAGE<span style="color:#e6db74">}</span><span style="color:#e6db74">/&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>  <span style="color:#e6db74">&#34;s3://</span><span style="color:#e6db74">${</span>S3_BUCKET<span style="color:#e6db74">}</span><span style="color:#e6db74">/</span><span style="color:#e6db74">${</span>RENEWED_LINEAGE#/<span style="color:#e6db74">}</span><span style="color:#e6db74">/&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>  --recursive <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>  --endpoint-url <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>ENDPOINT<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">if</span> <span style="color:#f92672">[</span> $? -ne <span style="color:#ae81ff">0</span> <span style="color:#f92672">]</span>; <span style="color:#66d9ef">then</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e"># Insert failure notification technique here</span>
</span></span><span style="display:flex;"><span>  exit <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">fi</span>
</span></span></code></pre></div><p>Make sure that this script is executable after saving it. This script is different from the last in that it uses <code>podman</code> to run <code>aws-cli</code> as opposed to executing it directly. This is because I&rsquo;m using Fedora CoreOS an immutable distribution which <a href="https://docs.fedoraproject.org/en-US/fedora-coreos/faq/#_how_do_i_run_custom_applications_on_fedora_coreos">highly discourages overlaying packages</a>.</p>
<p>Going over the script:</p>
<ul>
<li><code>${RENEWED_LINEAGE}</code> is the folder path which contains the renewed certs (e.g <code>/etc/letsencrypt/live/example.com</code>)</li>
<li>We need to mount the <code>${RENEWED_LINEAGE}</code> path as well as <code>/etc/letsencrypt/archive</code> since the live folder only contains symbolic links to the files which are actually stored in the archive.</li>
<li>Since we&rsquo;re not modifying these files, we can treat them as read-only (the <code>ro</code> flag). Since I have SELinux enabled I threw in the <code>z</code> flag so that Podman can automatically handle the contexts for me.</li>
<li>We&rsquo;re using <code>cp</code> instead of <code>sync</code> since the renewal procedure will overwrite all the existing files with new ones. Meaning that we don&rsquo;t need read permissions for this application key to update the certificates.</li>
<li>Personally for alerting, I send a curl request to a webhook on failure.</li>
</ul>
<h2 id="pulling-the-files">Pulling the files</h2>
<p>We can create an application key with read-only permissions in order to pull the SSL certificates and the website files.</p>
<h3 id="website-files">Website Files</h3>
<p>Here&rsquo;s the script that I use to synchronize the local copy with that of the object store:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e">#!/bin/bash
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>set -e
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>: <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>AWS_ACCESS_KEY_ID:?AWS_ACCESS_KEY_ID is not set<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span>: <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>AWS_SECRET_ACCESS_KEY:?AWS_SECRET_ACCESS_KEY is not set<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span>: <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>AWS_ENDPOINT_URL:?AWS_ENDPOINT_URL is not set<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span>: <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>S3_BUCKET:?S3_BUCKET is not set<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>sync_site<span style="color:#f92672">()</span> <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>    local path<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;</span>$1<span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    mkdir -p <span style="color:#e6db74">&#34;/</span><span style="color:#e6db74">${</span>path<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    podman run --rm <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>      -e AWS_ACCESS_KEY_ID<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>AWS_ACCESS_KEY_ID<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>      -e AWS_SECRET_ACCESS_KEY<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>AWS_SECRET_ACCESS_KEY<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>      -v <span style="color:#e6db74">&#34;/</span><span style="color:#e6db74">${</span>path<span style="color:#e6db74">}</span><span style="color:#e6db74">:/</span><span style="color:#e6db74">${</span>path<span style="color:#e6db74">}</span><span style="color:#e6db74">:z&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>      docker.io/amazon/aws-cli s3 sync <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>      <span style="color:#e6db74">&#34;s3://</span><span style="color:#e6db74">${</span>S3_BUCKET<span style="color:#e6db74">}</span><span style="color:#e6db74">/</span><span style="color:#e6db74">${</span>path<span style="color:#e6db74">}</span><span style="color:#e6db74">/&#34;</span> <span style="color:#e6db74">&#34;/</span><span style="color:#e6db74">${</span>path<span style="color:#e6db74">}</span><span style="color:#e6db74">/&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>      --delete <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>      --endpoint-url <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>AWS_ENDPOINT_URL<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>sync_site <span style="color:#e6db74">&#34;var/www/website1&#34;</span>
</span></span><span style="display:flex;"><span>sync_site <span style="color:#e6db74">&#34;var/www/website2&#34;</span>
</span></span><span style="display:flex;"><span>sync_site <span style="color:#e6db74">&#34;var/www/websiten&#34;</span>
</span></span></code></pre></div><p>I have a corresponding systemd unit file and timer which runs every 15 minutes to check for changes.</p>
<h3 id="ssl-certificates">SSL Certificates</h3>
<p>For my certificates, I only check for new ones daily. The script is very similar&hellip;</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e">#!/bin/bash
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>set -e
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>: <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>AWS_ACCESS_KEY_ID:?AWS_ACCESS_KEY_ID is not set<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span>: <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>AWS_SECRET_ACCESS_KEY:?AWS_SECRET_ACCESS_KEY is not set<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span>: <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>AWS_ENDPOINT_URL:?AWS_ENDPOINT_URL is not set<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span>: <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>S3_BUCKET:?S3_BUCKET is not set<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span>: <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>S3_PATH:?S3_PATH is not set<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>mkdir -p -m <span style="color:#ae81ff">700</span> <span style="color:#e6db74">&#34;/</span><span style="color:#e6db74">${</span>S3_PATH<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>podman run --rm <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>  -e AWS_ACCESS_KEY_ID<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>AWS_ACCESS_KEY_ID<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>  -e AWS_SECRET_ACCESS_KEY<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>AWS_SECRET_ACCESS_KEY<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>  -v <span style="color:#e6db74">&#34;/</span><span style="color:#e6db74">${</span>S3_PATH<span style="color:#e6db74">}</span><span style="color:#e6db74">/&#34;</span>:<span style="color:#e6db74">&#34;/</span><span style="color:#e6db74">${</span>S3_PATH<span style="color:#e6db74">}</span><span style="color:#e6db74">/&#34;</span>:z <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>  docker.io/amazon/aws-cli s3 cp <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>  <span style="color:#e6db74">&#34;s3://</span><span style="color:#e6db74">${</span>S3_BUCKET<span style="color:#e6db74">}</span><span style="color:#e6db74">/</span><span style="color:#e6db74">${</span>S3_PATH<span style="color:#e6db74">}</span><span style="color:#e6db74">/&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>  <span style="color:#e6db74">&#34;/</span><span style="color:#e6db74">${</span>S3_PATH<span style="color:#e6db74">}</span><span style="color:#e6db74">/&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>  --recursive <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>  --endpoint-url <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>AWS_ENDPOINT_URL<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>
</span></span></code></pre></div><h2 id="conclusion">Conclusion</h2>
<p>That&rsquo;s at least how I have it set up at the time of writing. I&rsquo;ve only been running this setup for two days, so we&rsquo;ll see how I feel ultimately. Right now, I&rsquo;m happy that it simplifies my Ansible setup for these servers. Before this, I had to manually setup Syncthing using their webui.</p>
<p>This updated method allows me to copy a few scripts and systemd unit files over and call it a day. I&rsquo;m also happy that I don&rsquo;t have to deal with creating a special <code>build</code> user and making sure that&rsquo;s locked down. Now we&rsquo;ll see if I can be patient for 15 minutes to see my website changes ;D</p>
]]></content:encoded>
  
</item>
  
  <item>
  <title>Can you tell the difference? A quick look into discrimination testing.</title>
  <link>https://brandonrozek.com/blog/discrimination-testing/</link>
  <pubDate>Sun, 24 May 2026 15:32:35 -0400</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid>https://brandonrozek.com/blog/discrimination-testing/</guid>
  <description><![CDATA[<p>A few month&rsquo;s ago, Brad Reese, the grandson of the founder of the Reese&rsquo;s company, called the company out for <a href="https://www.linkedin.com/posts/bradreesecom_reeses-brandstewardship-corporateaccountability-activity-7428545969430016001-zOL7/">swapping out the chocolate and peanut butter in some of their products</a>. The newer ingredients &ldquo;chocolate candy&rdquo; and &ldquo;peanut butter creme&rdquo; are only imitations.</p>
<blockquote>
<p>But today, REESE&rsquo;S  identity is being rewritten, not by storytellers, but by formulation  decisions that replace Milk Chocolate with compound coatings and Peanut  Butter with peanut‑butter‑style crèmes across multiple REESE’S products.</p>]]></description>
  <content:encoded><![CDATA[<p>A few month&rsquo;s ago, Brad Reese, the grandson of the founder of the Reese&rsquo;s company, called the company out for <a href="https://www.linkedin.com/posts/bradreesecom_reeses-brandstewardship-corporateaccountability-activity-7428545969430016001-zOL7/">swapping out the chocolate and peanut butter in some of their products</a>. The newer ingredients &ldquo;chocolate candy&rdquo; and &ldquo;peanut butter creme&rdquo; are only imitations.</p>
<blockquote>
<p>But today, REESE&rsquo;S  identity is being rewritten, not by storytellers, but by formulation  decisions that replace Milk Chocolate with compound coatings and Peanut  Butter with peanut‑butter‑style crèmes across multiple REESE’S products.</p>
<p>- Brad Reese</p></blockquote>
<p>Jonathan Deutsch over at the Conversation wrote that product reformulations in foods are common and most of the time <a href="https://theconversation.com/controversy-over-reeses-ingredients-reveals-standard-food-industry-practices-most-consumers-never-notice-276808">we don&rsquo;t even notice</a>. This along with shrinking the size of the product are the two main approaches companies use to reduce costs.</p>
<h2 id="discrimination-testing-for-food">Discrimination Testing for Food</h2>
<p>So how can companies be confident that few will notice? That&rsquo;s where discrimination testing comes in. From my research and what Jonathan shared, the most common type of discrimination test used in the food science industry is the <a href="https://www.sensorysociety.org/knowledge/sspwiki/Pages/Triangle%20Test.aspx">triangle test</a>.</p>
<p>In this test, the participant is given three products (A, B, C) and are told that only one of them is different. If the participant is able to correctly identify which one, then there&rsquo;s evidence that the average person can do the same. The probability that a random guess is correct is 1/3. Therefore, it&rsquo;s not sufficient to ask a single person and instead we need many participants to obtain statistical significance.</p>
<h2 id="discrimination-testing-for-audio">Discrimination Testing for Audio</h2>
<p>A few weeks later, I read Andreas&rsquo; post on <a href="https://82mhz.net/posts/2026/03/can-i-hear-a-difference-between-mp3s-and-uncompressed-audio/">telling the difference between compressed and uncompressed audio</a>. This made me curious on what discrimination tests are commonly used in the audio setting. However, this was difficult for me to search for.</p>
<p>In the food setting, I&rsquo;ve found multiple presentations and publications by the <a href="https://www.sensorysociety.org/Pages/default.aspx">Society of Sensory Professionals</a> and the <a href="https://www.ifpress.com/">Institute for Perception</a>. I wasn&rsquo;t able to easily find any groups focused on the audio setting. As our last resort, we&rsquo;ll trust Wikipedia and say that <a href="https://en.wikipedia.org/wiki/ABX_test">ABX Testing</a> is commonly used.</p>
<p>In ABX testing, the participant is told which sample is A and which sample is B. The task is then to guess whether X = A or X = B. What&rsquo;s important here is that the participant knows that A is not equal to B. Hence, the participant is provided with more information than in the triangle test setting.</p>
<p>For our audio example, we can say that A is the uncompressed audio, B is the compressed audio, and the task is to guess which X is. The probability of a random guess being correct in this test is 1/2 which is much higher than the triangle test.</p>
<p>Honestly, I can&rsquo;t figure out why this test is more common than the others. If you&rsquo;re a perception researcher and have some insight, please get in touch.</p>
<p>One thing to note about discrimination testing is that it only tells us if there is a perceptible difference. When comparing compression algorithms, we often want feedback on the perceived quality differences. I didn&rsquo;t look into this area much, but if you&rsquo;re interested then the <a href="https://en.wikipedia.org/wiki/MUSHRA">MUSHRA</a> method seems to be a good starting point.</p>
<h2 id="the-tip-of-the-iceburg">The Tip of the Iceburg</h2>
<p>As you might have noticed by now, I&rsquo;m not a perception researcher. There are a lot of discrimination tests out there and many folks are working on new ideas in this space. To close out this quick introduction,  I&rsquo;ll share two other approaches that I came across when writing this post.</p>
<p>First, there&rsquo;s the <a href="https://www.sensorysociety.org/knowledge/sspwiki/Pages/Two-out-of-five%20Test.aspx">two out of five test</a>. It&rsquo;s similar to the triangle test where the participant is given no labels but this time they&rsquo;re asked to identify the two that are unlike the other three. The probability of randomly guessing correctly in this test is 1/10 which is by far the lowest out of the approaches I shared in this post. The downside to this test is that the participant has to sample five items which might cause sensory fatigue and it&rsquo;s easy to give <a href="https://onlinelibrary.wiley.com/doi/10.1111/joss.12044">incorrect instructions</a>.</p>
<p><a href="https://www.ifpress.com/tr-15-1">Tetrad testing</a> is when the participant is given 4 samples and are asked to pair up the equivalent ones. The probability of guessing correctly is equivalent to that of the triangle test, but Ennis and Jesionka show that in some cases the Tetrad test <a href="https://doi.org/10.1111/j.1745-459X.2011.00353.x">requires one third the number of participants as that required by the triangle test</a>. The Institute for Perception released a techincal report arguing for the switch to Tetrad testing in order to <a href="https://www.ifpress.com/tr-15-1">reduce costs</a>. There&rsquo;s even a fun presentation publicly available by Hannah Lemar showing the suitability of the Tetrad test in the <a href="https://www.asbcnet.org/events/archives/2016/proceedings/Documents/8_Lemar.pdf">brewing industry</a>.</p>
<p>What do you think, is it important to perceive the original, or does an imitation work for you? For me, I don&rsquo;t mind listening to compressed audio at all. I like to think, however, that I&rsquo;m aware of what I&rsquo;m eating.</p>
]]></content:encoded>
  
</item>
  
  <item>
  <title>Praise the Smart Button</title>
  <link>https://brandonrozek.com/blog/praise-smart-button/</link>
  <pubDate>Fri, 22 May 2026 20:07:42 -0400</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid>https://brandonrozek.com/blog/praise-smart-button/</guid>
  <description><![CDATA[<img alt="Lamp which has a giraffe as it's base" height="500px" src="/files/images/blog/202605222012.jpg" />
<br/>

<p>Meet Giraffe. Equipped with an <a href="https://www.zigbee2mqtt.io/devices/AE_270_T.html">Innr AE 270 T</a> smart bulb, it allows me to turn the light on and off from our phones using <a href="https://www.home-assistant.io/">Home Assistant</a>. The main issue? I need my phone to turn it on and off.</p>
<p>Now don&rsquo;t get me wrong, I can still walk up to the lamp and flip the switch. But, then I need to walk back up to it in order to turn it back on. Turns out, the smart bulb needs some power to receive control messages via the network.</p>]]></description>
  <content:encoded><![CDATA[
<img alt="Lamp which has a giraffe as it's base" height="500px" src="/files/images/blog/202605222012.jpg" />
<br/>

<p>Meet Giraffe. Equipped with an <a href="https://www.zigbee2mqtt.io/devices/AE_270_T.html">Innr AE 270 T</a> smart bulb, it allows me to turn the light on and off from our phones using <a href="https://www.home-assistant.io/">Home Assistant</a>. The main issue? I need my phone to turn it on and off.</p>
<p>Now don&rsquo;t get me wrong, I can still walk up to the lamp and flip the switch. But, then I need to walk back up to it in order to turn it back on. Turns out, the smart bulb needs some power to receive control messages via the network.</p>
<p>If that wasn&rsquo;t annoying enough, flipping the switch off would mess with my cool automations. At sunrise, it&rsquo;s supposed to turn on to help wake me up and then automatically turn itself off after noon.</p>
<p>So I lived with that reality for a few years. Whenever I want to turn on or off the lamp, I would pull out my phone. Forgot to turn off the lights when I left the house? No worries, I can still control it remotely.</p>
<p>But that all changed this Christmas when my wife gifted me the following&hellip;</p>

<img alt="Lamp which has a giraffe as it's base" height="500px" src="/files/images/blog/202605222013.jpg" />
<br/>

<p>That&rsquo;s right. It&rsquo;s a <a href="https://www.zigbee2mqtt.io/devices/3RSB22BZ.html">Third Reality 3RSB22BZ</a> smart button. Setting this up was relatively straightforward. On Home Assistant, I clicked on &ldquo;Add Device&rdquo; and then specified that I wanted to add a Zigbee device. This requires a Zigbee hub, and for that I use the <a href="https://www.home-assistant.io/connect/zbt-2/">Home Assistant Connect ZBT-2</a>. After that, I went through a short pairing process and tada the device is added!</p>
<p>By itself, the button doesn&rsquo;t actually do anything. To change that, we need to set up automations. At the time of writing, Home Assistant specifies automations through triggers, conditions, and actions. I set my trigger to <code>remote_button_short_press</code>. I didn&rsquo;t add any extra conditions, and my action is to toggle my Giraffe lamp.</p>
<p>With that, I don&rsquo;t need to pull out my phone anymore to control the light!</p>
<hr>
<p>I&rsquo;ve been meaning to write more about my Home Assistant setup, but I&rsquo;m not sure what would be useful to share. For now I&rsquo;ll write what&rsquo;s on my mind, but feel free to get in touch if you want me to share more.</p>
<p>I started off my Home Assistant journey by purchasing smart bulbs and smart switches flashed with the <a href="https://tasmota.github.io/docs/">Tasmota firmware</a>. The devices specifically connected to my local WiFi network and sent messages to my MQTT server.</p>
<p>However, I wasn&rsquo;t the happiest with the quality of my smart bulbs. I came across itchaboyagin&rsquo;s post on the <a href="https://community.home-assistant.io/t/i-just-finished-testing-over-150-of-the-best-smart-lights-here-s-all-the-data/764760">Home Assistant forum</a> where they shared a <a href="https://optimizeyourbiology.com/smart-light-database/">database</a> of 120 different smart bulbs full of metrics. What I was looking for at the time escaped by head, but I believe I focused on bulbs with no flicker risk and great <a href="https://en.wikipedia.org/wiki/Color_rendering_index">color quality</a>.</p>
<p>That&rsquo;s when I came across the Innr bulb and noticed that it relied on Zigbee for connectivity.
This means that instead of connecting to my WiFI, it creates it&rsquo;s own mesh network and requires a hub to work. So&hellip; I needed to purchase an extra device. Luckily, many companies support the Zigbee standard, so I told myself that this would open up oppurtunities for future devices.</p>
<p>Overall, I&rsquo;ve been rocking this new setup for the last 6 months and I&rsquo;m happy.</p>
]]></content:encoded>
  
</item>
  
  <item>
  <title>Baked Salmon</title>
  <link>https://brandonrozek.com/menu/baked-salmon/</link>
  <pubDate>Thu, 30 Apr 2026 00:00:00 +0000</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid>https://brandonrozek.com/menu/baked-salmon/</guid>
  <description><![CDATA[<p>Prep Time: 5 minutes</p>
<p>Cook Time: 10 minutes</p>
<h1 id="ingridients">Ingridients</h1>
<ul>
<li>Salmon</li>
<li>1 tblspoon lemon</li>
<li>3 tblspoon soy sauce</li>
<li>some amount of honey</li>
<li>2 tablespoons of butter</li>
<li>Sushi Rice</li>
<li>Kewpie Mayo</li>
<li>Avocado</li>
<li>Nori (Optional)</li>
</ul>
<h1 id="recipe">Recipe</h1>
<ol>
<li>Set oven to 450 degrees</li>
<li>Put the rice with equal parts water in a rice cooker and get that started.</li>
<li>Grab a small bowl and make the sauce by mixing the soy sauce, lemon, butter, and honey. Make sure the butter is melted, one way is to use the microwave.</li>
<li>Pour the sauce mixture onto the salmon itself in a oven-safe dish.</li>
<li>When the oven is ready, pop it in there for 10 minutes. The salmon should be 145 degrees fahrenheit.</li>
<li>Once out, peel off the skin from the salmon.</li>
<li>Grab a large mixing bowl and put in the cooked rice and salmon.</li>
<li>Put some of the remaining sauce from the oven dish into the mixing bowl. How much is really a preference.</li>
<li>Add some amount of kewpie mayo.</li>
<li>Carefully mix. You don&rsquo;t want to mush up the salmon. It will naturally break itself in one direction.</li>
<li>Dice up and add avocados to the mixing bowl.</li>
</ol>
<p>Serve in a bowl (with nori) and enjoy!</p>]]></description>
  <content:encoded><![CDATA[<p>Prep Time: 5 minutes</p>
<p>Cook Time: 10 minutes</p>
<h1 id="ingridients">Ingridients</h1>
<ul>
<li>Salmon</li>
<li>1 tblspoon lemon</li>
<li>3 tblspoon soy sauce</li>
<li>some amount of honey</li>
<li>2 tablespoons of butter</li>
<li>Sushi Rice</li>
<li>Kewpie Mayo</li>
<li>Avocado</li>
<li>Nori (Optional)</li>
</ul>
<h1 id="recipe">Recipe</h1>
<ol>
<li>Set oven to 450 degrees</li>
<li>Put the rice with equal parts water in a rice cooker and get that started.</li>
<li>Grab a small bowl and make the sauce by mixing the soy sauce, lemon, butter, and honey. Make sure the butter is melted, one way is to use the microwave.</li>
<li>Pour the sauce mixture onto the salmon itself in a oven-safe dish.</li>
<li>When the oven is ready, pop it in there for 10 minutes. The salmon should be 145 degrees fahrenheit.</li>
<li>Once out, peel off the skin from the salmon.</li>
<li>Grab a large mixing bowl and put in the cooked rice and salmon.</li>
<li>Put some of the remaining sauce from the oven dish into the mixing bowl. How much is really a preference.</li>
<li>Add some amount of kewpie mayo.</li>
<li>Carefully mix. You don&rsquo;t want to mush up the salmon. It will naturally break itself in one direction.</li>
<li>Dice up and add avocados to the mixing bowl.</li>
</ol>
<p>Serve in a bowl (with nori) and enjoy!</p>
]]></content:encoded>
  
</item>
  
  <item>
  <title>Paella</title>
  <link>https://brandonrozek.com/menu/paella/</link>
  <pubDate>Thu, 30 Apr 2026 00:00:00 +0000</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid>https://brandonrozek.com/menu/paella/</guid>
  <description><![CDATA[<p>Inspired from this <a href="https://www.simplyrecipes.com/recipes/pressure_cooker_paella_with_chicken_and_sausage/">recipe</a>.</p>
<p>This dish is traditionally made with white rice and it
is tastier that way, but I&rsquo;ve been experimenting with eating
more brown rice recently.</p>
<h1 id="ingridients">Ingridients</h1>
<ul>
<li>1.5 cups of brown/white rice</li>
<li>2.5 cups of chicken broth if brown rice used otherwise 1.5 cups</li>
<li>1 bag of frozen peas</li>
<li>2 shallots</li>
<li>Red bell pepper</li>
<li>Chorizo</li>
<li>Half tablespoon tumeric</li>
<li>1 teaspoon smoked paprika</li>
<li>1 teaspoon salt</li>
</ul>
<h1 id="recipe">Recipe</h1>
<ol>
<li>Dice up the bell pepper and shallots, and throw onto a pan on the stove.</li>
<li>Take the chorizo and slice it up.</li>
<li>Saute pepper, shallots, and chorizo on the pan for 5 minutes.</li>
<li>Throw everything into the instant pot.</li>
<li>Set the pressure cook to high and 25 minutes</li>
<li>Let it naturally release for 10 minutes</li>
</ol>
<p>Enjoy!</p>]]></description>
  <content:encoded><![CDATA[<p>Inspired from this <a href="https://www.simplyrecipes.com/recipes/pressure_cooker_paella_with_chicken_and_sausage/">recipe</a>.</p>
<p>This dish is traditionally made with white rice and it
is tastier that way, but I&rsquo;ve been experimenting with eating
more brown rice recently.</p>
<h1 id="ingridients">Ingridients</h1>
<ul>
<li>1.5 cups of brown/white rice</li>
<li>2.5 cups of chicken broth if brown rice used otherwise 1.5 cups</li>
<li>1 bag of frozen peas</li>
<li>2 shallots</li>
<li>Red bell pepper</li>
<li>Chorizo</li>
<li>Half tablespoon tumeric</li>
<li>1 teaspoon smoked paprika</li>
<li>1 teaspoon salt</li>
</ul>
<h1 id="recipe">Recipe</h1>
<ol>
<li>Dice up the bell pepper and shallots, and throw onto a pan on the stove.</li>
<li>Take the chorizo and slice it up.</li>
<li>Saute pepper, shallots, and chorizo on the pan for 5 minutes.</li>
<li>Throw everything into the instant pot.</li>
<li>Set the pressure cook to high and 25 minutes</li>
<li>Let it naturally release for 10 minutes</li>
</ol>
<p>Enjoy!</p>
]]></content:encoded>
  
</item>
  
  <item>
  <title>Expectations are Linear</title>
  <link>https://brandonrozek.com/blog/expectations-are-linear/</link>
  <pubDate>Sun, 26 Apr 2026 09:03:28 -0400</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid>https://brandonrozek.com/blog/expectations-are-linear/</guid>
  <description><![CDATA[<blockquote>
<p>As an example, he asked me, in more words, what the expected rank when flipping over the top card of a deck of cards was (A=1, J=11, Q=12,  K=13). This is easy to compute directly as 7. Then he asked me the expectation of the <em>sum of the top two cards</em>.</p>
<p>- <a href="https://buttondown.com/jaffray/archive/expectation-and-copysets/">From &ldquo;Expectation and Copysets&rdquo; by Justin Jaffray</a></p></blockquote>
<p>What does your intuition say the answer is? Justin continues by stating that computing this expectation is as easy as summing their individual expectations.
$$
E[X + Y] = E[X] + E[Y]
$$
In other words, <strong>expectations are linear</strong>. I recommend reading his entire blog post. It&rsquo;s great and also talks about how this property is used in databases today. After a high-level explanation, he says:</p>]]></description>
  <content:encoded><![CDATA[<blockquote>
<p>As an example, he asked me, in more words, what the expected rank when flipping over the top card of a deck of cards was (A=1, J=11, Q=12,  K=13). This is easy to compute directly as 7. Then he asked me the expectation of the <em>sum of the top two cards</em>.</p>
<p>- <a href="https://buttondown.com/jaffray/archive/expectation-and-copysets/">From &ldquo;Expectation and Copysets&rdquo; by Justin Jaffray</a></p></blockquote>
<p>What does your intuition say the answer is? Justin continues by stating that computing this expectation is as easy as summing their individual expectations.
$$
E[X + Y] = E[X] + E[Y]
$$
In other words, <strong>expectations are linear</strong>. I recommend reading his entire blog post. It&rsquo;s great and also talks about how this property is used in databases today. After a high-level explanation, he says:</p>
<blockquote>
<p>The fact that expectation is linear is easy to show if you just look at the definition, which we will not do here, but I trust you are capable of if you are interested and have not already seen it.</p></blockquote>
<p>In this episode of <em>Exercise for the Reader</em> (<a href="/blog/implications-prenex-normal-form/">last episode</a>), we&rsquo;ll look at the definition and show why this property holds. This is true regardless of the underlying probability distribution and whether or not we&rsquo;re sampling with replacement.</p>
<p>As Justin stated, let&rsquo;s start with the definition of expectation and then split the sum:
$$
\begin{align*}
E[X + Y] &amp;= \sum_{x \in X} \sum_{y \in Y} (x + y) \cdot P(X = x, Y=y) \\
&amp;= (\sum_{x \in X} \sum_{y \in Y} x \cdot P(X = x, Y = y)) + (\sum_{x \in X} \sum_{y \in Y} y \cdot P(X = x, Y = y))
\end{align*}
$$
Notice that the left-hand-side of the multiplication does not depend on both variables anymore. Also it doesn&rsquo;t matter whether we do the summation over $X$ first or $Y$. Therefore, we can bring that variable out of the inner sum and simplify this to:
$$
E[X + Y] = (\sum_{x \in X} x \sum_{y \in Y} P(X = x, Y = y)) + (\sum_{y \in Y} y \sum_{x \in X} P(X = x, Y = y))
$$
We can then perform <em>marginalization</em> to substitute $\sum_{y \in Y} P(X = x, Y = y)$ with $P(X = x)$ and do the same for the right hand side of the sum.
$$
\begin{align*}
E[X + Y] &amp;= (\sum_{x \in X}xP(X = x)) + (\sum_{y \in y}yP(Y=y))) \\
&amp;= E[x] + E[Y]
\end{align*}
$$</p>
<hr>
<p>Why can we marginalize? For me to show why, we need to peel back the curtain on the notation.</p>
<p>The set $\Omega$ contains the outcomes of all the events that we&rsquo;re concerned about. So, if we are considering events $X$ and $Y$ with outcomes $x_i$ and $y_i$, respectively. Then, our event space $\Omega$ is equal to $\{ (x_i, y_i) \mid x_i \in X, y_i \in Y\}$.</p>
<p>Therefore when we say $X = x$, what we really mean is the set of outcomes where that is true. In mathematical terms, $\{\omega \in \Omega \mid X(\omega) = x\}$.</p>
<p>Now, let&rsquo;s show why $\sum_{y \in Y} P(X = x, Y = y) = P(X = x)$.
$$
\sum_{y \in Y}P(X = x, Y = y) = \sum_{y \in Y} P(\{\omega \in \Omega \mid X(\omega) = x\} \cap \{\omega \in \Omega \mid Y(\omega) = y\})
$$
One of the three Kolmogorov axioms of probability is <strong>countable additivity</strong>. This is defined as:
$$
\sum_{x \in A}P(X = x) = P(\bigcup_{x \in A}X =x )
$$
Substituting that in and simplifying, we get:
$$
\begin{align*}
\sum_{y \in Y}P(X = x, Y = y) &amp;= P(\bigcup_{y \in Y}(\{\omega \in \Omega \mid X(\omega) = x\} \cap \{\omega \in \Omega \mid Y(\omega) = y\})) \\
&amp;= P(\{\omega \in \Omega \mid X(\omega) = x\} \cap \bigcup_{y \in Y}\{\omega \in \Omega \mid Y(\omega) = y\})
\end{align*}
$$
Notice that the right hand side of the term is just $\Omega$. We can then simplify to,
$$
\begin{align*}
\sum_{y \in Y}P(X = x, Y = y) &amp;= P(\{\omega \in \Omega \mid X(\omega) = x\} \cap \Omega) \\
&amp;= P(\{\omega \in \Omega \mid X(\omega) = x\}) \\
&amp;= P(X = x)
\end{align*}
$$
Since countable additivity is an axiom, we&rsquo;ll stop our derivations there.  See you next time.</p>
]]></content:encoded>
  
</item>
  
  <item>
  <title>Filtering Goals of Necessity-Optimal Agents in Qualitative Possibilistic Recognition via Planning</title>
  <link>https://brandonrozek.com/paper/2603.01/</link>
  <pubDate>Thu, 05 Mar 2026 00:00:00 +0000</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid>https://brandonrozek.com/paper/2603.01/</guid>
  <description><![CDATA[]]></description>
  <content:encoded><![CDATA[]]></content:encoded>
  
</item>
  
  <item>
  <title>VSPursuer: A Tool for Finding Matrices Witnessing the Variable Sharing Property</title>
  <link>https://brandonrozek.com/paper/2602.01/</link>
  <pubDate>Mon, 09 Feb 2026 00:00:00 +0000</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid>https://brandonrozek.com/paper/2602.01/</guid>
  <description><![CDATA[]]></description>
  <content:encoded><![CDATA[]]></content:encoded>
  
</item>
  
  <item>
  <title>Bringing this website to the Tor network</title>
  <link>https://brandonrozek.com/blog/on-the-tor-network/</link>
  <pubDate>Sun, 01 Feb 2026 17:47:15 -0500</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid>https://brandonrozek.com/blog/on-the-tor-network/</guid>
  <description><![CDATA[<p>I believe in the freedom of information. By making my website available as a Tor hidden service, you can be sure to access the information even if it&rsquo;s blocked on the clearweb.</p>
<p>In this post, I&rsquo;ll share the steps I took and what I learned along the way. Huge credit to Christian <a href="https://cleberg.net/blog/self-hosting-tor.html">who wrote their own succinct version</a> of this post and helped me troubleshoot via email.</p>
<h3 id="getting-an-address">Getting an Address</h3>
<p>Unlike the clear web, we don&rsquo;t register a domain with anyone. <a href="https://github.com/torproject/torspec/blob/main/rend-spec-v3.txt">An address on Tor is a hash of your public key.</a></p>]]></description>
  <content:encoded><![CDATA[<p>I believe in the freedom of information. By making my website available as a Tor hidden service, you can be sure to access the information even if it&rsquo;s blocked on the clearweb.</p>
<p>In this post, I&rsquo;ll share the steps I took and what I learned along the way. Huge credit to Christian <a href="https://cleberg.net/blog/self-hosting-tor.html">who wrote their own succinct version</a> of this post and helped me troubleshoot via email.</p>
<h3 id="getting-an-address">Getting an Address</h3>
<p>Unlike the clear web, we don&rsquo;t register a domain with anyone. <a href="https://github.com/torproject/torspec/blob/main/rend-spec-v3.txt">An address on Tor is a hash of your public key.</a></p>
<p>This is why onion URLs are long and unreadable. Take a look at the following onion URL which takes you to the Tor homepage.</p>
<pre tabindex="0"><code>http://2gzyxa5ihm7nsggfxnu52rck2vv4rvmdlkiu3zzui5du4xyclen53wid.onion
</code></pre><p>Notice that the address starts with <code>http</code>. Unlike the clearweb, <em>all</em> traffic via Tor is encrypted. Our hidden service will use the public key behind the URL during the protocol exchange.</p>
<p>The primary benefit of these addresses are that they are entirely decentralized (we create our own keys). They are also incredibly difficult to spoof. The downside is that they are not human readable. We can get a little bit closer to that though with vanity keys.</p>
<p>To create a vanity key, we can use <a href="https://github.com/cathugger/mkp224o#requirements">mkp224o</a>. After following the installation instructions, we can create our own onion URL starting with some <code>prefix</code> by running the following:</p>
<pre tabindex="0"><code>./mkp224o prefix
</code></pre><p>Given the current algorithms and hardware, we can easily generate keys which have a URL prefix length of up to six characters in minutes. Beyond that, the generation quickly becomes infeasible&hellip; However, we want this to be the case. If it was feasible to generate a key-pair for an entire onion URL then anyone can spoof your hidden service.</p>
<p>The script by default will create many folders in the current directory which have the onion URLs as their name and the contents of the keys within. Pick your favorite and copy it over to <code>/var/lib/tor/somehiddenservicename</code>.</p>
<p><strong>While you&rsquo;re at it, make a backup of these keys because if we lose it then we lose control over the domain.</strong></p>
<h2 id="installing-and-configuring-tor">Installing and Configuring Tor</h2>
<p>Now that we have our address. Let&rsquo;s get Tor installed and set up. In this guide, I&rsquo;ll show how to do so via Podman Quadlets.</p>
<p>We&rsquo;ll use the Docker container <a href="https://github.com/dockur/tor">dockur/tor</a>. Since Tor is a cryptographic software, we need to be extremely careful where we download it from. As of this time of writing if we look at the Dockerfile in this repo, we can see that this is a simple wrapper over Alpine&rsquo;s tor packages. Currently, I feel that it&rsquo;s safe to trust the Alpine maintainers.</p>
<p>After selecting the Docker container, we need to write the Quadlet definition file. Here&rsquo;s how I have <code>/etc/containers/systemd/tor.container</code> configured:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ini" data-lang="ini"><span style="display:flex;"><span><span style="color:#66d9ef">[Container]</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">ContainerName</span><span style="color:#f92672">=</span><span style="color:#e6db74">tor</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">HostName</span><span style="color:#f92672">=</span><span style="color:#e6db74">tor</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">Image</span><span style="color:#f92672">=</span><span style="color:#e6db74">docker.io/dockurr/tor</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">AutoUpdate</span><span style="color:#f92672">=</span><span style="color:#e6db74">registry</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">Volume</span><span style="color:#f92672">=</span><span style="color:#e6db74">/etc/tor:/etc/tor:ro,Z</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">Volume</span><span style="color:#f92672">=</span><span style="color:#e6db74">/var/lib/tor:/var/lib/tor:Z,U</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">[Service]</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">Restart</span><span style="color:#f92672">=</span><span style="color:#e6db74">always</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">[Install]</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">WantedBy</span><span style="color:#f92672">=</span><span style="color:#e6db74">default.target</span>
</span></span></code></pre></div><p>Before we run it, we&rsquo;ll need to create our main Tor configuration file. This lives in <code>/etc/tor/torrc</code>.</p>
<pre tabindex="0"><code>SocksPort 0
HiddenServiceDir /var/lib/tor/somehiddenservicename
HiddenServicePort 80 IP_OF_NGINX_CONTAINER:80
</code></pre><p>Replace <code>IP_OF_NGINX_CONTAINER</code> with the internal IP of the Nginx container or of the host machine if it is running on there. Here&rsquo;s an explanation of each line:</p>
<table>
  <thead>
      <tr>
          <th>Key</th>
          <th>Value</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><code>SocksPort</code></td>
          <td>By default, the tor service will open a SOCKS port so that we can have other HTTP clients proxy to the dark web. Setting this to 0 disables that behavior.</td>
      </tr>
      <tr>
          <td><code>HiddenServiceDir</code></td>
          <td>The location of our hostname file and the keys for our hidden service.</td>
      </tr>
      <tr>
          <td><code>HiddenServicePort</code></td>
          <td>The port on the Tor network followed by the <code>address:port</code> to proxy the traffic to. We may have multiple of these per hidden service.</td>
      </tr>
  </tbody>
</table>
<p>Since we&rsquo;re proxying traffic to our application, let&rsquo;s configure our target next.</p>
<h2 id="configuring-nginx">Configuring Nginx</h2>
<p>My website is a static site served by Nginx. These files are linked together via absolute URLs. This adds some complications because the onion hidden service URL is completely different than my clearnet one.</p>
<p>One solution would be to make my URLs relative. However, I want my website to be as portable as possible. For example, you can run my website in a subfolder. Thus, our solution here is to have an entirely separate copy of the website where the only difference is the internal URLs.</p>
<p>I&rsquo;ve set this version of my website to live in <code>/var/www/brozekhs</code>.</p>
<p>As such, we have to create an Nginx configuration file solely for our hidden service. We&rsquo;ll make sure to point the root to the folder which contains the hidden service version of my website.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-nginx" data-lang="nginx"><span style="display:flex;"><span><span style="color:#66d9ef">server</span> {
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">listen</span> <span style="color:#ae81ff">80</span>;
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">server_name</span> <span style="color:#e6db74">ONION_URL</span>;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>	<span style="color:#f92672">root</span> <span style="color:#e6db74">/var/www/brozekhs</span>;
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">index</span> <span style="color:#e6db74">index.html</span>;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>	<span style="color:#75715e"># ...
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span>	<span style="color:#f92672">location</span> <span style="color:#e6db74">/</span> {
</span></span><span style="display:flex;"><span>		<span style="color:#f92672">allow</span> <span style="color:#e6db74">IP_OF_TOR_CONTAINER</span>;
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">deny</span> <span style="color:#e6db74">all</span>;
</span></span><span style="display:flex;"><span>        <span style="color:#75715e"># ...
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>	}
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>Replace <code>/var/www/brozekhs</code>, <code>ONION_URL</code> and <code>IP_OF_TOR_CONTAINER</code> with their respective values. We need to configure the <code>allow</code> and <code>deny</code> lines because we don&rsquo;t want someone to confirm that our machine responds to tor addresses over the clearnet.</p>
<p>After this when running my <code>nginx</code> container I came across the following error:</p>
<pre tabindex="0"><code>date time [emerg] 1#1: could not build server_names_hash, you should increase server_names_hash_bucket_size: 64
</code></pre><p>As stated, the solution is to increase the server name hash bucket size. I doubled it from 64 to 128 in the <code>http</code> block of <code>/etc/nginx/nginx.conf</code>:</p>
<pre tabindex="0"><code>server_names_hash_bucket_size 128;
</code></pre><p>Lastly if you have a clearnet site and you want to advertise the onion URL for users visiting the clearnet URL on the Tor browser, then we can add an <a href="https://community.torproject.org/onion-services/advanced/onion-location/"><code>Onion-Location</code> header</a> to the Nginx config of our clearnet site.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-nginx" data-lang="nginx"><span style="display:flex;"><span><span style="color:#66d9ef">location</span> <span style="color:#e6db74">/</span> {
</span></span><span style="display:flex;"><span>	<span style="color:#75715e"># ...
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>    <span style="color:#f92672">add_header</span> <span style="color:#e6db74">Onion-Location</span> <span style="color:#e6db74">ONION_URL</span>$request_uri;
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>Replace <code>ONION_URL</code> with your own and make sure that <code>$request_uri</code> stays at the end of the header value. This will help the Tor browser with the redirection.</p>
<h2 id="start-em-up">Start em up!</h2>
<p>With that, we can start our two services:</p>
<pre tabindex="0"><code>sudo systemctl start nginx
sudo systemctl start tor
</code></pre><p>When we look at <code>journalctl -U tor</code>, we should see something like the following:</p>
<pre tabindex="0"><code>datetime hostname systemd[1]: Started tor.service.
datetime hostname tor[681220]: datetime [notice] Tor can&#39;t help you if you use it wrong! Learn how to be safe at https://support.torproject.org/faq/staying-anonymous/
datetime hostname tor[681220]: datetime [notice] Read configuration file &#34;/etc/tor/torrc&#34;.
datetime hostname tor[681220]: datetime [notice] Parsing GEOIP IPv4 file /usr/share/tor/geoip.
datetime hostname tor[681220]: datetime [notice] Parsing GEOIP IPv6 file /usr/share/tor/geoip6.
datetime hostname tor[681220]: datetime [notice] Bootstrapped 0% (starting): Starting
datetime hostname tor[681220]: datetime [notice] Starting with guard context &#34;default&#34;
datetime hostname tor[681220]: datetime [notice] Bootstrapped 5% (conn): Connecting to a relay
datetime hostname tor[681220]: datetime [notice] Bootstrapped 10% (conn_done): Connected to a relay
datetime hostname tor[681220]: datetime [notice] Bootstrapped 14% (handshake): Handshaking with a relay
datetime hostname tor[681220]: datetime [notice] Bootstrapped 15% (handshake_done): Handshake with a relay done
datetime hostname tor[681220]: datetime [notice] Bootstrapped 45% (requesting_descriptors): Asking for relay descriptors
datetime hostname tor[681220]: datetime [notice] Bootstrapped 50% (loading_descriptors): Loading relay descriptors
datetime hostname tor[681220]: datetime [notice] Bootstrapped 55% (loading_descriptors): Loading relay descriptors
datetime hostname tor[681220]: datetime [notice] Bootstrapped 60% (loading_descriptors): Loading relay descriptors
datetime hostname tor[681220]: datetime [notice] Bootstrapped 66% (loading_descriptors): Loading relay descriptors
datetime hostname tor[681220]: datetime [notice] Bootstrapped 75% (enough_dirinfo): Loaded enough directory info to build circuits
datetime hostname tor[681220]: datetime [notice] Bootstrapped 90% (ap_handshake_done): Handshake finished with a relay to build circuits
datetime hostname tor[681220]: datetime [notice] Bootstrapped 95% (circuit_create): Establishing a Tor circuit
datetime hostname tor[681220]: datetime [notice] Bootstrapped 100% (done): Done
</code></pre><p>We won&rsquo;t be able to access the hidden service until the bootstrapping process reaches 100%. Depending on the state of the network, this might take awhile&hellip;</p>
<p>I mention the network state since it&rsquo;s common for me to see this in the logs:</p>
<pre tabindex="0"><code>datetime hostname tor[295456]: datetime [warn] Detected possible compression bomb with input size = 17413 and output size = 515472 (compression factor = 29.60)
datetime hostname tor[295456]: datetime [warn] Possible compression bomb; abandoning stream.
datetime hostname tor[295456]: datetime [warn] Detected possible compression bomb with input size = 23289 and output size = 774624 (compression factor = 33.26)
datetime hostname tor[295456]: datetime [warn] Possible compression bomb; abandoning stream.
</code></pre><p>This compression or <a href="https://en.wikipedia.org/wiki/Zip_bomb">zip bomb</a> appears to be an attempt at a distributed <a href="https://en.wikipedia.org/wiki/Denial-of-service_attack">denial of service attack</a>. Luckily, the Tor software is smart enough to guard against this.</p>
<p>Every so often my Tor service goes down and I need to restart the daemon for it to come back up. I haven&rsquo;t gotten around to writing monitoring scripts for my hidden service so if anyone has any tips feel free to get in touch.</p>
]]></content:encoded>
  
</item>
  
  <item>
  <title>Tales of Christmas Trees</title>
  <link>https://brandonrozek.com/blog/tales-of-christmas-trees/</link>
  <pubDate>Sun, 25 Jan 2026 17:59:15 -0500</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid>https://brandonrozek.com/blog/tales-of-christmas-trees/</guid>
  <description><![CDATA[<p>In 2020, Clare and I got our first live Christmas tree. We were living in Virginia at the time, and we showed up to a farm that had many trees planted in rows. They gave us a bow saw, and it was up to us to chop one down and bring it home.</p>
<p><img src="/files/images/blog/transportingtree2020.jpg" alt="Brandon hauling his tree in a cart."></p>
<p>I enjoyed having a live tree in my apartment. I still remember the smell of fresh conifer. After several weeks, the holidays pass and the needles start falling to the ground. I don&rsquo;t quite remember how we got rid of this tree, but I wouldn&rsquo;t be surprised if we just threw it in our dumpster.</p>]]></description>
  <content:encoded><![CDATA[<p>In 2020, Clare and I got our first live Christmas tree. We were living in Virginia at the time, and we showed up to a farm that had many trees planted in rows. They gave us a bow saw, and it was up to us to chop one down and bring it home.</p>
<p><img src="/files/images/blog/transportingtree2020.jpg" alt="Brandon hauling his tree in a cart."></p>
<p>I enjoyed having a live tree in my apartment. I still remember the smell of fresh conifer. After several weeks, the holidays pass and the needles start falling to the ground. I don&rsquo;t quite remember how we got rid of this tree, but I wouldn&rsquo;t be surprised if we just threw it in our dumpster.</p>
<p>We later moved to New York. For the next few years, we would travel to see friends and family during the holidays. I used that as an excuse to not have a tree setup at home. Eventually Clare convinces me that we should still be festive at home, and we bought a plastic tree.</p>
<p>Around us in upstate New York, there are several bonfire events in January. There&rsquo;s one in particular that we&rsquo;ve attended for several New Year&rsquo;s Eve. What&rsquo;s special about this bonfire is that the fuel of the fire is not prepared as chopped wood in advance. Instead, it is sourced from the community.</p>
<p>Let me paint a picture. It&rsquo;s a cold winter night, and there is a group of around 20-30 people bundled up in full winter gear staying close to the bonfire. As time progresses, the fire gets smaller and smaller, and we get closer to try to feel some of its heat.  Then, a person in a pickup truck arrives, gets out of their vehicle, and chucks their Christmas tree from the bed of the truck onto the fire. The fire rages.</p>
<p><img src="/files/images/blog/bonfire2025.jpg" alt="Christmas tree burning in a bonfire"></p>
<p>Now I find this very cool, but some trees have different fates. Ton writes on <a href="https://www.zylstra.org/blog/2026/01/not-the-elves/">his blog</a> that they have the same tree every year. Instead of sawing their tree down, the tree gets delivered to their place with the root ball intact. Once the holidays are over, the growers come back and pick it up.</p>
<p>Through an email exchange, I learn that this is a <a href="https://adopteereenkerstboom.nl/">national service</a> over in the Netherlands. Now that&rsquo;s pretty cool.</p>
]]></content:encoded>
  
</item>
  
  <item>
  <title>Blogging as an Invitation for Dialogue</title>
  <link>https://brandonrozek.com/blog/blogging-as-dialogue-invitation/</link>
  <pubDate>Thu, 15 Jan 2026 11:21:29 -0500</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid>https://brandonrozek.com/blog/blogging-as-dialogue-invitation/</guid>
  <description><![CDATA[<p>We have many ways to share ideas today. We can:</p>
<ul>
<li>Text</li>
<li>Email</li>
<li>Pen a letter</li>
<li>Post on a microblog (Mastodon/X/Pixelfed/etc.)</li>
<li>Write a blog post</li>
</ul>
<p>But not all of these methods inherently create a conversation or dialogue. When I write a technical blog post, I don&rsquo;t expect a reply. Similarly, when I toot on Mastodon, I&rsquo;m fine if no one favorited the post. As such, (micro-)blogging differs greatly from texting and calling someone and is instead much closer to recording a postcast or uploading a video &ndash; a one-way transmission of information.</p>]]></description>
  <content:encoded><![CDATA[<p>We have many ways to share ideas today. We can:</p>
<ul>
<li>Text</li>
<li>Email</li>
<li>Pen a letter</li>
<li>Post on a microblog (Mastodon/X/Pixelfed/etc.)</li>
<li>Write a blog post</li>
</ul>
<p>But not all of these methods inherently create a conversation or dialogue. When I write a technical blog post, I don&rsquo;t expect a reply. Similarly, when I toot on Mastodon, I&rsquo;m fine if no one favorited the post. As such, (micro-)blogging differs greatly from texting and calling someone and is instead much closer to recording a postcast or uploading a video &ndash; a one-way transmission of information.</p>
<p>Ploum wrote about how he views the <a href="https://ploum.net/2025-12-15-communication-entertainment.html">ActivityPub protocol as a conversation</a>, and as such servers should not filter posts based on <a href="https://ploum.net/2025-12-04-pixelfed-against-fediverse.html">whether they have a picture</a>. Now I&rsquo;m not on Pixelfed, so I do not have a stake in this issue. However since I view Pixelfed as a microblogging platform, I tend to see it as more of a one-way transmission of information rather than soliciting a response from my friends. This view would put me in the category of folks that view AcitvityPub as a &ldquo;content consumption platform.&rdquo; Though I find that term derogative<sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup>.</p>
<p>Now should Pixelfed filter posts based on whether it contains a picture? I&rsquo;m not sure. But if I was on Mastodon and I specifically @&rsquo;d  someone on Pixelfed,  then I would sure hope that either they received that message or I was shown an error.</p>
<p>So if we&rsquo;re not having a conversation with these (micro-)blog posts, what are we doing? Some of us are trying to teach, keep a public journal, or share our perspectives.  Some of us don&rsquo;t even want responses<sup id="fnref:2"><a href="#fn:2" class="footnote-ref" role="doc-noteref">2</a></sup>. Though I find that many of us do:</p>
<blockquote>
<p>Blog posts become invitations that never expire
- <a href="https://dri.es/20-years-of-blogging">Dries</a></p></blockquote>
<p>When I send a postcard to a loved one, they don&rsquo;t need to reply. However, I send it because it&rsquo;s an acknowledgement of our relationship and it&rsquo;s an invitation to reach out.</p>
<p>Similarly when I write a blog post, by default I&rsquo;m only transmitting information. However, any of you readers can choose to promote this from a transmission to an exchange. From a communication to a dialogue.</p>
<div class="footnotes" role="doc-endnotes">
<hr>
<ol>
<li id="fn:1">
<p>The idea that folks are doom-scrolling and are only consuming empty calories misses how communities are  formed on these platforms &ndash; complete with their own social norms.&#160;<a href="#fnref:1" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
<li id="fn:2">
<p>Every so often I get sad when I want to reply to someone, but I don&rsquo;t see an email to reach out to.&#160;<a href="#fnref:2" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
</ol>
</div>
]]></content:encoded>
  
</item>
  
  <item>
  <title></title>
  <link></link>
  <pubDate>Sun, 11 Jan 2026 23:16:43 +0000</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid></guid>
  <description><![CDATA[<p>Wikipedia turns 25 this upcoming Thursday 🎂 🎈 🎉 </p><p><a href="https://meta.wikimedia.org/wiki/Event:Wikipedia_25_Virtual_Celebration" target="_blank" rel="nofollow noopener" translate="no"><span class="invisible">https://</span><span class="ellipsis">meta.wikimedia.org/wiki/Event:</span><span class="invisible">Wikipedia_25_Virtual_Celebration</span></a></p><p>Here&#39;s to another 25 years!</p>]]></description>
  <content:encoded><![CDATA[<p>Wikipedia turns 25 this upcoming Thursday 🎂 🎈 🎉 </p><p><a href="https://meta.wikimedia.org/wiki/Event:Wikipedia_25_Virtual_Celebration" target="_blank" rel="nofollow noopener" translate="no"><span class="invisible">https://</span><span class="ellipsis">meta.wikimedia.org/wiki/Event:</span><span class="invisible">Wikipedia_25_Virtual_Celebration</span></a></p><p>Here&#39;s to another 25 years!</p>]]></content:encoded>
  
</item>
  
  <item>
  <title>Backing up my data with Restic, Btrfs, and MinIO</title>
  <link>https://brandonrozek.com/blog/backups-with-restic-btrfs/</link>
  <pubDate>Tue, 30 Dec 2025 11:51:07 -0500</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid>https://brandonrozek.com/blog/backups-with-restic-btrfs/</guid>
  <description><![CDATA[<p>For the past year, I settled on a backup strategy that serves my needs. In this post, I&rsquo;ll share the properties I look for in a backup solution and how my current solution addresses them. As always, if you have any suggestions or improvements, feel free to get in touch.</p>
<p>The first step before talking technology is to identify exactly what data we want to backup. In my homelab, I rely on <a href="https://immich.app/">Immich</a> for photo storage, <a href="https://www.navidrome.org/">Navidrome</a> for music streaming, databases for my website, and other personal documents. This amounts to a little over 250 GB of data that would be very difficult for me to replace if it was lost.</p>]]></description>
  <content:encoded><![CDATA[<p>For the past year, I settled on a backup strategy that serves my needs. In this post, I&rsquo;ll share the properties I look for in a backup solution and how my current solution addresses them. As always, if you have any suggestions or improvements, feel free to get in touch.</p>
<p>The first step before talking technology is to identify exactly what data we want to backup. In my homelab, I rely on <a href="https://immich.app/">Immich</a> for photo storage, <a href="https://www.navidrome.org/">Navidrome</a> for music streaming, databases for my website, and other personal documents. This amounts to a little over 250 GB of data that would be very difficult for me to replace if it was lost.</p>
<p>Not all my data lives on that one server though. I also have a storage VPS which runs <a href="https://nextcloud.com/">Nextcloud</a> and <a href="https://hedgedoc.org/">Hedgedoc</a>. Both of those services combined have less than 100 GB of data, but just like the homelab, that data is precious. The storage VPS has a total capacity of 1.5 TB.</p>
<p>The <a href="https://www.backblaze.com/blog/the-3-2-1-backup-strategy/">3-2-1 backup strategy</a> coined by Peter Krogh suggests that we should have three copies of our data, stored on two different media, and with one being off-site.</p>
<p>Both of my servers have enough storage capacity to hold a copy of all of my data. For my third copy, I decided to rely on <a href="https://www.backblaze.com/cloud-storage">Backblaze b2</a>. This is a S3 object storage service that charges low rates for what I store and the number of transactions I make.</p>
<p>My homelab sits in my house, the storage VPS sits in Montreal, and Backblaze stores my data in Phoenix. Therefore, I have <strong>3</strong> copies of my data and it&rsquo;s stored in more than <strong>1</strong> location.</p>
<p>In order to address having at least <strong>2</strong> different storage media, I backup my data using two different approaches: Restic and Btrfs Snapshots. I don&rsquo;t currently have enough data such that hot online storage is cost-prohibitive.</p>
<h3 id="restic">Restic</h3>
<p><a href="https://restic.net/">Restic</a> is a modern and open-source backup software that both deduplicates and encrypts file contents at the blob level. In combination with a metadata local cache, this makes this Restic snappy and efficient to use.</p>
<p>It supports a variety of backup targets:</p>
<ul>
<li>Local filesystem</li>
<li>SFTP</li>
<li>REST server</li>
<li>S3</li>
<li>and <a href="https://restic.readthedocs.io/en/latest/030_preparing_a_new_repo.html#">several others</a>, including those implemented by <a href="https://rclone.org/">Rclone</a>!</li>
</ul>
<p>While I could use the variety of backup targets to increase the number of approaches my data is backed up, to me, this does not feel sufficiently different enough to warrent the additional complexity. Therefore, I&rsquo;ll use one backup target for all three locations.</p>
<p>Since Backblaze b2 only supports the S3 protocol, this means then that my choice has been made for me. However even if it wasn&rsquo;t forced upon me, I would still pick that option. Designed by Amazon for their storage service, the S3 protocol is built with scale in mind and supports concurrent multipart file uploads. Additionally unlike SFTP, S3 separates its accounts from that of the server. There are ways to restrict SSH clients, however, it is not the default behavior. In S3, by default a user cannot do anything.</p>
<p>Thus, after choosing S3, I need to set up a S3 server on both my storage VPS and my homelab. I landed on MinIO for its ease of setup and longevity, however, any of the other solutions would work as well.</p>
<p>Since, we&rsquo;re storing copies of the data on all the servers, one idea is to set it up in a cluster configuration. However, since I&rsquo;m not managing the S3 server hosted by Backblaze, I wouldn&rsquo;t be able to include that in the cluster. Generally, it is not recommended to run a cluster with only two nodes. If we do, it can lead to what&rsquo;s called a <a href="https://en.wikipedia.org/wiki/Split-brain_(computing)"><em>split brain problem</em></a> where both nodes are unable to communicate with each other and think that they are the leader node.</p>
<p>To avoid this, we can run both MinIO instances inpendently and have Restic separately send the data to all servers.</p>
<h4 id="minio-setup">MinIO Setup</h4>
<p>If you already have a bucket setup and configured with the appropriate permissions, then feel free to skip this section.</p>
<p>The following code examples assume that <a href="https://min.io/docs/minio/container/index.html">MinIO is installed</a> and the <code>mc</code> client is available with the root credentials to each server (alias) set. These general steps can also be achieved using the management UI. For simplicity, I&rsquo;ll show how to do this with respect to one server <code>homelab</code>. However, we&rsquo;ll need to do this for every MinIO instance.</p>
<p>First, <a href="https://min.io/docs/minio/linux/reference/minio-mc/mc-mb.html">create a bucket</a> which will hold our backup data.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># alias_of_server/bucket_name</span>
</span></span><span style="display:flex;"><span>mc mb homelab/backups
</span></span></code></pre></div><p>Afterwards, create a <a href="https://min.io/docs/minio/linux/administration/identity-access-management/minio-user-management.html">backup user</a>. We&rsquo;ll need to specify the <code>ACCESS_KEY</code> and <code>SECRET_KEY</code> which corresponds to the username and password respectively. Store these as we&rsquo;ll later need to use them.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>export ACCESS_KEY<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;my_awesome_homelab_user&#34;</span>
</span></span><span style="display:flex;"><span>export SECRET_KEY<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;SUPER_SECURE_SECRET_KEY&#34;</span>
</span></span><span style="display:flex;"><span>mc admin user add homelab $ACCESSKEY $SECRETKEY
</span></span></code></pre></div><p><em>Note:</em> For a bit more security, I like to create a different access key and secret key for the other servers.</p>
<p>By default, our user cannot cannot do anything. Let&rsquo;s make it so that they have access to our <code>backups</code> bucket we created earlier. To do that, we&rsquo;ll need to create a <a href="https://min.io/docs/minio/linux/administration/identity-access-management/policy-based-access-control.html">policy</a> which allows the user to perform operations on that bucket.</p>
<p>We&rsquo;ll have to create a JSON file and follow the AWS IAM format.</p>
<pre tabindex="0"><code class="language-iam" data-lang="iam">{
 &#34;Version&#34;: &#34;2012-10-17&#34;,
 &#34;Statement&#34;: [
  {
   &#34;Effect&#34;: &#34;Allow&#34;,
   &#34;Action&#34;: [
    &#34;s3:ListBucket&#34;,
    &#34;s3:PutObject&#34;,
    &#34;s3:DeleteObject&#34;,
    &#34;s3:GetObject&#34;
   ],
   &#34;Resource&#34;: [
    &#34;arn:aws:s3:::backups/*&#34;,
    &#34;arn:aws:s3:::backups&#34;
   ]
  }
 ]
}
</code></pre><p>Assume that we saved the prior JSON at a location specified by the environmental variable <code>$POLICY_PATH</code>, then we can create the policy through the following:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>export POLICY_NAME<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;backup-policy&#34;</span>
</span></span><span style="display:flex;"><span>mc admin policy create homelab $POLICY_NAME $POLICY_PATH
</span></span></code></pre></div><p>After creating the policy, we need to assign it to our backup user.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>mc admin policy attach homelab $POLICY_NAME --user $ACCESS_KEY
</span></span></code></pre></div><h4 id="nginx-and-initializing-restic">Nginx and Initializing Restic</h4>
<p>With our bucket and user configured, now let&rsquo;s discuss how we&rsquo;ll perform our backups. Our bucket will have the following directory structure:</p>
<pre tabindex="0"><code>backups/
  homelab/
  vps/
</code></pre><p>Each folder will contain a restic repository. We separate them out instead of having one giant restic repository, so that we don&rsquo;t have to worry about multiple servers competing for a lock.</p>
<p>Instead of communicating over HTTP, we want a secure way to access our buckets from outside the server. For this, I use <a href="https://min.io/docs/minio/linux/integrations/setup-nginx-proxy-with-minio.html">nginx to proxy the traffic over to MinIO</a>. I configure <a href="https://letsencrypt.org/getting-started/">Certbot with LetsEncrypt</a> so that the connection can be secureted with HTTPS/TLS. In addition to the instructions listed on the MinIO page, I also restrict the IPs which are allowed to connect. For example, to only allow traffic from within your Wireguard network (ex subnet: <code>10.10.10.1/24</code>) then you can put the following within the <code>location</code> block of the nginx config.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-nginx" data-lang="nginx"><span style="display:flex;"><span><span style="color:#66d9ef">allow</span> <span style="color:#ae81ff">10</span><span style="color:#e6db74">.10.10.1/24</span>;
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">deny</span> <span style="color:#e6db74">all</span>; <span style="color:#66d9ef">//</span> <span style="color:#e6db74">Denies</span> <span style="color:#e6db74">all</span> <span style="color:#e6db74">other</span> <span style="color:#e6db74">traffic</span>
</span></span></code></pre></div><p>After securing the entryway to our S3 server, we&rsquo;re ready to use Restic. Before jumping in, you might want to <a href="https://restic.readthedocs.io/en/stable/080_examples.html#full-backup-without-root">create a dedicated account</a> so that we don&rsquo;t have to use the <code>root</code>  user.</p>
<p>Let&rsquo;s initialize each server&rsquo;s respective repository. Since our backups will be encrypted, we need to come up with another password and put it within the <code>RESTIC_PASSWORD</code> environmental variable. Save this password in a safe place, since we will not be able to decrypt the backup without it.</p>
<pre tabindex="0"><code>export RESTIC_REPOSITORY=s3:https://&lt;domain-of-s3-server&gt;/backups/homelab
export AWS_ACCESS_KEY_ID=$ACCESS_KEY
export AWS_SECRET_ACCESS_KEY=$SECRET_ACCESS_KEY
export RESTIC_PASSWORD=&#34;RESTIC_SUPER_SECURE_PASSWORD&#34;

restic init
</code></pre><p>From here, create a backup script at <code>/usr/local/bin/backup.sh</code>. This is where we specify which folders to backup.</p>
<p>Example:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e">#!/bin/sh
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span>set -o errexit
</span></span><span style="display:flex;"><span>set -o nounset
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">if</span> <span style="color:#f92672">[</span> <span style="color:#e6db74">&#34;</span>$EUID<span style="color:#e6db74">&#34;</span> -ne <span style="color:#e6db74">&#34;</span><span style="color:#66d9ef">$(</span>id -u restic<span style="color:#66d9ef">)</span><span style="color:#e6db74">&#34;</span> <span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">then</span> echo <span style="color:#e6db74">&#34;Please run as restic&#34;</span>
</span></span><span style="display:flex;"><span>  exit
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">fi</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Usage: rbackup [message] [restic-tag] [backup-dir]</span>
</span></span><span style="display:flex;"><span>rbackup <span style="color:#f92672">()</span> <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>  echo <span style="color:#e6db74">&#34;</span>$1<span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span>  restic backup <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>    --tag <span style="color:#e6db74">&#34;</span>$2<span style="color:#e6db74">&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>    <span style="color:#e6db74">&#34;</span>$3<span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">## BACKUP TO CLOUD</span>
</span></span><span style="display:flex;"><span>export RESTIC_REPOSITORY<span style="color:#f92672">=</span>s3:https://&lt;domain-of-cloud-server&gt;/backups/homelab
</span></span><span style="display:flex;"><span>export AWS_ACCESS_KEY_ID<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;CLOUD_ACCESS_KEY&#34;</span>
</span></span><span style="display:flex;"><span>export AWS_SECRET_ACCESS_KEY<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;CLOUD_SECRET_ACCESS_KEY&#34;</span>
</span></span><span style="display:flex;"><span>export RESTIC_PASSWORD<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;RESTIC_SUPER_SECURE_PASSWORD&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>rbackup <span style="color:#e6db74">&#34;Backing up documents&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>  Documents <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>  /home/user/Documents
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Backup other great directories...</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">## BACKUP TO BACKBLAZE</span>
</span></span><span style="display:flex;"><span>export RESTIC_REPOSITORY<span style="color:#f92672">=</span>s3:https://&lt;domain-of-backblaze-server&gt;/backups/homelab
</span></span><span style="display:flex;"><span>export AWS_ACCESS_KEY_ID<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;BACKBLAZE_ACCESS_KEY&#34;</span>
</span></span><span style="display:flex;"><span>export AWS_SECRET_ACCESS_KEY<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;BACKBLAZE_SECRET_ACCESS_KEY&#34;</span>
</span></span><span style="display:flex;"><span>export RESTIC_PASSWORD<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;RESTIC_SUPER_SECURE_PASSWORD&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>rbackup <span style="color:#e6db74">&#34;Backing up documents&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>  Documents <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>  /home/user/Documents
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Backup other great directories...</span>
</span></span></code></pre></div><p>Unless you have unlimited storage, you probably want to prune old backups according to some schedule. In the same script I have the following function:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>prune <span style="color:#f92672">()</span> <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>  echo <span style="color:#e6db74">&#34;Pruning old snapshots&#34;</span>
</span></span><span style="display:flex;"><span>  restic unlock
</span></span><span style="display:flex;"><span>  restic forget <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>    --group-by <span style="color:#e6db74">&#34;tags&#34;</span> <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>    --keep-daily N_DAYS <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>    --keep-weekly N_WEEKS <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>    --keep-monthly N_MONTHS <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>    --prune
</span></span><span style="display:flex;"><span><span style="color:#f92672">}</span>
</span></span></code></pre></div><p>Replace <code>N_*</code> to your liking. Restic will then ensure that it keeps enough snapshots such that those time-based rules are satisfied.</p>
<p>With the script written, we can then setup a systemd service and timer so that it runs daily. Write the following to <code>/etc/systemd/system/restic-backup.service</code>.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ini" data-lang="ini"><span style="display:flex;"><span><span style="color:#66d9ef">[Unit]</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">Description</span><span style="color:#f92672">=</span><span style="color:#e6db74">Executes backup script</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">Requires</span><span style="color:#f92672">=</span><span style="color:#e6db74">network-online.target</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">Wants</span><span style="color:#f92672">=</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">[Service]</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">User</span><span style="color:#f92672">=</span><span style="color:#e6db74">restic</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">Group</span><span style="color:#f92672">=</span><span style="color:#e6db74">restic</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">Type</span><span style="color:#f92672">=</span><span style="color:#e6db74">oneshot</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">ExecStart</span><span style="color:#f92672">=</span><span style="color:#e6db74">/usr/local/bin/backup.sh</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">Environment</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;HOME=/home/restic&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">[Install]</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">WantedBy</span><span style="color:#f92672">=</span><span style="color:#e6db74">multi-user.target</span>
</span></span></code></pre></div><p>Write the timer to <code>/etc/systemd/system/restic-backup.timer</code></p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ini" data-lang="ini"><span style="display:flex;"><span><span style="color:#66d9ef">[Timer]</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">OnCalendar</span><span style="color:#f92672">=</span><span style="color:#e6db74">daily</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">Persistent</span><span style="color:#f92672">=</span><span style="color:#e6db74">true</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">[Install]</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">WantedBy</span><span style="color:#f92672">=</span><span style="color:#e6db74">timers.target</span>
</span></span></code></pre></div><h3 id="btrfs-snapshots">Btrfs snapshots</h3>
<p>Both my servers run Btrfs as the underlying filesystem. One cool feature is that Btrfs can create <em>snapshots</em>. These are immutable point-in-time views of a given subvolume. As such, we&rsquo;ll need to create a subvolume that will contain the directories we want.</p>
<p>If we&rsquo;re not starting from scratch, and instead want to create a subvolume from an existing folder, then I recommend performing the following steps from <a href="https://www.reddit.com/r/btrfs/comments/198hbod/converting_directory_into_subvolume/">this reddit thread</a>:</p>
<pre tabindex="0"><code>mv folder folder_backup
btrfs subvolume create folder
cp --archive --one-file-system --reflink=always folder_backup/. folder
</code></pre><p>From here, we can create our snapshots. Like with our Restic setup, I like having some daily, weekly, and monthly backups available. I&rsquo;ll store these snapshots in <code>/snapshots</code>, but you&rsquo;re free to change the location. Here&rsquo;s what it looks like on my machine:</p>
<pre tabindex="0"><code>/snapshots/
  daily
    20251201
      /home/user/Documents
      ...
      /home/user/Music
    ...
    20251227
  monthly
    ...
  weekly
    ...
</code></pre><p>Since these are backup snapshots, we want it to be <em>readonly</em>. Here is what it looks like to create a daily snapshot for our documents subvolume:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>SNAPSHOT_PATH<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;/snapshots/daily/</span><span style="color:#66d9ef">$(</span>date +<span style="color:#e6db74">&#39;%Y%m%d&#39;</span><span style="color:#66d9ef">)</span><span style="color:#e6db74">/home/user/Documents&#34;</span>
</span></span><span style="display:flex;"><span>mkdir -p <span style="color:#e6db74">&#34;</span><span style="color:#66d9ef">$(</span>dirname $SNAPSHOT_PATH<span style="color:#66d9ef">)</span><span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span>btrfs subvolume snapshot -r /home/user/Documents <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>SNAPSHOT_PATH<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>
</span></span></code></pre></div><p>We used the date in the folder name so that we can easily detect the oldest snapshots for deletion.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>OLDEST_SNAPSHOT<span style="color:#f92672">=</span><span style="color:#66d9ef">$(</span>ls <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>SNAPSHOT_DIR<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span> | sort | head -n 1<span style="color:#66d9ef">)</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">for</span> SUBVOLUME_PATH in <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>SUBVOLUMES[@]<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">do</span>
</span></span><span style="display:flex;"><span>    SNAPSHOT_PATH<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>SNAPSHOT_DIR<span style="color:#e6db74">}</span><span style="color:#e6db74">/</span><span style="color:#e6db74">${</span>OLDEST_SNAPSHOT<span style="color:#e6db74">}${</span>SUBVOLUME_PATH<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span>    btrfs subvolume delete -c <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>SNAPSHOT_PATH<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>    
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">done</span>
</span></span><span style="display:flex;"><span>rm -rf <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>SNAPSHOT_DIR<span style="color:#e6db74">}</span><span style="color:#e6db74">/</span><span style="color:#e6db74">${</span>OLDEST_SNAPSHOT<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>
</span></span></code></pre></div><p>I put together a script which takes as input the environment variable <code>SNAPSHOT_DIR</code> and handles creating and pruning snapshots. To get these snapshots at different time intervals, we use different systemd timers and change that input variable. Unlike with our restic setup, this will keep the same $N$ number of snapshots for each of our time intervals.  We copy this script to <code>/usr/local/bin/localbtrbak.sh</code>.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e">#!/bin/bash
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span>set -o nounset
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>show_usage<span style="color:#f92672">()</span> <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>    echo <span style="color:#e6db74">&#34;Usage: localbtrback&#34;</span>
</span></span><span style="display:flex;"><span>    exit <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Check argument count</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">if</span> <span style="color:#f92672">[</span> <span style="color:#e6db74">&#34;</span>$#<span style="color:#e6db74">&#34;</span> -ne <span style="color:#ae81ff">0</span> <span style="color:#f92672">]</span>; <span style="color:#66d9ef">then</span>
</span></span><span style="display:flex;"><span>    show_usage
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">fi</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">if</span> <span style="color:#f92672">[</span> <span style="color:#e6db74">&#34;</span>$EUID<span style="color:#e6db74">&#34;</span> -ne <span style="color:#ae81ff">0</span> <span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">then</span> echo <span style="color:#e6db74">&#34;Please run as root&#34;</span>
</span></span><span style="display:flex;"><span>    exit
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">fi</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">if</span> <span style="color:#f92672">[</span> -z <span style="color:#e6db74">&#34;</span>$SNAPSHOT_DIR<span style="color:#e6db74">&#34;</span> <span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">then</span> echo <span style="color:#e6db74">&#34;SNAPSHOT_DIR not defined&#34;</span>
</span></span><span style="display:flex;"><span>    exit
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">fi</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># EDIT TO POINT TO YOUR SUBVOLUMES</span>
</span></span><span style="display:flex;"><span>SUBVOLUMES<span style="color:#f92672">=(</span><span style="color:#e6db74">&#34;/home/user/Documents&#34;</span>  <span style="color:#e6db74">&#34;/home/user/Music&#34;</span><span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">for</span> SUBVOLUME_PATH in <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>SUBVOLUMES[@]<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">do</span>
</span></span><span style="display:flex;"><span>    SNAPSHOT_PATH<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>SNAPSHOT_DIR<span style="color:#e6db74">}</span><span style="color:#e6db74">/</span><span style="color:#66d9ef">$(</span>date +<span style="color:#e6db74">&#39;%Y%m%d&#39;</span><span style="color:#66d9ef">)</span><span style="color:#e6db74">${</span>SUBVOLUME_PATH<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#75715e"># Create folder if not already exists</span>
</span></span><span style="display:flex;"><span>    mkdir -p <span style="color:#e6db74">&#34;</span><span style="color:#66d9ef">$(</span>dirname $SNAPSHOT_PATH<span style="color:#66d9ef">)</span><span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#75715e"># Create the readonly snapshot</span>
</span></span><span style="display:flex;"><span>    btrfs subvolume snapshot -r <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>SUBVOLUME_PATH<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span> <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>SNAPSHOT_PATH<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">done</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Calculate the number of snapshots</span>
</span></span><span style="display:flex;"><span>COUNT<span style="color:#f92672">=</span><span style="color:#66d9ef">$(</span>ls <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>SNAPSHOT_DIR<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span> | wc -l<span style="color:#66d9ef">)</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">if</span> <span style="color:#f92672">[</span> <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>COUNT<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span> -gt <span style="color:#ae81ff">3</span> <span style="color:#f92672">]</span>; <span style="color:#66d9ef">then</span>
</span></span><span style="display:flex;"><span>    OLDEST_SNAPSHOT<span style="color:#f92672">=</span><span style="color:#66d9ef">$(</span>ls <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>SNAPSHOT_DIR<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span> | sort | head -n 1<span style="color:#66d9ef">)</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">for</span> SUBVOLUME_PATH in <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>SUBVOLUMES[@]<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">do</span>
</span></span><span style="display:flex;"><span>        SNAPSHOT_PATH<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>SNAPSHOT_DIR<span style="color:#e6db74">}</span><span style="color:#e6db74">/</span><span style="color:#e6db74">${</span>OLDEST_SNAPSHOT<span style="color:#e6db74">}${</span>SUBVOLUME_PATH<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span>        btrfs subvolume delete -c <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>SNAPSHOT_PATH<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>    
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">done</span>
</span></span><span style="display:flex;"><span>    rm -rf <span style="color:#e6db74">&#34;</span><span style="color:#e6db74">${</span>SNAPSHOT_DIR<span style="color:#e6db74">}</span><span style="color:#e6db74">/</span><span style="color:#e6db74">${</span>OLDEST_SNAPSHOT<span style="color:#e6db74">}</span><span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">fi</span>
</span></span></code></pre></div><p>For our systemd service in <code>/etc/systemd/system/btrlocalback@.service</code></p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ini" data-lang="ini"><span style="display:flex;"><span><span style="color:#66d9ef">[Unit]</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">Description</span><span style="color:#f92672">=</span><span style="color:#e6db74">Create a local BTRFS snapshot</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">[Service]</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">Type</span><span style="color:#f92672">=</span><span style="color:#e6db74">oneshot</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">Environment</span><span style="color:#f92672">=</span><span style="color:#e6db74">SNAPSHOT_DIR=&#34;/snapshots/%i&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">ExecStart</span><span style="color:#f92672">=</span><span style="color:#e6db74">/usr/local/bin/localbtrbak.sh</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">[Install]</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">WantedBy</span><span style="color:#f92672">=</span><span style="color:#e6db74">multi-user.target</span>
</span></span></code></pre></div><p>An example daily timer stored in <code>/etc/systemd/system/btrlocalbak@daily.timer</code></p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ini" data-lang="ini"><span style="display:flex;"><span><span style="color:#66d9ef">[Unit]</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">Description</span><span style="color:#f92672">=</span><span style="color:#e6db74">Create a daily local BTRFS snapshot</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">[Timer]</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">OnCalendar</span><span style="color:#f92672">=</span><span style="color:#e6db74">daily</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">Persistent</span><span style="color:#f92672">=</span><span style="color:#e6db74">true</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">[Install]</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">WantedBy</span><span style="color:#f92672">=</span><span style="color:#e6db74">timers.target</span>
</span></span></code></pre></div><h3 id="conclusion">Conclusion</h3>
<p>Here is a visualization of the three servers and where the data gets backed up to:</p>
<p><img src="/files/images/blog/BackupSetup2025.svg" alt="Diagram of the backup setup I described"></p>
<p>The bucket image in the diagram denotes the S3 storage, while the cylinder database icon denotes the Btrfs snapshots. Pictorially, this also shows us how the 3-2-1 rule is satisfied.</p>
<ul>
<li>Three outgoing arrows on the two servers means that we have three copies of the data</li>
<li>The two icons on each of the servers show that we&rsquo;re backing it up in two different ways</li>
<li>I have more than one off-site backup since all three boxes are in different locations.</li>
</ul>
<p>If I accidentally delete a file, the Btrfs setup is useful since I can quickly access the old version at <code>/snapshots/daily/&lt;yesterday&gt;/path</code>. However, if my entire server goes down, then I can use one of the restic backups in either server to restore.</p>
]]></content:encoded>
  
</item>
  
  <item>
  <title>After 75 Miles of Running</title>
  <link>https://brandonrozek.com/blog/running-75-miles/</link>
  <pubDate>Fri, 26 Dec 2025 09:55:41 -0500</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid>https://brandonrozek.com/blog/running-75-miles/</guid>
  <description><![CDATA[<p>Back in August, I started running regularly and recording my sessions. I recently completed a total of 75 miles of running across all my sessions. In this post, I&rsquo;ll reflect on my journey so far and what I&rsquo;ve learned.</p>
<h2 id="the-beginning">The Beginning</h2>
<p>Over the summer, I lived and worked in Austin, Texas. For the prior months of the year, I&rsquo;ve lived a fairly sedimentary lifestyle. I enjoy these summers where I am forced to walk more places and <a href="/blog/exploring-via-public-transit/">take public transit</a> since I don&rsquo;t have access to a vehicle.</p>]]></description>
  <content:encoded><![CDATA[<p>Back in August, I started running regularly and recording my sessions. I recently completed a total of 75 miles of running across all my sessions. In this post, I&rsquo;ll reflect on my journey so far and what I&rsquo;ve learned.</p>
<h2 id="the-beginning">The Beginning</h2>
<p>Over the summer, I lived and worked in Austin, Texas. For the prior months of the year, I&rsquo;ve lived a fairly sedimentary lifestyle. I enjoy these summers where I am forced to walk more places and <a href="/blog/exploring-via-public-transit/">take public transit</a> since I don&rsquo;t have access to a vehicle.</p>
<p>Two of my coworkers were really into running and one of them even regularly ran a few miles outside in the <a href="/blog/embrace-the-heat/">95+ degree Fahrenheit weather</a>. This didn&rsquo;t immediately convince me to start myself, but it definitely planted the seed. Towards the end of the summer, I asked myself &ldquo;What&rsquo;s stopping me from running?&rdquo; and took this as an opportunity to prove something to myself.</p>
<blockquote>
<p>What do I need to get started?</p></blockquote>
<p>At the beginning, I didn&rsquo;t end up buying anything new. In Austin, I wore some sneakers from <a href="https://www.keenfootwear.com">Keen footwear</a> which I accidentally soaked a few times in sudden downpours. I also wear a Fitbit watch that has heart rate monitoring built in.</p>
<p>When I returned to New York, I ended up buying a <a href="https://www.brooksrunning.com/en_us">Brooks running shoe</a>. Shoes designed for running are usually lighter and have shock absorption. This makes for a more pleasant workout.</p>
<blockquote>
<p>Did you use a training plan?</p></blockquote>
<p>Initially, I used the <a href="https://www.nhs.uk/better-health/get-active/get-running-with-couch-to-5k/couch-to-5k-running-plan/">couch to 5k running plan</a> developed by the UK&rsquo;s National Health Service (NHS). After completing that plan, I charted out my own path, with most of my sessions consisting of 30 minutes of running surrounded by 5 minutes of walking.</p>
<p>When I returned to New York, I saw that my city was hosting a <a href="https://troyturkeytrot.com/">turkey trot</a> on Thanksgiving. That was a perfect amount of time to follow the program and see how things turn out!</p>
<h2 id="training-arc">Training Arc</h2>
<p>With a race in mind, I had to make sure to not skimp on my training. Initially, I had an every other day schedule. Though as I adjusted back to my new schedule, this has become a little chaotic.</p>
<h3 id="running-inside-vs-outside">Running Inside vs Outside</h3>
<p>The transition between summer and fall in New York state is lovely. It makes for a great time to run outside.  However, as the months rolled by it started getting colder and colder. Now that we&rsquo;re in the midst of winter, I&rsquo;ve mostly abandoned running outside.</p>
<p>Some people swear by running outdoors versus using a treadmill. I&rsquo;m fine with either, but there are definitely trade-offs.</p>
<p>With outdoor running there is much more visual stimuli. Instead of staring at a wall, the scenery changes as you move around. This is a huge pro when it comes to staving off boredom; which I find very important for a successful workout. The uneven ground also prevents repetitive strain injuries.</p>
<p>On the other hand, it&rsquo;s very easy to keep pace with a treadmill. Another benefit is that you don&rsquo;t have to plan out a route ahead of time. Though, I find it imperative to have some sort of distraction ready for when I do my treadmill runs. Initially I turned to watching YouTube videos, but I noticed that my posture would then suffer. I find podcasts to be a nice compromise.</p>
<h3 id="run-slowly">Run Slowly</h3>
<p>I&rsquo;m far from an expert in this area, but it&rsquo;s generally recommended to keep your <a href="https://en.wikipedia.org/wiki/Long_slow_distance">heart rate low</a> when you&rsquo;re running. This helps improve your cardiovascular fitness over the long run. An informal test is to see if you can carry a conversation while running.</p>
<p>Formally, it&rsquo;s recommended to stay in &ldquo;Zone 2&rdquo; while running which is about 60-70% of your max heart rate.  We can use the Bruce protocol to find out our max heart rate, or for a much simpler approximation, we can use the Tanaka, Monahan, &amp; Seals (2001) formula.
$$
hr_{max} = 208 - (0.7 * age)
$$
That means for a 30 year old their zone 2 heart rate lies between 112 and 130.</p>
<p>In Zone 2, the body can still supply energy using fat reserves and clear up the lactate before it builds up. It&rsquo;s easy when running to go past this heart rate. The best way I&rsquo;ve found to keeping it in zone 2 is to run <em>really slow</em>. Often much slower than you think you should be running. When I was first starting out, I wasn&rsquo;t going much faster than walking pace.</p>
<h3 id="running-with-others">Running with others</h3>
<p>A friend recently got me to attend the local run club in the city. At first, I was nervous about joining since I thought it would only be full of people who ran their whole life. It turns out that it had people at all different points in the running journey. I joined once a week until it started regularly staying below freezing. I hope to attend again next year.</p>
<p>Either way, running can be a great excuse to get together with others!</p>
<h2 id="the-turkey-trot">The Turkey Trot</h2>
<p>We then arrive at the big day! I showed up around thirty minutes before the event started. To give an idea of the scale, the Troy turkey trot had over 4000 finishers for the 5k.</p>
<p>At the beginning of the race, everyone lined up by flags marking different paces. I timed myself at a nearby track, and my last 5k was 35 minutes. Feeling optimistic, I lined up at the 11 minute flag.</p>
<p><img src="/files/images/blog/ttslpaceflags.jpg" alt="High-up view of my starting position"></p>
<p>Bam! The sound of the gun then went off signaling the start of the race &ndash; except there was no action. Since I was so far back from the start line, it took over 5 minutes before me and the others around me got to shuffling.</p>
<p>Luckily, when it comes to timing there&rsquo;s the gun time and the net time. The net time is the time it takes once you cross the &ldquo;start line&rdquo; to hit the &ldquo;finish line&rdquo;.</p>
<p>With the majority of my running sessions featuring me, myself, and I, running with so many other people gave a huge energy boost. I let the energy get to me, and I didn&rsquo;t end up running a consistent pace at all. I likely ran a little too fast in the beginning, resulting in short walking breaks towards the end. Also I underestimated the energy it would take to weave around other people.</p>
<p>I hit the finish line at <a href="https://www.zippy-reg.com/results/live/athlete/index.php?eid=228&amp;bib=1508">34 minutes and 14 seconds</a>! It&rsquo;s pretty exciting to hit a new personal best during a race.</p>
<p>Focusing on the race, I didn&rsquo;t end up taking too many photos. Instead here&rsquo;s a blurry snapshot from the <a href="https://www.youtube.com/watch?v=fLRtp4DtcB8">finish cam</a> and a selfie of me with my participation medal.</p>
<p><img src="/files/images/blog/ttfc2025.png" alt="Screenshot of me passing the finish line with many others"></p>
<p><img src="/files/images/blog/ttselfie2025.jpg" alt="Selfie of me with the participation medal"></p>
<h2 id="onto-the-future">Onto the future!</h2>
<p>With that milestone completed, now it&rsquo;s time to think about what&rsquo;s next. Do I train for a 10k? A half-marathon? Nothing is set in stone yet, and I&rsquo;m keeping my eye out for future events.</p>
<p>I mentioned that one of my challenges with running is starving off boredom. While the race does inject a new form of energy, I still currently can&rsquo;t see running for multiple hours!</p>
<p>Beyond running itself, I find it fun to look at my logs. For example, we can take the times from the Troy turkey trot, and plot my performance on the histogram of all participant net times.</p>
<p><img src="/files/images/blog/tthistnettime2025.png" alt="Histogram of net times for all the participants"></p>
<p>Additionally, from my overall training log, I can see that I run on average 2.5 miles during my 30 minute runs.  I&rsquo;m excited to see how these metrics improve over time.</p>
]]></content:encoded>
  
</item>
  
  <item>
  <title>Disabling Nat Source Port Randomization on OPNsense for Gaming</title>
  <link>https://brandonrozek.com/blog/disabling-nat-source-port-randomization-opnsense/</link>
  <pubDate>Tue, 23 Dec 2025 11:16:02 -0500</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid>https://brandonrozek.com/blog/disabling-nat-source-port-randomization-opnsense/</guid>
  <description><![CDATA[<blockquote>
<p>Let&rsquo;s play Mario Party tonight!</p></blockquote>
<p>After many years of friendship, I&rsquo;ve learned that playing online multiplayer games is almost never as simple as it seems. This night was no different.  In this post, I&rsquo;ll go over what I learned setting up my Nintendo Switch for online play. Luckily, this same concept applies to the PlayStation 5 as well<sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup>.</p>
<p>But first, I&rsquo;ll take a detour into how peer-to-peer (P2P) gaming typically works. So, feel free to <a href="#the-solution">skip</a> down to the solution.</p>]]></description>
  <content:encoded><![CDATA[<blockquote>
<p>Let&rsquo;s play Mario Party tonight!</p></blockquote>
<p>After many years of friendship, I&rsquo;ve learned that playing online multiplayer games is almost never as simple as it seems. This night was no different.  In this post, I&rsquo;ll go over what I learned setting up my Nintendo Switch for online play. Luckily, this same concept applies to the PlayStation 5 as well<sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup>.</p>
<p>But first, I&rsquo;ll take a detour into how peer-to-peer (P2P) gaming typically works. So, feel free to <a href="#the-solution">skip</a> down to the solution.</p>
<h2 id="peer-to-peer-gaming">Peer-to-Peer Gaming</h2>
<p>Mario Party is a board game where you move characters around in hopes of collecting the most stars. You play as a character from the Mario franchise, and between each turn on the board is a minigame. These minigames provide the illusion that this is a skill-based game. But trust me, you can win by just tapping A.</p>
<p>Sony and Nintendo both aren&rsquo;t forthcoming with information about how their games and systems work. Therefore, I&rsquo;ll be making a number of assumptions here.</p>
<p>Nintendo owns Mario Party, and from there we can presume that they use the standard Nintendo libraries when building the game. The homebrew community over the years reverse-engineered many of these libraries and due to this we can look at the protocols they use. The Nintendo networking library, called <a href="https://github.com/kinnay/NintendoClients/wiki/Pia-Overview">Pia</a>, uses a service called NEX to match players in games. This match-making protocol includes a <a href="https://en.wikipedia.org/wiki/UDP_hole_punching">network-address-translation (nat) traversal protocol</a>.</p>
<p>For sake of simplicity, I won&rsquo;t describe the protocol in full-depth. What&rsquo;s important to know is that when both players message the server, the server knows each player&rsquo;s IP address and the source port that they used to communicate. The server will then share the other console&rsquo;s information to facilitate that direct peer-to-peer connection</p>
<p>Unfortunately, I was not able to find either official or unofficial documentation on how P2P gaming works on the PlayStation 5. From browsing around, I have the impression that this is less standardized and developers are either relying on external SDKs or developing their own libraries.</p>
<h2 id="the-problem">The Problem</h2>
<p>Opnsense, in all their great wisdom, wants to protect me from <a href="https://en.wikipedia.org/wiki/TCP_sequence_prediction_attack">TCP hijacking</a> and spoofing attacks. Therefore, by default during nat my source port is randomized.</p>
<p>Now the game consoles will not tell us directly that this is the issue. Instead it will provide a &ldquo;score&rdquo; which is supposed to establish a rough sense of how easy it will be to establish a P2P connection.</p>
<p>Nintendo Switch: Settings -&gt; Internet -&gt; Test Connection</p>
<p>PS5: Settings -&gt; Network -&gt; Test Internet Connection</p>
<p>Before applying any changes, on the switch I had a &ldquo;D&rdquo; score on on the PS5 it was &ldquo;Type 3&rdquo;. I wish I can tell you what these scores mean, but the documentation is lacking to say the least&hellip;</p>
<p>However, I was finally able to determine that nat source port randomization was the problem after stumbling upon this <a href="https://www.reddit.com/r/OPNsenseFirewall/comments/g3sx2l/tip_opnsense_and_nintendo_switch_nat_rules/">Reddit thread</a> &ndash; which now takes us to the solution:</p>
<h2 id="the-solution">The Solution</h2>
<p>We need to tell our router that our gaming devices are special, and therefore does not need the additional security measure of randomizing the source port during nat. That way when the game is establishing a P2P connection, the ports aren&rsquo;t randomized and the connection can proceed smoothly.</p>
<p>On Opnsense, we can change this setting by navigating to Firewall -&gt; NAT -&gt; Outbound.</p>
<p>Now I do want this security measure to be applied to the rest of my devices. Therefore, we&rsquo;ll be setting the mode to &ldquo;Hybrid outbound NAT rule generation&rdquo;  which allows us to specify the custom rules.</p>
<p>From there, we can add a manual rule for each game console with the following:</p>
<ul>
<li>Interface: WAN</li>
<li>TCP/IP Version: IPv4</li>
<li>Protocol: UDP</li>
<li>Source Address: Single host or network
<ul>
<li>Insert Switch/PS5 address</li>
<li>Replace netmask with 32</li>
</ul>
</li>
<li>Source Port: any</li>
<li>Destination Address: any</li>
<li>Destination Port: Any</li>
<li>Static Port: <strong>Checked</strong></li>
</ul>
<p>The last option is what tells Opnsense to not randomize the source port.</p>
<p>From there, we can save, apply our settings, and rerun our connection tests. With this change, my Switch reports a NAT type of B and PS5 reports Type 2. Good enough for online gaming :)</p>
<div class="footnotes" role="doc-endnotes">
<hr>
<ol>
<li id="fn:1">
<p>Sorry Xbox folks, I do not own one so I cannot tell you if this technique works for that platform as well.&#160;<a href="#fnref:1" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
</ol>
</div>
]]></content:encoded>
  <category>Networking</category>
  
</item>
  
  <item>
  <title>Fedora CoreOS: First Impressions</title>
  <link>https://brandonrozek.com/blog/fedora-coreos-first-impressions/</link>
  <pubDate>Fri, 28 Nov 2025 10:47:11 -0500</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid>https://brandonrozek.com/blog/fedora-coreos-first-impressions/</guid>
  <description><![CDATA[<p>I have a VPS whose contract ends in December. Instead of renewing, I decided to switch providers of that VPS to OVHCloud. The latter&rsquo;s commitment to <a href="https://corporate.ovhcloud.com/en/sustainability/environment/">sustainability</a> through renewables and component reuse is super cool. Now, I could&rsquo;ve kept the migration simple and keep the configuration the same. I don&rsquo;t write about it much here, but I have <a href="https://www.redhat.com/en/ansible-collaborative">Ansible</a> playbooks for all my servers. However, <a href="https://www.zdnet.com/article/what-is-immutable-linux-heres-why-youd-run-an-immutable-linux-distro/">immutable Linux distributions</a> have been receiving a lot of attention over the past few years and tragically I knew little about them.</p>]]></description>
  <content:encoded><![CDATA[<p>I have a VPS whose contract ends in December. Instead of renewing, I decided to switch providers of that VPS to OVHCloud. The latter&rsquo;s commitment to <a href="https://corporate.ovhcloud.com/en/sustainability/environment/">sustainability</a> through renewables and component reuse is super cool. Now, I could&rsquo;ve kept the migration simple and keep the configuration the same. I don&rsquo;t write about it much here, but I have <a href="https://www.redhat.com/en/ansible-collaborative">Ansible</a> playbooks for all my servers. However, <a href="https://www.zdnet.com/article/what-is-immutable-linux-heres-why-youd-run-an-immutable-linux-distro/">immutable Linux distributions</a> have been receiving a lot of attention over the past few years and tragically I knew little about them.</p>
<p><strong>What is an immutable Linux distribution?</strong> It is a Linux distribution with a read-only core. This prevents accidental modifications which overtime lead to an unstable system.</p>
<p>There are <a href="https://nixos.org/">many</a> <a href="https://ubuntu.com/core">different</a> <a href="https://microos.opensuse.org/">options</a> for these immutable distributions, but as you can see from the title of this post, I went with <a href="https://www.fedoraproject.org/coreos/">Fedora CoreOS</a>. The reason is simple. All my other servers run Fedora Server, so hopefully the changes I need to make to my playbooks are minimal.</p>
<p>At the time of writing, Fedore CoreOS uses <a href="https://ostreedev.github.io/ostree/introduction/">OSTree</a> to perform upgrades over the entire filesystem. These upgrades are <em>atomic</em> which suggests that we are not updating individual packages but the entire Linux distribution as a whole. Apart from the read-only core, there are two writable directories <code>/etc</code> and <code>/var</code>. In fact, your home directory lives in <code>/var/home</code>.</p>
<h2 id="initial-installation">Initial Installation</h2>
<p>OVHCloud does not have a way to upload an ISO and boot directly from there. Instead, we&rsquo;ll have to use their rescue mode feature. Luckily, Timothée wrote up a <a href="https://tim.siosm.fr/blog/2025/09/14/fedora-coreos-ovhcloud-vps/">great guide</a> on how to get started. If this doesn&rsquo;t exactly match your situation, the <a href="https://docs.fedoraproject.org/en-US/fedora-coreos/getting-started/">official documentation</a> has over 20 different provisioning guides.</p>
<p>When I was following the documentation, one of the parts I got tripped up on was how much configuration to put in my Butane file. As noted above, I already have Ansible setup to copy over various files I need. Then I saw that <em>ignition runs only once during the first boot of the system</em>. Hence, if we wanted to customize our storage partitions or lay out networking, then this is a good place to do this. Otherwise, if we want to setup <code>systemd</code> services and the like, we can always add those via Ansible later.</p>
<p>In other words, if you&rsquo;re fine with the defaults and there&rsquo;s a DHCP server running on your network, then the  <em>base Butane config outlined in the documentation is sufficient</em>.</p>
<p>Here&rsquo;s an example configuration we can write to <code>config.bu</code>:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#f92672">variant</span>: <span style="color:#ae81ff">fcos</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">version</span>: <span style="color:#ae81ff">1.6.0</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">passwd</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">users</span>:
</span></span><span style="display:flex;"><span>    - <span style="color:#f92672">name</span>: <span style="color:#ae81ff">core</span>
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">ssh_authorized_keys</span>:
</span></span><span style="display:flex;"><span>        - <span style="color:#ae81ff">ssh-rsa AAAA...</span>
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">groups</span>:
</span></span><span style="display:flex;"><span>        - <span style="color:#ae81ff">wheel</span>
</span></span></code></pre></div><p>Where you replace the <code>ssh-rsa</code> line with your own SSH public key file.</p>
<p>The <code>wheel</code> group allows that user to run commands with <code>sudo</code>, if you don&rsquo;t want that then you can remove that line. If you want to add a password, you&rsquo;ll need to generate a password hash using the following command:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>podman run -ti --rm quay.io/coreos/mkpasswd --method<span style="color:#f92672">=</span>yescrypt
</span></span></code></pre></div><p>It&rsquo;ll return some string <code>$y...</code></p>
<p>Then, we can add it to our config:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#75715e"># ...</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">users</span>:
</span></span><span style="display:flex;"><span>  - <span style="color:#f92672">name</span>: <span style="color:#ae81ff">core</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">password_hash</span>: <span style="color:#ae81ff">$y..</span>
</span></span><span style="display:flex;"><span>    <span style="color:#75715e"># ...</span>
</span></span></code></pre></div><p>After that, in order to get the ignition file, we can run the following command:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>podman run --interactive --rm quay.io/coreos/butane:release --pretty --strict &lt; config.bu &gt; config.ign
</span></span></code></pre></div><h2 id="running-software">Running Software</h2>
<p>For the most part, using OSTree to install additional packages is <a href="https://docs.fedoraproject.org/en-US/fedora-coreos/faq/#_how_do_i_run_custom_applications_on_fedora_coreos">highly discouraged</a>. Instead, it&rsquo;s suggested to install and run things through <a href="https://docs.fedoraproject.org/en-US/fedora-coreos/running-containers/">containers</a>. The official documentation shows how to set up containers via the Butane configuration above, however, I kept my file as simple as shown above.  Instead since <code>/etc/containers/systemd</code> is writable, I wrote <a href="https://brandonrozek.com/blog/migrating-docker-compose-podman-quadlets/">Podman Quadlet files</a> directly (<a href="https://docs.podman.io/en/latest/markdown/podman-systemd.unit.5.html">Official Quadlet Documentation</a>).</p>
<p>For example, here is my Wireguard Quadlet file</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ini" data-lang="ini"><span style="display:flex;"><span><span style="color:#66d9ef">[Unit]</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">Description</span><span style="color:#f92672">=</span><span style="color:#e6db74">WireGuard VPN Container</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">After</span><span style="color:#f92672">=</span><span style="color:#e6db74">network-online.target</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">Wants</span><span style="color:#f92672">=</span><span style="color:#e6db74">network-online.target</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">[Container]</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">Image</span><span style="color:#f92672">=</span><span style="color:#e6db74">docker.io/linuxserver/wireguard:latest</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">ContainerName</span><span style="color:#f92672">=</span><span style="color:#e6db74">wireguard</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Give the container the ability to add network interfaces</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">AddCapability</span><span style="color:#f92672">=</span><span style="color:#e6db74">NET_ADMIN</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Have the wireguard network accessible on the host</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">Network</span><span style="color:#f92672">=</span><span style="color:#e6db74">host</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Mount the WireGuard configuration directory</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">Volume</span><span style="color:#f92672">=</span><span style="color:#e6db74">/etc/wireguard:/config/wg_confs:Z</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">[Service]</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">Restart</span><span style="color:#f92672">=</span><span style="color:#e6db74">always</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">TimeoutStartSec</span><span style="color:#f92672">=</span><span style="color:#e6db74">900</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">[Install]</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">WantedBy</span><span style="color:#f92672">=</span><span style="color:#e6db74">multi-user.target default.target</span>
</span></span></code></pre></div><p>The following are my Ansible tasks which copy that file over to the machine.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span>- <span style="color:#f92672">name</span>: <span style="color:#ae81ff">Create /etc/wireguard directory</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">become</span>: <span style="color:#66d9ef">true</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">ansible.builtin.file</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">path</span>: <span style="color:#ae81ff">/etc/wireguard</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">state</span>: <span style="color:#ae81ff">directory</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">mode</span>: <span style="color:#e6db74">&#39;0700&#39;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">owner</span>: <span style="color:#ae81ff">root</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">group</span>: <span style="color:#ae81ff">root</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>- <span style="color:#f92672">name</span>: <span style="color:#ae81ff">Copy Quadlet container file</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">become</span>: <span style="color:#66d9ef">true</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">ansible.builtin.copy</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">src</span>: <span style="color:#ae81ff">etc/containers/systemd/wireguard.container</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">dest</span>: <span style="color:#ae81ff">/etc/containers/systemd/wireguard.container</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">mode</span>: <span style="color:#e6db74">&#39;0644&#39;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">owner</span>: <span style="color:#ae81ff">root</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">group</span>: <span style="color:#ae81ff">root</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">register</span>: <span style="color:#ae81ff">wireguardcontainer</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>- <span style="color:#f92672">name</span>: <span style="color:#ae81ff">Reload systemd daemon to pick up Quadlet</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">become</span>: <span style="color:#66d9ef">true</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">ansible.builtin.systemd</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">daemon_reload</span>: <span style="color:#66d9ef">yes</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">when</span>: <span style="color:#ae81ff">wireguardcontainer.changed</span>
</span></span></code></pre></div><p>Now not everything deserves a spot in <code>/etc/containers/systemd</code>. Take <code>fastfetch</code> for example.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-txt" data-lang="txt"><span style="display:flex;"><span>             .&#39;,;::::;,&#39;.                 core@toolbx
</span></span><span style="display:flex;"><span>         .&#39;;:cccccccccccc:;,.             ------------
</span></span><span style="display:flex;"><span>      .;cccccccccccccccccccccc;.          OS: Fedora Linux 43 (Toolbx Container Image) x86_64
</span></span><span style="display:flex;"><span>    .:cccccccccccccccccccccccccc:.        Host: OpenStack Nova (19.3.2)
</span></span><span style="display:flex;"><span>  .;ccccccccccccc;.:dddl:.;ccccccc;.      Kernel: Linux 6.17.1-300.fc43.x86_64
</span></span><span style="display:flex;"><span> .:ccccccccccccc;OWMKOOXMWd;ccccccc:.     Uptime: 22 hours, 16 mins
</span></span><span style="display:flex;"><span>.:ccccccccccccc;KMMc;cc;xMMc;ccccccc:.    Packages: 366 (rpm)
</span></span><span style="display:flex;"><span>,cccccccccccccc;MMM.;cc;;WW:;cccccccc,    Shell: bash 5.3.0
</span></span><span style="display:flex;"><span>:cccccccccccccc;MMM.;cccccccccccccccc:    Terminal: conmon
</span></span><span style="display:flex;"><span>:ccccccc;oxOOOo;MMM000k.;cccccccccccc:    CPU: 6 x Intel Core (Haswell, no TSX) (6) @ 2.99 GHz
</span></span><span style="display:flex;"><span>cccccc;0MMKxdd:;MMMkddc.;cccccccccccc;    GPU: Cirrus Logic GD 5446
</span></span><span style="display:flex;"><span>ccccc;XMO&#39;;cccc;MMM.;cccccccccccccccc&#39;    Memory: 920.56 MiB / 11.39 GiB (8%)
</span></span><span style="display:flex;"><span>ccccc;MMo;ccccc;MMW.;ccccccccccccccc;     Swap: Disabled
</span></span><span style="display:flex;"><span>ccccc;0MNc.ccc.xMMd;ccccccccccccccc;      Disk (/): 11.53 GiB / 99.44 GiB (12%) - overlay
</span></span><span style="display:flex;"><span>cccccc;dNMWXXXWM0:;cccccccccccccc:,       Disk (/run/host/boot): 277.41 MiB / 349.87 MiB (79%) - ext4 [Read-only]
</span></span><span style="display:flex;"><span>cccccccc;.:odl:.;cccccccccccccc:,.        Disk (/run/host/etc): 11.53 GiB / 99.44 GiB (12%) - xfs
</span></span><span style="display:flex;"><span>ccccccccccccccccccccccccccccc:&#39;.          
</span></span><span style="display:flex;"><span>:ccccccccccccccccccccccc:;,..             
</span></span><span style="display:flex;"><span> &#39;:cccccccccccccccc::;,.
</span></span></code></pre></div><p>All it does it displays system information. Now this is a very important task when showing off your system on Reddit, but it&rsquo;s more of a <em>system administration</em> tool than a software service that your server provides. For these types of tools, we can use <code>toolbox</code>.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>toolbox create <span style="color:#75715e"># Run this once</span>
</span></span><span style="display:flex;"><span>toolbox enter
</span></span></code></pre></div><p>This will give us a new prompt:</p>
<pre tabindex="0"><code>⬢ [core@toolbx ~]$
</code></pre><p>From here, we can use <code>dnf</code> and treat it similarly as a mutable Fedora server machine.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>sudo dnf install fastfetch
</span></span></code></pre></div><p>Now you&rsquo;ll notice that by default it mounts your home directory but the <code>/etc</code> and <code>/var</code> directories are those of the container. We can find all the files in the host system by accessing <code>/run/host</code>.</p>
<p>I use this when trying to view my Nginx logs:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>goaccess /run/host/var/log/nginx/access.log
</span></span></code></pre></div><h2 id="system-security">System Security</h2>
<p>A huge benefit to running all your services via Quadlets is that Podman is able to automatically set the SELinux contexts and configure your firewall rules for you. This means that we don&rsquo;t have to manually change the SELinux context of every file with <code>chcon</code>. If you&rsquo;re lazy, this means hopefully we don&rsquo;t have to disable SELinux!</p>
<p><strong>SELinux:</strong> Notice in my Wireguard Quadlet file I had the following</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ini" data-lang="ini"><span style="display:flex;"><span><span style="color:#a6e22e">Volume</span><span style="color:#f92672">=</span><span style="color:#e6db74">/etc/wireguard:/config/wg_confs:Z</span>
</span></span></code></pre></div><p>The part after <code>wg_confs:</code> is an optional comma-separated list of options. Here are some that I found to be particularly relevant:</p>
<table>
  <thead>
      <tr>
          <th>Option</th>
          <th>Description</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><code>Z</code></td>
          <td>Label the content with a private unshared SELinux label.</td>
      </tr>
      <tr>
          <td><code>z</code></td>
          <td>Label the content with a shared SELinux content label so that two or more containers can access it.</td>
      </tr>
      <tr>
          <td><code>U</code></td>
          <td>Recursively change the owner and group of the source volume based on the UID and GID of the container</td>
      </tr>
      <tr>
          <td><code>ro</code></td>
          <td>The container can only read, not write to the volume</td>
      </tr>
  </tbody>
</table>
<p><strong>NFTables:</strong> My other Fedora server systems use <code>firewalld</code> as the primary way I interface with the firewall. Instead of using a CLI tool, the idea is that we edit <code>/etc/sysconfig/nftables.conf</code> with the rules we want. I&rsquo;m still getting used writing my firewall config this way, but I do like how it&rsquo;s all easily viewable in one place.</p>
<p>Here&rsquo;s a version of what I have:</p>
<pre tabindex="0"><code class="language-nftables" data-lang="nftables">#!/usr/sbin/nft -f

# Define the main table
table inet filter {
    
    # Data structure we&#39;ll use to keep track of rate-limiting
    set ssh_ratelimit {
        type ipv4_addr
        size 65536
        flags dynamic,timeout
        timeout 30s
    }

    chain input {
        type filter hook input priority filter; policy drop;

        # Allow loopback
        iif lo accept

        # Allow established/related connections
        ct state established,related accept

        # Allow ICMP (ping, etc)
        ip protocol icmp accept
        ip6 nexthdr icmpv6 accept

        # SSH with rate limiting
        tcp dport 22 ct state new limit rate over 12/minute burst 6 packets drop
        tcp dport 22 accept

        # Allow HTTP and HTTPS
        tcp dport { 80, 443 } accept

        # Drop everything else
        drop
    }

    chain forward {
        type filter hook forward priority filter; policy drop;
        
        # Allow established/related connections
        ct state established,related accept
    }

    chain output {
    	# Allow outgoing connections
        type filter hook output priority filter; policy accept;
    }
}
</code></pre><p>I won&rsquo;t go into detail how NFTables works here. Notice though how we don&rsquo;t specify anything about the Podman network. As I said before, Podman will automatically handle that for us.</p>
<p>However, what Podman won&rsquo;t automatically handle is if we try to change our NFTables configuration without a reboot. This is because reloading NFTables will <em>wipe the existing configuration</em>. As such, we need to manually invoke Podman to regenerate the rules.</p>
<p>Luckily, we can override the NFTables systemd service so that it happens automatically. Create the file <code>/etc/systemd/system/nftables.service.d/override.conf</code> with the following:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ini" data-lang="ini"><span style="display:flex;"><span><span style="color:#66d9ef">[Service]</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">ExecStartPost</span><span style="color:#f92672">=</span><span style="color:#e6db74">podman network reload --all</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">ExecReload</span><span style="color:#f92672">=</span><span style="color:#e6db74">podman network reload --all</span>
</span></span></code></pre></div><h2 id="conclusion">Conclusion</h2>
<p>That wraps up the bits and pieces I had to learn while I was setting my machine up. From there, I&rsquo;ve been running my CoreOS machine for a month and have not yet had any issues. It&rsquo;s too early for me to make any grand claims, but it <em>feels</em> incredibly reliable.</p>
<p>By default, updates are automatic. Since these are atomic, it means that the machine reboots regularly to apply these updates. This encourages us to setup everything to survive reboots and not require any manual intervention. Also, boot times are quick with it clocking under 12 seconds for my VPS.</p>
<p>Running everything in containers provides isolation between these services and the host. This is useful of course for security, but also allows everything to update on their own cadence and not conflict.</p>
<p>Overall, using an immutable distribution is different than traditional Linux server management. However hopefully with this setup, it incentivizes us to create less fragile systems. A community of maintainers will keep the stable read-only core in a great state, and if things go wrong, we can copy our container volumes to another machine.</p>
<p>So if you haven&rsquo;t already, I recommend giving Fedora CoreOS a shot. Next, I have to take a look at how it&rsquo;s like using an immutable distribution on a desktop.</p>
]]></content:encoded>
  <category>Fedora CoreOS</category>
  <category>Podman</category>
  <category>SELinux</category>
  <category>nftables</category>
  
</item>
  
  <item>
  <title>Flattening Cases to Avoid Nesting in Lean 4</title>
  <link>https://brandonrozek.com/blog/flattening-cases-avoid-nesting-lean-4/</link>
  <pubDate>Sun, 05 Oct 2025 19:38:20 -0400</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid>https://brandonrozek.com/blog/flattening-cases-avoid-nesting-lean-4/</guid>
  <description><![CDATA[<p>Nested cases in proofs increase cognitive load for the reader since they have to process not only the case recently stated but also all the case splits prior. That&rsquo;s why if I can, I prefer to flatten out my cases so that we can see in one step all the variables we&rsquo;re segmenting.</p>
<p>I came across this recently in Lean when working on Lattice proofs over integers with $\infty$ and $-\infty$  In Lean, we can define this &ldquo;extended integer&rdquo; (<code>EInt</code>) by using <code>WithTop</code> and <code>WithBot</code></p>]]></description>
  <content:encoded><![CDATA[<p>Nested cases in proofs increase cognitive load for the reader since they have to process not only the case recently stated but also all the case splits prior. That&rsquo;s why if I can, I prefer to flatten out my cases so that we can see in one step all the variables we&rsquo;re segmenting.</p>
<p>I came across this recently in Lean when working on Lattice proofs over integers with $\infty$ and $-\infty$  In Lean, we can define this &ldquo;extended integer&rdquo; (<code>EInt</code>) by using <code>WithTop</code> and <code>WithBot</code></p>
<pre tabindex="0"><code class="language-lean4" data-lang="lean4">import Mathlib.Order.Interval.Basic

-- An Integer with a top (∞) and bottom (-∞) element
def EInt : Type := WithBot (WithTop Int)
deriving LinearOrder

@[simp] def EInt.ninf : EInt := (⊥ : WithBot (WithTop Int))
@[simp] def EInt.inf : EInt := (WithBot.some ⊤ : WithBot (WithTop Int))

notation &#34;-∞&#34; =&gt; EInt.ninf
notation &#34;∞&#34; =&gt; EInt.inf

-- Helper instances so I can later write numbers and have them casted
instance: IntCast EInt where
  intCast n := WithBot.some (WithTop.some n)

instance: OfNat EInt n where
  ofNat := some (some (Int.ofNat n))
</code></pre><p>Unfortunately, using <code>WithBot</code> and <code>WithTop</code> is just weird. Look at how we would define functions and write proofs using them.</p>
<pre tabindex="0"><code class="language-lean4" data-lang="lean4">def EIntFun : EInt → ℤ
  | none =&gt; 0
  | some ⊤ =&gt; 0
  | some (some _) =&gt; 0

lemma EIntFunIsZero (e: EInt) : EIntFun e = 0 := by
  cases e
  case none =&gt;
    rfl
  case some e =&gt;
    cases e
    case top =&gt;
      rfl
    case coe e =&gt;
      rfl
</code></pre><p>What&rsquo;s more intuitive is to break it up based on whether it&rsquo;s $-\infty$, $\infty$ or some integer $z$. Luckily, we&rsquo;re able to define our own way of splitting up cases in Lean.</p>
<pre tabindex="0"><code class="language-lean4" data-lang="lean4">def EInt.casesOn.{u} {motive : EInt -&gt; Sort u} (a : EInt)
  (ninf : motive -∞)
  (int : ∀ n : Int, motive ↑n)
  (pinf : motive ∞) :
motive a := by
  cases a
  case none =&gt;
    exact ninf
  case some v =&gt;
    cases v
    case top =&gt;
      exact pinf
    case coe n =&gt;
      exact int n
</code></pre><p>When we&rsquo;re doing a proof by cases, we&rsquo;re trying to prove some <code>motive a</code>. What the above definition says, is that if we&rsquo;re given some EInt <code>a</code> and three proofs regarding the motive of each of the cases, then performing the cases successfully proves the motive.</p>
<p>Notice how the proof now no longer has any nested cases:</p>
<pre tabindex="0"><code class="language-lean4" data-lang="lean4">lemma EIntFunIsZero2 (e: EInt) : EIntFun e = 0 := by
  cases e using EInt.casesOn
  case ninf =&gt;
    rfl
  case int z =&gt;
    rfl
  case pinf =&gt;
    rfl
</code></pre><p>In fact, we can even use this trick to simplify our function</p>
<pre tabindex="0"><code class="language-lean4" data-lang="lean4">def EIntFun2 (e: EInt) : ℤ := by
  cases e using EInt.casesOn with
  | ninf =&gt;
    exact 0
  | int z =&gt;
    exact 0
  | pinf =&gt;
    exact 0
</code></pre><h2 id="a-more-complicated-example">A more complicated example</h2>
<p>Personally I find utility in defining how we want our cases to go prior to the proof itself. For example, let&rsquo;s break up the domain further by considering the sign of our integers.</p>
<pre tabindex="0"><code class="language-lean4" data-lang="lean4">def EInt.casesOnSigns.{u} {motive : EInt -&gt; Sort u} (a : EInt)
  (ninf : motive -∞)
  (nint : ∀ n : Int, n &lt; 0 → motive ↑n)
  (zero: ∀ n : Int, n = 0 → motive ↑n)
  (pint : ∀ n : Int, n &gt; 0 → motive ↑n)
  (pinf : motive ∞) :
motive a := by
  cases a
  case none =&gt;
    exact ninf
  case some v =&gt;
    cases v
    case top =&gt;
      exact pinf
    case coe n =&gt;
      by_cases n &lt; 0
      case pos H =&gt;
        exact nint n H
      case neg H =&gt;
        by_cases n = 0
        case pos H2 =&gt;
          exact zero n H2
        case neg H2 =&gt;
          have H3 : n &gt; 0 := by
            have HH : n ≥ 0 := Int.not_lt.mp H
            have HH2 : n ≠ 0 := H2
            have HH3 : 0 ≠ n := Ne.symm HH2
            exact lt_of_le_of_ne HH HH3
          exact pint n H3
</code></pre><p>The more complicated we make our cases, the more Lean will struggle to establish definitional equality. I personally find it useful to create helper lemmas for each of the cases to later help establish our motive.</p>
<p><strong>Negative Infinity Case</strong></p>
<pre tabindex="0"><code class="language-lean4" data-lang="lean4">@[simp]
lemma EInt.casesOnSigns.is_ninf.{u} {motive : EInt -&gt; Sort u}
  (ninf : motive -∞)
  (nint : ∀ n : Int, n &lt; 0 → motive ↑n)
  (zero: ∀ n : Int, n = 0 → motive ↑n)
  (pint : ∀ n : Int, n &gt; 0 → motive ↑n)
  (pinf : motive ∞) : EInt.casesOnSigns (-∞) ninf nint zero pint pinf = ninf := rfl
</code></pre><p>The above says that if we perform a cases on $-\infty$ then the result will be equivalent to the <code>ninf</code> case.</p>
<p><strong>Negative Integer Case</strong></p>
<pre tabindex="0"><code class="language-lean4" data-lang="lean4">lemma EInt.casesOnSigns.is_nint.{u} {motive : EInt -&gt; Sort u}
  (z : Int)
  (Hz : z &lt; 0)
  (ninf : motive -∞)
  (nint : ∀ n : Int, n &lt; 0 → motive ↑n)
  (zero: ∀ n : Int, n = 0 → motive ↑n)
  (pint : ∀ n : Int, n &gt; 0 → motive ↑n)
  (pinf : motive ∞) :
  EInt.casesOnSigns (↑z) ninf nint zero pint pinf = nint z Hz := by
  unfold casesOnSigns
  show (casesOn (↑z) ninf (fun n =&gt; if h : n &lt; 0 then nint n h
                                    else if h : n = 0 then zero n h
                                    else pint n (by omega : n &gt; 0)) pinf) = nint z Hz
  change (if h : z &lt; 0 then nint z h
          else if h : z = 0 then zero z h
          else pint z (by omega : z &gt; 0)) = nint z Hz
  rw [dif_pos Hz]
</code></pre><p>With our usage of inequalities, we have to help guide Lean through this proof. We first unfold the <code>casesOnSigns</code> definition to get the goal shown in the <code>show</code> tactic. From there, we already know that our EInt is the integer <code>z</code>, so we can simplify the cases to our nested if-then-else statement.  After that, since we have the hypothesis that our integer <code>z</code> is negative, we can directly get the <code>nint z h</code> case from the consequent of the outer ite.</p>
<p><strong>Zero Case</strong></p>
<pre tabindex="0"><code class="language-lean4" data-lang="lean4">@[simp]
lemma EInt.casesOnSigns.is_zero.{u}  {motive : EInt -&gt; Sort u}
  (z : Int)
  (Hn : z = 0)
  (ninf : motive -∞)
  (nint : ∀ n : Int, n &lt; 0 → motive ↑n)
  (zero: ∀ n : Int, n = 0 → motive ↑n)
  (pint : ∀ n : Int, n &gt; 0 → motive ↑n)
  (pinf : motive ∞) : (EInt.casesOnSigns (z) ninf nint zero pint pinf)  = zero z Hn := by
    subst z
    rfl
</code></pre><p>Once we substitute zero in, Lean can automatically establish definitional equality.</p>
<p><strong>Positive Case</strong></p>
<pre tabindex="0"><code class="language-lean4" data-lang="lean4">lemma EInt.casesOnSigns.is_pint.{u}  {motive : EInt -&gt; Sort u}
  (z : Int)
  (Hz : z &gt; 0)
  (ninf : motive -∞)
  (nint : ∀ n : Int, n &lt; 0 → motive ↑n)
  (zero: ∀ n : Int, n = 0 → motive ↑n)
  (pint : ∀ n : Int, n &gt; 0 → motive ↑n)
  (pinf : motive ∞) : (EInt.casesOnSigns (z) ninf nint zero pint pinf)  = pint z Hz := by
  unfold casesOnSigns
  show (casesOn (↑z) ninf (fun n =&gt; if h : n &lt; 0 then nint n h
                                    else if h : n = 0 then zero n h
                                    else pint n (by omega : n &gt; 0)) pinf) = pint z Hz
  change (if h : z &lt; 0 then nint z h
          else if h : z = 0 then zero z h
          else pint z (Hz : z &gt; 0)) = pint z Hz
  have HH: ¬(z &lt; 0) := not_lt_of_gt Hz
  rw [dif_neg HH]
  have HH2: ¬(z = 0) := Int.ne_of_gt Hz
  rw [dif_neg HH2]
</code></pre><p>Similar to the negative case, but we need to do slightly more work to get to the last alternative within the nested if-then-else statement.</p>
<p><strong>Infinity Case</strong></p>
<pre tabindex="0"><code class="language-lean4" data-lang="lean4">@[simp]
lemma EInt.casesOnSigns.is_pinf.{u} {motive : EInt -&gt; Sort u}
  (ninf : motive -∞)
  (nint : ∀ n : Int, n &lt; 0 → motive ↑n)
  (zero: ∀ n : Int, n = 0 → motive ↑n)
  (pint : ∀ n : Int, n &gt; 0 → motive ↑n)
  (pinf : motive ∞) : EInt.casesOnSigns (∞) ninf nint zero pint pinf = pinf := rfl
</code></pre><hr>
<p>Like before, now that we have our new definition <code>EInt.casesOnSigns</code>, we can create our function which determines whether an EInt is positive cleanly.</p>
<pre tabindex="0"><code class="language-lean4" data-lang="lean4">def EInt.isPos (e: EInt) : Bool := by
  cases e using EInt.casesOnSigns with
  | ninf =&gt; exact false
  | nint _ =&gt; exact false
  | zero =&gt; exact false
  | pint _ =&gt; exact true
  | pinf =&gt; exact true
</code></pre><p>This is much better than if we worked with the original <code>WithTop</code> and <code>WithBot</code> version! Now let&rsquo;s prove that our EInt is positive iff it is greater than zero. To do this we&rsquo;ll need one helper lemma.</p>
<pre tabindex="0"><code class="language-lean4" data-lang="lean4">lemma EInt.coe_lt_coe {a b : Int}:  ((↑a : EInt) &lt; (↑b: EInt)) ↔ a &lt; b := by
  have H1 : ((↑a : EInt) &lt; (↑b: EInt)) → a &lt; b := by
    intro (H: (↑a : EInt) &lt; (↑b: EInt))
    apply WithTop.coe_lt_coe.mp
    exact WithBot.coe_lt_coe.mp H
  have H2 : a &lt; b → ((↑a : EInt) &lt; (↑b: EInt)) := by
    clear H1
    intro (H : a &lt; b)
    apply WithBot.coe_lt_coe.mpr
    exact WithTop.coe_lt_coe.mpr H
  exact Iff.intro H1 H2
</code></pre><p>The above lemma states that if the integer $a$ is less than the integer $b$, then the EInt version of $a$ is less than the EInt version of $b$ and vice versa.  Now for the main proof</p>
<p><strong>Soundness</strong></p>
<p>If our EInt <code>e</code> is positive, then <code>e</code> is greater than zero.</p>
<pre tabindex="0"><code class="language-lean4" data-lang="lean4">lemma EInt.isPos_sound (e: EInt) : e.isPos = true → e &gt; 0 := by
  intro H
  cases e using EInt.casesOnSigns
  case ninf =&gt;
    contradiction
  case nint n Hn =&gt;
    unfold EInt.isPos at H
    rw [EInt.casesOnSigns.is_nint n Hn] at H
    contradiction
  case zero n Hz =&gt;
    unfold EInt.isPos at H
    rw [EInt.casesOnSigns.is_zero n Hz] at H
    contradiction
  case pint n Hp =&gt;
    apply EInt.coe_lt_coe.mpr Hp
  case pinf =&gt;
    exact Batteries.compareOfLessAndEq_eq_lt.mp rfl
</code></pre><p><strong>Completeness</strong></p>
<p>If our EInt <code>e</code> is greater than zero, then <code>e</code> is positive.</p>
<pre tabindex="0"><code class="language-lean4" data-lang="lean4">lemma EInt.isPos_complete (e: EInt) : e &gt; 0 → e.isPos = true := by
  intro H
  cases e using EInt.casesOnSigns
  case ninf =&gt;
    contradiction
  case nint n Hn =&gt;
    have H2 : n &gt; 0 := EInt.coe_lt_coe.mp H
    have H3 : ¬(n &gt; 0) := not_lt_of_gt Hn
    contradiction
  case zero n Hz =&gt;
    have H2 : n &gt; 0 := EInt.coe_lt_coe.mp H
    have H3 : ¬(n &gt; 0) := Eq.not_gt Hz
    contradiction
  case pint n Hp =&gt;
    unfold EInt.isPos
    rw [EInt.casesOnSigns.is_pint n Hp _ _ _ _ _ ]
  case pinf =&gt;
    unfold EInt.isPos
    rw [EInt.casesOnSigns.is_pinf]
</code></pre>]]></content:encoded>
  <category>Lean</category>
  <category>Proof assistant</category>
  <category>Formal Proof</category>
  
</item>
  
  <item>
  <title></title>
  <link></link>
  <pubDate>Sun, 07 Sep 2025 17:50:44 +0000</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid></guid>
  <description><![CDATA[]]></description>
  <content:encoded><![CDATA[]]></content:encoded>
  
</item>
  
  <item>
  <title>Cursed Knowledge: Javascript Arrays Are Objects</title>
  <link>https://brandonrozek.com/blog/cursed-knowledge-javascript-arrays-are-objects/</link>
  <pubDate>Mon, 01 Sep 2025 09:47:01 -0400</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid>https://brandonrozek.com/blog/cursed-knowledge-javascript-arrays-are-objects/</guid>
  <description><![CDATA[<p>My friend Ethan recently wrote a blog post on <a href="https://emar10.dev/posts/cursed-commands-part-1/">cursed commands</a>. Chris shared with me that Immich has a page on their site called <a href="https://immich.app/cursed-knowledge/">cursed knowledge</a>, and it looks like this has started a trend. I&rsquo;ve seen my fair share of the dark arts in programming, so I&rsquo;ll hop on and share what I know about JavaScript arrays.</p>
<p>JavaScript arrays are <a href="https://262.ecma-international.org/#sec-array-exotic-objects"><em>exotic objects</em></a> according to the ECMAScript specification. Therefore, they may lead to unintuitive behavior if we think of these arrays as C-like.</p>]]></description>
  <content:encoded><![CDATA[<p>My friend Ethan recently wrote a blog post on <a href="https://emar10.dev/posts/cursed-commands-part-1/">cursed commands</a>. Chris shared with me that Immich has a page on their site called <a href="https://immich.app/cursed-knowledge/">cursed knowledge</a>, and it looks like this has started a trend. I&rsquo;ve seen my fair share of the dark arts in programming, so I&rsquo;ll hop on and share what I know about JavaScript arrays.</p>
<p>JavaScript arrays are <a href="https://262.ecma-international.org/#sec-array-exotic-objects"><em>exotic objects</em></a> according to the ECMAScript specification. Therefore, they may lead to unintuitive behavior if we think of these arrays as C-like.</p>
<p>Let&rsquo;s play around.</p>
<h3 id="concept-1-javascript-arrays-are-not-continguous">Concept 1: JavaScript arrays are not continguous</h3>
<p>First, consider the following array:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span><span style="color:#66d9ef">let</span> <span style="color:#a6e22e">x</span> <span style="color:#f92672">=</span> [<span style="color:#ae81ff">0</span>, <span style="color:#ae81ff">1</span>, <span style="color:#ae81ff">2</span>];
</span></span></code></pre></div><p>As one might expect, <code>x.length</code> is equal to <code>3</code>. To tell whether or not an index is in an array, we can use the <code>in</code> operator.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span><span style="color:#ae81ff">3</span> <span style="color:#66d9ef">in</span> <span style="color:#a6e22e">x</span> <span style="color:#75715e">// Evaluates to false
</span></span></span></code></pre></div><p>If we try to access the 3rd index, the result will evaluate to <code>undefined</code>.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span><span style="color:#a6e22e">x</span>[<span style="color:#ae81ff">3</span>] <span style="color:#75715e">// Evaluates to undefined
</span></span></span></code></pre></div><p>Now let&rsquo;s assign an element to the 4th index. Keep in mind that we&rsquo;re skipping over the 3rd one.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span><span style="color:#a6e22e">x</span>[<span style="color:#ae81ff">4</span>] <span style="color:#f92672">=</span> <span style="color:#ae81ff">4</span>;
</span></span></code></pre></div><p>Now when we check our <code>length</code> property, it&rsquo;ll say that our array is now of size <code>5</code>.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span><span style="color:#a6e22e">x</span>.<span style="color:#a6e22e">length</span> <span style="color:#75715e">// Evaluates to 5
</span></span></span></code></pre></div><p>However, the 3rd index still does not exist</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span><span style="color:#ae81ff">3</span> <span style="color:#66d9ef">in</span> <span style="color:#a6e22e">x</span> <span style="color:#75715e">// Evaluates to false
</span></span></span></code></pre></div><h3 id="concept-2-explicit-vs-implicit-undefined">Concept 2: Explicit vs Implicit <code>undefined</code></h3>
<p>Recall that <code>x[3]</code> evaluates to <code>undefined</code>. What happens when we set the value explicitly?</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span><span style="color:#a6e22e">x</span>[<span style="color:#ae81ff">3</span>] <span style="color:#f92672">=</span> <span style="color:#66d9ef">undefined</span>;
</span></span><span style="display:flex;"><span><span style="color:#ae81ff">3</span> <span style="color:#66d9ef">in</span> <span style="color:#a6e22e">x</span> <span style="color:#75715e">// Evaluates to true
</span></span></span></code></pre></div><p>So there is a difference on whether we have explicitly set an index to <code>undefined</code>! This distinction is not always used. For example, our trusty for-of loop does not care.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span><span style="color:#a6e22e">x</span> <span style="color:#f92672">=</span> [<span style="color:#ae81ff">0</span>, <span style="color:#ae81ff">1</span>, <span style="color:#ae81ff">2</span>];
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">x</span>[<span style="color:#ae81ff">4</span>] <span style="color:#f92672">=</span> <span style="color:#ae81ff">4</span>;
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">for</span> (<span style="color:#a6e22e">a</span> <span style="color:#66d9ef">of</span> <span style="color:#a6e22e">x</span>) {
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">console</span>.<span style="color:#a6e22e">log</span>(<span style="color:#a6e22e">a</span>)
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>Will print out</p>
<pre tabindex="0"><code>0
1
2
undefined
4
</code></pre><h3 id="concept-3-indices-are-actually-strings">Concept 3: Indices are actually strings</h3>
<p>Given that we have a length property and that we&rsquo;ve been indexing with numeric keys, it must mean that arrays have numeric indices. Right?</p>
<pre tabindex="0"><code>&#34;0&#34; in [&#34;a&#34;, &#34;b&#34;] // Evaluates to true
</code></pre><p>Okay, it looks like there&rsquo;s some conversion magic that&rsquo;s happening behind the scenes here. The ECMAScript specification says that an array index must be strictly less than $2^{32}$. So what happens if it is not?</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span><span style="color:#66d9ef">let</span> <span style="color:#a6e22e">x</span> <span style="color:#f92672">=</span> [<span style="color:#ae81ff">0</span>];
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">x</span>[<span style="color:#ae81ff">4294967296</span>] <span style="color:#f92672">=</span> <span style="color:#66d9ef">true</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">x</span> <span style="color:#75715e">// Evaluates to [ 0, &#39;4294967296&#39;: true ]
</span></span></span></code></pre></div><p>It looks like it no longer gets treated as an array item, but instead treats it as an arbitrary key-value pair. Why stop there, this must mean that we can store any sort of arbitrary data in our array.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span><span style="color:#a6e22e">x</span>.<span style="color:#a6e22e">name</span> <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;Brandon&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">x</span> <span style="color:#75715e">// Evaluates to [ 0, &#39;4294967296&#39;: true, name: &#39;Brandon&#39; ]
</span></span></span></code></pre></div><h3 id="viewing-arrays-as-objects">Viewing arrays as objects</h3>
<p>Now everything starts to make more sense when we think of these arrays as objects.</p>
<pre tabindex="0"><code class="language-javscript" data-lang="javscript">let x = [0, 1, 2];
x[4] = 4;
</code></pre><p>Internally, this corresponds to the object:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span>    <span style="color:#e6db74">&#34;0&#34;</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">0</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#e6db74">&#34;1&#34;</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">1</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#e6db74">&#34;2&#34;</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">2</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#e6db74">&#34;4&#34;</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">4</span>
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>From this object, we can see that the keys are strings and that the 3rd key is not in the object. Now let&rsquo;s see what happens when we explicitly set <code>x[5] = undefined</code>.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span>  <span style="color:#e6db74">&#34;0&#34;</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">0</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#e6db74">&#34;1&#34;</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">1</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#e6db74">&#34;2&#34;</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">2</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#e6db74">&#34;4&#34;</span><span style="color:#f92672">:</span> <span style="color:#ae81ff">4</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#e6db74">&#34;5&#34;</span><span style="color:#f92672">:</span> <span style="color:#66d9ef">undefined</span>
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>The 5th key is now in our object and it&rsquo;s set to an undefined value. We also get an undefined value when we try to retrieve a value of a key that is not in our object.</p>
<p>The length of our array is the highest &ldquo;numeric&rdquo; key within our object (subject to the size limit). When we iterate over our array using <code>for-of</code>, we&rsquo;re iterating from <code>&quot;0&quot;</code> to our length.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span><span style="color:#66d9ef">for</span> (<span style="color:#a6e22e">a</span> <span style="color:#66d9ef">of</span> <span style="color:#a6e22e">x</span>) {
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">console</span>.<span style="color:#a6e22e">log</span>(<span style="color:#a6e22e">a</span>);
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>Is the same as:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span><span style="color:#a6e22e">console</span>.<span style="color:#a6e22e">log</span>(<span style="color:#a6e22e">x</span>[<span style="color:#ae81ff">0</span>]);
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">console</span>.<span style="color:#a6e22e">log</span>(<span style="color:#a6e22e">x</span>[<span style="color:#ae81ff">1</span>]);
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">console</span>.<span style="color:#a6e22e">log</span>(<span style="color:#a6e22e">x</span>[<span style="color:#ae81ff">2</span>]);
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">console</span>.<span style="color:#a6e22e">log</span>(<span style="color:#a6e22e">x</span>[<span style="color:#ae81ff">3</span>]);
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">console</span>.<span style="color:#a6e22e">log</span>(<span style="color:#a6e22e">x</span>[<span style="color:#ae81ff">4</span>]);
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">console</span>.<span style="color:#a6e22e">log</span>(<span style="color:#a6e22e">x</span>[<span style="color:#ae81ff">5</span>]);
</span></span></code></pre></div><p>That&rsquo;s an exotic object for you.</p>
]]></content:encoded>
  <category>JavaScript</category>
  
</item>
  
  <item>
  <title></title>
  <link></link>
  <pubDate>Sat, 26 Jul 2025 15:56:50 +0000</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid></guid>
  <description><![CDATA[<p>The polls are now open over at USPS to determine which forever stamp to bring back.</p><p><a href="https://www.stampsforever.com/vote" target="_blank" rel="nofollow noopener" translate="no"><span class="invisible">https://www.</span><span class="">stampsforever.com/vote</span><span class="invisible"></span></a></p><p>The stamps that they make are always cool and it&#39;s great to see recognition for some of the earlier designs.</p>]]></description>
  <content:encoded><![CDATA[<p>The polls are now open over at USPS to determine which forever stamp to bring back.</p><p><a href="https://www.stampsforever.com/vote" target="_blank" rel="nofollow noopener" translate="no"><span class="invisible">https://www.</span><span class="">stampsforever.com/vote</span><span class="invisible"></span></a></p><p>The stamps that they make are always cool and it&#39;s great to see recognition for some of the earlier designs.</p>]]></content:encoded>
  
</item>
  
  <item>
  <title>Deterministically Iterating over a set within Dafny functions</title>
  <link>https://brandonrozek.com/blog/deterministic-set-iteration-dafny/</link>
  <pubDate>Sun, 06 Jul 2025 12:27:01 -0400</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid>https://brandonrozek.com/blog/deterministic-set-iteration-dafny/</guid>
  <description><![CDATA[<p>Say we have a set that we want to iterate over within a pure Dafny function. For sake of example, we will look at a set of strings. In Dafny,  <code>var x :| condition</code> denotes &ldquo;let us define variable x such that [condition]&rdquo;. Therefore, a first attempt at writing our function might be:</p>
<pre tabindex="0"><code>function iterate_helper(collection: set&lt;string&gt;, acc: seq&lt;string&gt;): seq&lt;string&gt;
{
    if collection == {} then acc
    else
        var x :| x in collection;
        var newAcc := acc + [x];
        var newCollection := collection - {x};
        iterate_helper(newCollection, newAcc)
}
</code></pre><p>The issue is that Dafny will complain with the following error message:</p>]]></description>
  <content:encoded><![CDATA[<p>Say we have a set that we want to iterate over within a pure Dafny function. For sake of example, we will look at a set of strings. In Dafny,  <code>var x :| condition</code> denotes &ldquo;let us define variable x such that [condition]&rdquo;. Therefore, a first attempt at writing our function might be:</p>
<pre tabindex="0"><code>function iterate_helper(collection: set&lt;string&gt;, acc: seq&lt;string&gt;): seq&lt;string&gt;
{
    if collection == {} then acc
    else
        var x :| x in collection;
        var newAcc := acc + [x];
        var newCollection := collection - {x};
        iterate_helper(newCollection, newAcc)
}
</code></pre><p>The issue is that Dafny will complain with the following error message:</p>
<blockquote>
<p>to be compilable, the value of a let-such-that expression must be uniquely determined</p></blockquote>
<p>Dafny functions must be deterministic. This means that no matter how many times we call a function with some specified input, we will always get the same output. Therefore, as the error message suggests, we need to write a condition that <em>uniquely</em> determines <code>x</code>. One way to achieve this is to specify an order as described in <a href="https://www.microsoft.com/en-us/research/wp-content/uploads/2016/12/krml252.pdf">Rustan&rsquo;s paper</a>:</p>
<pre tabindex="0"><code>function iterate_helper(collection: set&lt;string&gt;, acc: seq&lt;string&gt;): seq&lt;string&gt;
{
    if collection == {} then acc
    else
        var x :| x in collection &amp;&amp; forall y | y in collection :: x &lt;= y;
        var newAcc := acc + [x];
        var newCollection := collection - {x};
        iterate_helper(newCollection, newAcc)
}
</code></pre><p>Unfortunately, this code will return two errors:</p>
<blockquote>
<p>cannot establish the existence of LHS values that satisfy the such-that predicate</p></blockquote>
<blockquote>
<p>to be compilable, the value of a let-such-that expression must be uniquely determined</p></blockquote>
<p>However, it&rsquo;s totally possible to define an ordering over strings. We&rsquo;ll just need to do some work to convince the verifier of this.</p>
<h3 id="comparing-two-strings">Comparing two strings</h3>
<p>Since strings in Dafny are a sequence of characters, it turns out that the <code>&lt;=</code> relation checks whether the left side is a prefix of the right side. Therefore, there is no such thing as a <em>unique</em> minimum element, since there are incomparable elements like &ldquo;a&rdquo; and &ldquo;b&rdquo;.</p>
<p>As such, our first step is to create a less than or equal to (<code>&lt;=</code>) relation that induces a total order.  Consider the following function that determines the order based on the left-most character.</p>
<pre tabindex="0"><code class="language-function" data-lang="function">function string_le(s1: string, s2: string): bool
    decreases |s1| + |s2|
{
    if |s1| == 0 &amp;&amp; |s2| &gt; 0 then
        true
    else if |s1| &gt; 0 &amp;&amp; |s2| == 0 then
        false
    else if |s1| == 0 &amp;&amp; |s2| == 0 then
        true
    else
        assert(|s1| &gt; 0);
        assert(|s2| &gt; 0);
        var c1 := s1[0];
        var c2 := s2[0];
        if c1 &lt; c2 then
            true
        else if c1 &gt; c2 then
            false
        else
            string_le(s1[1..], s2[1..])
}
</code></pre><h3 id="properties-of-our-comparison-function">Properties of our comparison function</h3>
<p>From here we need to prove that our relation induces a total order. For this, we need to show that it is reflexive, total, anti-symmetric, and transitive.</p>
<p>Reflexivity: All strings are less than or equal to themselves</p>
<pre tabindex="0"><code>lemma string_le_reflexive()
    ensures forall s :: string_le(s ,s)
{
    forall s ensures string_le(s, s)
    {
        string_le_reflexive_helper(s);
    }
}

lemma string_le_reflexive_helper(s1: string)
    ensures string_le(s1, s1)
{}
</code></pre><p>Totality: Given two strings, one is less than or equal to the other.</p>
<pre tabindex="0"><code>lemma string_le_totality()
    ensures forall s1, s2 :: string_le(s1, s2) || string_le(s2, s1)
{
    forall s1, s2 ensures string_le(s1, s2) || string_le(s2, s1)
    {
        string_le_totality_helper(s1, s2);
    }
}

lemma string_le_totality_helper(s1: string, s2: string)
    ensures string_le(s1, s2) || string_le(s2, s1)
{}
</code></pre><p>Antisymmetric: If one string is less than or equal to another string and that other string is also less than or equal to the original string then both strings are equivalent.</p>
<pre tabindex="0"><code>lemma string_le_antisymmetric()
    ensures forall s1, s2 :: string_le(s1, s2) &amp;&amp; string_le(s2, s1) ==&gt; s1 == s2
{
    forall s1, s2 | string_le(s1, s2) &amp;&amp; string_le(s2, s1)
    ensures s1 == s2
    {
        string_le_antisymmetric_helper(s1, s2);
    }
}

lemma string_le_antisymmetric_helper(s1: string, s2: string)
    requires string_le(s1, s2)
    requires string_le(s2, s1)
    ensures s1 == s2
{}
</code></pre><p>Transitive: If one string is less than or equal to another string, and that other string is less than or equal to some third string, then the first string is less than or equal to that third string.</p>
<pre tabindex="0"><code>lemma string_le_transitive()
    ensures forall s1, s2, s3 :: string_le(s1, s2) &amp;&amp; string_le(s2, s3) ==&gt; string_le(s1, s3)
{
    forall s1, s2, s3 | string_le(s1, s2) &amp;&amp; string_le(s2, s3)
    ensures string_le(s1, s3)
    {
        string_le_transitive_helper(s1, s2, s3);
    }
}

lemma string_le_transitive_helper(s1: string, s2: string, s3: string)
    requires string_le(s1, s2)
    requires string_le(s2, s3)
    ensures string_le(s1, s3)
{}
</code></pre><p>Then, we conviniently package all the properties together:</p>
<pre tabindex="0"><code>lemma string_le_properties()
    ensures forall s :: string_le(s, s)
    ensures forall s1, s2 :: string_le(s1, s2) &amp;&amp; string_le(s2, s1) ==&gt; s1 == s2
    ensures forall s1, s2, s3 :: string_le(s1, s2) &amp;&amp; string_le(s2, s3) ==&gt; string_le(s1, s3)
    ensures forall s1, s2 :: string_le(s1, s2) || string_le(s2, s1)
{
    string_le_reflexive();
    string_le_antisymmetric();
    string_le_transitive();
    string_le_totality();
}
</code></pre><h3 id="string-sets-have-a-minimum">String sets have a minimum</h3>
<p>With the total ordering of strings, we can prove that a smallest element exists within a non-empty set <code>s</code>. First, let us invoke our comparison properties lemma, so the verifier has access to those properties:</p>
<pre tabindex="0"><code>string_le_properties();
</code></pre><p>Since our set is non-empty, we can grab an arbitrary element from <code>s</code>.</p>
<pre tabindex="0"><code>var x :| x in s;
</code></pre><p>For this proof, we&rsquo;ll approach it inductively. First, let&rsquo;s consider when <code>s == {x}</code>.</p>
<ol>
<li>By construction, every element in <code>s</code> is equal to <code>x</code>.</li>
<li>Then by reflexivity, <code>x</code> is smaller than every element in <code>s</code>.</li>
</ol>
<pre tabindex="0"><code>assert forall y :: y in s ==&gt; y == x;
assert forall y :: y in s ==&gt; string_le(x, y);
</code></pre><p>Now let&rsquo;s consider the inductive case. The set in this case has more elements than just <code>x</code>. Let&rsquo;s consider <code>s'</code> the subset of <code>s</code> without the element <code>x</code>.</p>
<pre tabindex="0"><code>var s&#39; := s - {x};
assert s&#39; != {};
</code></pre><p>Since <code>s'</code> is non-empty, we can by induction say that  <code>s'</code> has a smallest element.</p>
<pre tabindex="0"><code>string_smallest_exists(s&#39;);
var x&#39; :| x&#39; in s&#39; &amp;&amp; forall y :: y in s&#39; ==&gt; string_le(x&#39;, y);
</code></pre><p>As <code>s'</code> is the subset of <code>s</code> without <code>x</code>, we can assert that <code>x'</code> and <code>x</code> are not the same:</p>
<pre tabindex="0"><code>assert x&#39; != x;
</code></pre><p>From here, we compare both <code>x</code> and <code>x'</code> (which we&rsquo;re able to do since <code>&lt;=</code> is total)</p>
<p>Case 1: <code>x &lt;= x'</code>: By transitivity, <code>x</code> will be less than all the elements of <code>s'</code>. Since <code>s'</code> is  <code>s</code>  without <code>x</code>, we can safely say that <code>x</code> is less than every element in <code>s</code>.</p>
<pre tabindex="0"><code>assert forall y :: y in s&#39; ==&gt; string_le(x, y);
assert forall y :: y in s ==&gt; string_le(x, y);
</code></pre><p>Case 2: <code>!(x &lt;= x')</code>. From totality, we have that <code>x' &lt;= x</code>. Since we know from the inductive hypothesis that <code>x'</code> is the minimum of <code>s'</code> and <code>s</code> is <code>s'</code> with the element <code>x</code>, we can conclude that <code>x'</code> is the smallest element of <code>s</code>.</p>
<pre tabindex="0"><code>assert !string_le(x, x&#39;);
assert string_le(x&#39;, x);
assert forall y :: y in s ==&gt; string_le(x&#39;, y);
</code></pre><p>With that, we&rsquo;ve proven that a smallest string exists! Here&rsquo;s the lemma in its entirety:</p>
<pre tabindex="0"><code>lemma string_smallest_exists(s: set&lt;string&gt;)
    requires s != {}
    decreases s
    ensures exists x :: x in s &amp;&amp; forall y :: y in s ==&gt; string_le(x, y)
{
    string_le_properties();

    var x :| x in s;

    // Base Case
    if s == {x} {
        assert forall y :: y in s ==&gt; y == x;
        assert forall y :: y in s ==&gt; string_le(x, y);
	
    // Inductive Case
    } else {
        var s&#39; := s - {x};
        assert s&#39; != {};
        string_smallest_exists(s&#39;);
        var x&#39; :| x&#39; in s&#39; &amp;&amp; forall y :: y in s&#39; ==&gt; string_le(x&#39;, y);
        assert x != x&#39;;

        if string_le(x, x&#39;) {
            assert forall y :: y in s&#39; ==&gt; string_le(x, y);
            assert forall y :: y in s ==&gt; string_le(x, y);
        } else {
            // x&#39; is smaller than x
            assert !string_le(x, x&#39;);
            assert string_le(x&#39;, x);
            assert forall y :: y in s ==&gt; string_le(x&#39;, y);
        }
    }
}
</code></pre><h3 id="select-the-smallest-element-from-a-set">Select the smallest element from a set</h3>
<p>Now that we have determined that a minimum exists in a set, we can use these lemmas to establish that we can uniquely determine the element that we select based on the ordering.</p>
<pre tabindex="0"><code>function select_string_from_set(collection: set&lt;string&gt;): string
    requires collection != {}
{
    string_le_properties();
    string_smallest_exists(collection);
    var value :| value in collection &amp;&amp; forall y | y in collection :: string_le(value, y);
    value
}
</code></pre><h3 id="conclusion">Conclusion</h3>
<p>Revisiting our iteration example, we can use our new <code>select_string_from_set</code> function to iterate over a set of strings in a pure deterministic function. More specifically, we&rsquo;ll visit all the elements in the collection in the order defined by our relation.</p>
<pre tabindex="0"><code>function iterate_helper(collection: set&lt;string&gt;, acc: seq&lt;string&gt;): seq&lt;string&gt;
    decreases collection
{
    if collection == {} then acc
    else
        var x := select_string_from_set(collection);
        var newAcc := acc + [x];
        var newCollection := collection - {x};
        iterate_helper(newCollection, newAcc)
}
</code></pre><p>From here you can generalize beyond a set of strings, as long as you&rsquo;re able to prove the properties of a total order. The full code for our string sets example is below:</p>
<pre tabindex="0"><code>function string_le(s1: string, s2: string): bool
    decreases |s1| + |s2|
{
    if |s1| == 0 &amp;&amp; |s2| &gt; 0 then
        true
    else if |s1| &gt; 0 &amp;&amp; |s2| == 0 then
        false
    else if |s1| == 0 &amp;&amp; |s2| == 0 then
        true
    else
        assert(|s1| &gt; 0);
        assert(|s2| &gt; 0);
        var c1 := s1[0];
        var c2 := s2[0];
        if c1 &lt; c2 then
            true
        else if c1 &gt; c2 then
            false
        else
            string_le(s1[1..], s2[1..])
}

lemma string_le_reflexive()
    ensures forall s :: string_le(s ,s)
{
    forall s ensures string_le(s, s)
    {
        string_le_reflexive_helper(s);
    }
}

lemma string_le_reflexive_helper(s1: string)
    ensures string_le(s1, s1)
{}

lemma string_le_totality()
    ensures forall s1, s2 :: string_le(s1, s2) || string_le(s2, s1)
{
    forall s1, s2 ensures string_le(s1, s2) || string_le(s2, s1)
    {
        string_le_totality_helper(s1, s2);
    }
}

lemma string_le_totality_helper(s1: string, s2: string)
    ensures string_le(s1, s2) || string_le(s2, s1)
{}

lemma string_le_antisymmetric()
    ensures forall s1, s2 :: string_le(s1, s2) &amp;&amp; string_le(s2, s1) ==&gt; s1 == s2
{
    forall s1, s2 | string_le(s1, s2) &amp;&amp; string_le(s2, s1)
    ensures s1 == s2
    {
        string_le_antisymmetric_helper(s1, s2);
    }
}

lemma string_le_antisymmetric_helper(s1: string, s2: string)
    requires string_le(s1, s2)
    requires string_le(s2, s1)
    ensures s1 == s2
{}


lemma string_le_transitive()
    ensures forall s1, s2, s3 :: string_le(s1, s2) &amp;&amp; string_le(s2, s3) ==&gt; string_le(s1, s3)
{
    forall s1, s2, s3 | string_le(s1, s2) &amp;&amp; string_le(s2, s3)
    ensures string_le(s1, s3)
    {
        string_le_transitive_helper(s1, s2, s3);
    }
}

lemma string_le_transitive_helper(s1: string, s2: string, s3: string)
    requires string_le(s1, s2)
    requires string_le(s2, s3)
    ensures string_le(s1, s3)
{}

lemma string_le_properties()
    ensures forall s :: string_le(s, s)
    ensures forall s1, s2 :: string_le(s1, s2) &amp;&amp; string_le(s2, s1) ==&gt; s1 == s2
    ensures forall s1, s2, s3 :: string_le(s1, s2) &amp;&amp; string_le(s2, s3) ==&gt; string_le(s1, s3)
    ensures forall s1, s2 :: string_le(s1, s2) || string_le(s2, s1)
{
    string_le_reflexive();
    string_le_antisymmetric();
    string_le_transitive();
    string_le_totality();
}


lemma string_smallest_exists(s: set&lt;string&gt;)
    requires s != {}
    decreases s
    ensures exists x :: x in s &amp;&amp; forall y :: y in s ==&gt; string_le(x, y)
{
    string_le_properties();

    var x :| x in s;

    if s == {x} {
        assert forall y :: y in s ==&gt; y == x;
        assert forall y :: y in s ==&gt; string_le(x, y);
    } else {
        // For sets with more than one element, we use induction-like reasoning
        var s&#39; := s - {x};

        assert s&#39; != {};
        string_smallest_exists(s&#39;);

        var x&#39; :| x&#39; in s&#39; &amp;&amp; forall y :: y in s&#39; ==&gt; string_le(x&#39;, y);
        assert x != x&#39;;

        if string_le(x, x&#39;) {
            assert forall y :: y in s&#39; ==&gt; string_le(x, y);
            assert forall y :: y in s ==&gt; string_le(x, y);
        } else {
            // x&#39; is smaller than x
            assert !string_le(x, x&#39;);
            assert string_le(x&#39;, x);
            assert forall y :: y in s ==&gt; string_le(x&#39;, y);
        }
    }
}

function select_string_from_set(collection: set&lt;string&gt;): string
    requires collection != {}
{
    string_le_properties();
    string_smallest_exists(collection);
    var value :| value in collection &amp;&amp; forall y | y in collection :: string_le(value, y);
    value
}

function iterate_helper(collection: set&lt;string&gt;, acc: seq&lt;string&gt;): seq&lt;string&gt;
    decreases collection
{
    if collection == {} then acc
    else
        var x := select_string_from_set(collection);
        var newAcc := acc + [x];
        var newCollection := collection - {x};
        iterate_helper(newCollection, newAcc)
}
</code></pre>]]></content:encoded>
  <category>Dafny</category>
  <category>Formal methods</category>
  <category>Deterministic algorithm</category>
  <category>Total order</category>
  
</item>
  
  <item>
  <title>Dealing with Web Scrapers</title>
  <link>https://brandonrozek.com/blog/anti-scraper-techniques/</link>
  <pubDate>Wed, 02 Jul 2025 09:10:23 -0400</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid>https://brandonrozek.com/blog/anti-scraper-techniques/</guid>
  <description><![CDATA[<p>Nowadays it seems like every tech company is eager to scrape the web. Unfortunately, it seems like
<sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup> the majority of traffic that comes to this small site are scrapers. While my static website is able to handle the load, the same cannot be said about everyone.</p>
<p>Overall, the techinques I&rsquo;ve seen website owners use aim to make scraping more difficult. Though it&rsquo;s a balance. The harder we make it for bots to access a website, the more we turn away regular humans as well. Here&rsquo;s a short and non-exhaustive list of techinques:</p>]]></description>
  <content:encoded><![CDATA[<p>Nowadays it seems like every tech company is eager to scrape the web. Unfortunately, it seems like
<sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup> the majority of traffic that comes to this small site are scrapers. While my static website is able to handle the load, the same cannot be said about everyone.</p>
<p>Overall, the techinques I&rsquo;ve seen website owners use aim to make scraping more difficult. Though it&rsquo;s a balance. The harder we make it for bots to access a website, the more we turn away regular humans as well. Here&rsquo;s a short and non-exhaustive list of techinques:</p>
<ol>
<li>User Agent Filtering</li>
<li>CAPTCHA solving</li>
<li>Rate Limiting</li>
<li>Proof of work</li>
<li>Identification</li>
<li>Paywall</li>
</ol>
<h3 id="user-agent-filtering">User Agent Filtering</h3>
<p>When a person/bot requests a page from a website, the HTTP header of the request has a field called <code>User-Agent</code>.  This is to denote the type of client that the requester is using. For example, when I visited a website just now, I sent the user agent <code>Mozilla/5.0 (X11; Linux x86_64; rv:139.0) Gecko/20100101 Firefox/139.0</code>.</p>
<p>Filtering based on this string is the easiest technique to employ and also has a low chance of impacting regular humans visiting the website. <a href="https://www.rfc-editor.org/rfc/rfc9309.html">RFC 9309 Robots Exclusion Protocol</a>, more commonly known as <code>robots.txt</code>, is the most common way of implementing this technique.</p>
<p>How it works is that you create a file named <code>robots.txt</code> at the root directory of your website and write a set of rules that different robots <em>should</em> follow. Here&rsquo;s an example from <a href="https://developers.google.com/search/docs/crawling-indexing/robots/create-robots-txt">Google&rsquo;s search documentation</a>:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-txt" data-lang="txt"><span style="display:flex;"><span>User-agent: Googlebot
</span></span><span style="display:flex;"><span>Disallow: /nogooglebot/
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>User-agent: *
</span></span><span style="display:flex;"><span>Allow: /
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Sitemap: https://www.example.com/sitemap.xml
</span></span></code></pre></div><p>The <code>*</code> here is the Klenne star which means that it can match any string. Before the bot requests a page, the idea is that they first request this <code>robots.txt</code> file, find the rules that match their user agent, and follow it&rsquo;s instructions.</p>
<p>As you might imagine, not everyone writes scrapers that follow these rules. This depends on how well-written the bot was and how considerate the developer is. An alternative to this approach is to block the request at the web server. For example, here&rsquo;s how you would do that using <code>nginx</code></p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-nginx" data-lang="nginx"><span style="display:flex;"><span><span style="color:#66d9ef">if</span> <span style="color:#e6db74">(</span>$http_user_agent = <span style="color:#e6db74">&#34;Googlebot&#34;)</span>{
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">return</span> <span style="color:#ae81ff">403</span>;
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>This returns an empty response with the HTTP code <code>403 Forbidden</code>.</p>
<p>The downside to this approach is that it&rsquo;s easy to pretend that you have a different user agent. For example on my machine, the user agent set by <code>curl</code> is <code>curl/8.9.1</code>. However, I can use the same user agent as my browser by adding a flag:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>curl --user-agent <span style="color:#e6db74">&#34;Mozilla/5.0 (X11; Linux x86_64; rv:139.0) Gecko/20100101 Firefox/139.0&#34;</span> https://brandonrozek.com
</span></span></code></pre></div><h3 id="captcha-solving">CAPTCHA Solving</h3>
<p>The Completely Automated Public Turing test to tell Computers and Humans Apart (CAPTCHA) is a challenge-response approach to dealing with bots. The idea is that the webserver would present some sort of challenge that is supposedly hard for computers to solve but easy for humans. The human responds to the challenge and then is granted access to the website.</p>
<p>In the paper &ldquo;Recent advances of Captcha security analysis: a short literature review&rdquo; by Nghia Trong Dinh and Vinh Truong Hoang, they show that for the majority of CAPTCHA systems, bots are successful at solving them over 50% of the time. Specifically, the best bots are able to solve Google&rsquo;s image-based CAPTCHAs with 70.78% accuracy.</p>
<p>Unfortunately<sup id="fnref:2"><a href="#fn:2" class="footnote-ref" role="doc-noteref">2</a></sup> the success rate of bots are bound to improve over time. Additionally, CAPTCHA systems are annoying to humans. For example, when I use a VPN, I don&rsquo;t bother with Google search since I don&rsquo;t want to select pictures of stairs, fire hydrants, or crosswalks 10 times before being granted a search query.</p>
<h3 id="rate-limiting">Rate Limiting</h3>
<p>Computers are inherently faster than us. In the paper &ldquo;How many words do we read per minute? A review and meta-analysis of reading rate&rdquo; by Marc Brysbaert, he writes that the average human adult reads 238 words per minute of non-fiction silently. Thus, it would take a human on average almost 11 hours to read all my prior blog posts (assuming they don&rsquo;t get tired or distracted). Meanwhile a bot can scrape this site in under a minute.</p>
<p>From this insight, one technique is to limit the number of requests that an IP address can make at any given time. This is formally known as <em>rate limiting</em>.</p>
<p>It sounds simple in concept but can be difficult to implement without impacting user experience. How many requests is a human reasonably allowed to make in a minute? Human traffic is typically bursty, where a page load can request many different files (CSS, JS, media) in a short period of time.  How quick can I expect someone to reasonably click around my website? If this isn&rsquo;t dialed in properly, then rate limiting can cause frustration with your visitors.</p>
<p>I&rsquo;m also unsure how successful this is against the LLM web scrapers. Nowadays there are bot farms where they each have their own IP address. It&rsquo;s difficult to determine whether a request is from a human visitor or part of a larger bot collection network.</p>
<h3 id="proof-of-work">Proof of work</h3>
<p>We talked about how CAPTCHAs are difficult for computers but easy for humans. Proof of work is difficult for both computers and humans. This helps reduce the number of scrapers by making it <em>costly</em> to request resources from the website. By making the web browser solve some proof of work challenge (usually involving hash functions), the request consumes additional CPU cycles and takes additional time.</p>
<p>Similar to rate limiting, how <em>difficult</em> you make the problem has a direct impact on user experience. The more difficult, the longer it&rsquo;ll take for the web browser to solve it. This will deter more bots, but after a few seconds will also deter human visitors. <a href="https://web.archive.org/web/20250121155519/https://www.thinkwithgoogle.com/marketing-strategies/app-and-mobile/page-load-time-statistics/">According to a study performed by Google and SOASTA Research in 2017</a>, if a user has to wait 3 seconds instead of 1 second, then the probability that they <em>bounce</em> (leave the page) increases by 32%.</p>
<p>Recently, open-source projects <a href="https://anubis.techaro.lol/">Anubis</a> and <a href="https://git.gammaspectra.live/git/go-away">go-away</a> gained popularity for making it easy to implement this technique. It&rsquo;s popular for git forges like <a href="https://git.sr.ht/">sourcehut&rsquo;s</a> as scraping those incurs a lot of CPU cycles in traversing git repositories.</p>
<h3 id="identification">Identification</h3>
<p>Another tactic is to ask the requester to provide some information that a human would likely have but a bot less so. Examples include email addresses, phone number, government ID, etc. Of course, a bot can supply false information, but as with the other techinques this adds an additional barrier. Watch out for the <a href="https://gregoryhammond.ca/blog/never-to-connect-phone-numbers-a-project/">fake phone numbers</a>.</p>
<h3 id="paywall">Paywall</h3>
<p>Lastly, you can require users to pay to see the contents of your website. This is popular with news organizations where they ask you to pay for a subscription in order to see content. This ties in well with the previous tactic, because if the user pays for a subscription, then you likely have a lot of identifying information about that user.</p>
<p>Another interesting idea that I haven&rsquo;t seen widely implemented is requiring some amount of money per interaction. This can be in the form of the <a href="https://webmonetization.org/">Web Monetization API</a> or via cryptocurrency like Bitcoin on the <a href="https://lightning.network/">Lightning network</a>. <a href="https://stacker.news/">Stacker news</a> is an example of a Reddit-like platform where users need to pay a small fee in order to upvote a post. The idea is to make it cheap for a human to do on a small scale (like 1 cent per up-vote), but expensive for a bot to do at scale.</p>
<h3 id="conclusion">Conclusion</h3>
<p>We&rsquo;re in a special time period where everyone is fighting to become the top AI company. Long term, I feel that the scraper activity will die down. Similar to how there weren&rsquo;t as many web search scrapers out there.</p>
<p>In the meantime, these are multiple techniques to consider if your website is suffering under heavy load. As for myself, I don&rsquo;t currently implement any of these as my website is mostly static and I haven&rsquo;t noticed my servers being overloaded.</p>
<p>However if you do, I urge you to exercise some caution. For the most part, we share on the web for information to flow freely, and if we&rsquo;re not careful we may drive people away.</p>
<div class="footnotes" role="doc-endnotes">
<hr>
<ol>
<li id="fn:1">
<p>At least I don&rsquo;t think a human using Chrome would try to visit my homepage every minute.&#160;<a href="#fnref:1" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
<li id="fn:2">
<p>Or fortunately, if we want to get closer to AGI&#160;<a href="#fnref:2" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
</ol>
</div>
]]></content:encoded>
  <category>web scraping</category>
  <category>CAPTCHA</category>
  <category>rate limiting</category>
  <category>robots.txt</category>
  <category>proof of work</category>
  
</item>
  
  <item>
  <title>Exploring via Public Transit</title>
  <link>https://brandonrozek.com/blog/exploring-via-public-transit/</link>
  <pubDate>Sun, 15 Jun 2025 21:38:02 -0400</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid>https://brandonrozek.com/blog/exploring-via-public-transit/</guid>
  <description><![CDATA[<p>Last weekend, on my way back north from visiting downtown, I took a break near the Crestview lightrail station. There, I had a wonderful meal at the <a href="https://kurasushi.com/locations/austin-tx-airport-blvd/">Kura revolving sushi bar</a>. Afterwards, I walked around the <a href="https://usa.kinokuniya.com/stores-kinokuniya-austin">Kinokuniya Bookstore</a>. Honestly, this spot is not something I would&rsquo;ve naturally discovered on my own.</p>
<p><img src="/files/images/blog/202506071440.png" alt="Image of Sushi Conveyor Belt"></p>
<p>Using public transportation is a great way to explore the neighborhoods around you. Busses often don&rsquo;t take highways, and instead will take you through areas that you would&rsquo;ve otherwise skipped. You can find many great restaurants to eat in the Bay Area right next to the Mountain View Caltrain station. A few years ago when Clare and I visited Portland, Maine, we got to explore the thousand islands by a <a href="https://www.cascobaylines.com/maine-boat-tours/specialty-cruises/mailboat/">mail boat</a>.</p>]]></description>
  <content:encoded><![CDATA[<p>Last weekend, on my way back north from visiting downtown, I took a break near the Crestview lightrail station. There, I had a wonderful meal at the <a href="https://kurasushi.com/locations/austin-tx-airport-blvd/">Kura revolving sushi bar</a>. Afterwards, I walked around the <a href="https://usa.kinokuniya.com/stores-kinokuniya-austin">Kinokuniya Bookstore</a>. Honestly, this spot is not something I would&rsquo;ve naturally discovered on my own.</p>
<p><img src="/files/images/blog/202506071440.png" alt="Image of Sushi Conveyor Belt"></p>
<p>Using public transportation is a great way to explore the neighborhoods around you. Busses often don&rsquo;t take highways, and instead will take you through areas that you would&rsquo;ve otherwise skipped. You can find many great restaurants to eat in the Bay Area right next to the Mountain View Caltrain station. A few years ago when Clare and I visited Portland, Maine, we got to explore the thousand islands by a <a href="https://www.cascobaylines.com/maine-boat-tours/specialty-cruises/mailboat/">mail boat</a>.</p>
<p>Even if you have a car, it&rsquo;s worth taking a look at the transit maps to see if there are any hidden gems.</p>
]]></content:encoded>
  <category>public transport</category>
  
</item>
  
  <item>
  <title>Embrace the Heat</title>
  <link>https://brandonrozek.com/blog/embrace-the-heat/</link>
  <pubDate>Sun, 08 Jun 2025 20:36:54 -0400</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid>https://brandonrozek.com/blog/embrace-the-heat/</guid>
  <description><![CDATA[<p>It&rsquo;s summer and I&rsquo;m currently in Austin, Texas, where the temperature ranges between 85 F when we had a recent thunderstorm to 100 F when there are no clouds in the sky.</p>
<p>I don&rsquo;t currently have a car so I rely on public transportation and walking to get around. As such, I&rsquo;m consistently exposed to the heat. On the weekends, there is a strong temptation to hunker down and enjoy my air-conditioned apartment.  However, the part of me that loves going out and exploring wins in the end.</p>]]></description>
  <content:encoded><![CDATA[<p>It&rsquo;s summer and I&rsquo;m currently in Austin, Texas, where the temperature ranges between 85 F when we had a recent thunderstorm to 100 F when there are no clouds in the sky.</p>
<p>I don&rsquo;t currently have a car so I rely on public transportation and walking to get around. As such, I&rsquo;m consistently exposed to the heat. On the weekends, there is a strong temptation to hunker down and enjoy my air-conditioned apartment.  However, the part of me that loves going out and exploring wins in the end.</p>
<p>As with any outdoor adventure, it&rsquo;s always important to be prepared. I don&rsquo;t leave my apartment without the following three items: bucket hat, sunglasses, and a water pack. Out of these, I would say the most important is drinking lots of water. It&rsquo;s the best way to <a href="https://www.cdc.gov/healthy-weight-growth/water-healthy-drinks/index.html">regulate body temperature</a> after all. Also, it&rsquo;s better to start your day early, before the temperatures climb. Even after the sun goes down, it takes a while for the temperature to drop.</p>
<p>While browsing Reddit, I came across the phrase &ldquo;Embrace the Heat.&rdquo; In my adventures, I see plenty of people eating outdoors, walking on trails, and paddle boarding on the Colorado river. It says a lot about human resiliency that we make the most out of any situation.</p>
<p>Yesterday, I rented a bicycle from Cap Metro and rode along Lady Bird lake for two hours. Before that I&rsquo;ve been graced by the presence of the <a href="https://peasepark.org/pease-park-troll">Austin Troll Malin</a>, and I&rsquo;m looking forward to kayaking at Barton Springs.</p>
<p>If you happen to visit Austin and want an indoor activity, I recommend visiting the <a href="https://tspb.texas.gov/plan/tours/tours.html">state capitol</a>. They allow visitors to sit in the gallerie and observe when the state house and senate is in session which is pretty cool to witness.</p>
<p>Otherwise, embrace the heat. Wear light clothes and come prepared to sweat.</p>
]]></content:encoded>
  
</item>
  
  <item>
  <title>Verifying Proofs with Type Checkers</title>
  <link>https://brandonrozek.com/blog/verifying-proofs-type-checkers/</link>
  <pubDate>Tue, 27 May 2025 09:27:59 -0400</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid>https://brandonrozek.com/blog/verifying-proofs-type-checkers/</guid>
  <description><![CDATA[<p>The <a href="https://en.wikipedia.org/wiki/Curry%E2%80%93Howard_correspondence">Curry-Howard Correspondance</a> establishes a direct connection between computer programs and mathematical proofs.</p>
<table>
  <thead>
      <tr>
          <th>Programs</th>
          <th>Proofs</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>Type</td>
          <td>Formula</td>
      </tr>
      <tr>
          <td>Term</td>
          <td>Proof</td>
      </tr>
      <tr>
          <td>Type has an element</td>
          <td>Formula is provable</td>
      </tr>
      <tr>
          <td>Type does not have an element</td>
          <td>Formula is not provable</td>
      </tr>
  </tbody>
</table>
<p>When we think about traditional type systems, however, most are uncapable of expressing interesting formula. This ultimately limits the formulas we can prove.</p>
<p>For example, consider the simply typed lambda calculus. In that system we have base types like <code>int</code> and <code>bool</code>, as well as function types $t1 \rightarrow t2$ which take a type and return a type.</p>]]></description>
  <content:encoded><![CDATA[<p>The <a href="https://en.wikipedia.org/wiki/Curry%E2%80%93Howard_correspondence">Curry-Howard Correspondance</a> establishes a direct connection between computer programs and mathematical proofs.</p>
<table>
  <thead>
      <tr>
          <th>Programs</th>
          <th>Proofs</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>Type</td>
          <td>Formula</td>
      </tr>
      <tr>
          <td>Term</td>
          <td>Proof</td>
      </tr>
      <tr>
          <td>Type has an element</td>
          <td>Formula is provable</td>
      </tr>
      <tr>
          <td>Type does not have an element</td>
          <td>Formula is not provable</td>
      </tr>
  </tbody>
</table>
<p>When we think about traditional type systems, however, most are uncapable of expressing interesting formula. This ultimately limits the formulas we can prove.</p>
<p>For example, consider the simply typed lambda calculus. In that system we have base types like <code>int</code> and <code>bool</code>, as well as function types $t1 \rightarrow t2$ which take a type and return a type.</p>
<p>From that system, we can then create a proof of an integer by showing the term <code>0</code>.  The following shows how to use the Lean 4 type checker to verify that <code>0</code> is an integer:</p>
<pre tabindex="0"><code class="language-lean4" data-lang="lean4">#check (0: Int)
</code></pre><p>This, however, isn&rsquo;t a very interesting proof or formula. What would be more interesting is if we can use a type checker to verify the following:</p>
<pre tabindex="0"><code class="language-lean4" data-lang="lean4">#check (by exists [] : ∃ (x : List Int), x.length = 0)
</code></pre><p>Sadly, we can&rsquo;t verify this with the simply typed lambda calculus. This does not mean that we cannot design a type system that can.</p>
<p>Interactive theorem provers (ITPs) or <a href="https://en.wikipedia.org/wiki/Proof_assistant">proof assistants</a> help fill this void. Equipped with sophisticated type systems, they allow us to prove a formula by writing a program of that type. Some of the most popular ones include <a href="https://lean-lang.org/">Lean</a>, <a href="https://rocq-prover.org/">Rocq</a>, <a href="https://isabelle.in.tum.de/">Isabelle</a>, <a href="https://wiki.portal.chalmers.se/agda/pmwiki.php">Agda</a>, and <a href="https://fstar-lang.org/">F*</a>.</p>
<p>The underlying type system of each proof assistant is different. However, there are many similarities. In general, most aim to be at least as powerful as the calculus of constructions developed by Thierry Coquand.</p>
<p>To get an idea of how expressive these type systems are, we can analyze the <a href="https://en.wikipedia.org/wiki/Lambda_cube">Lambda cube</a>. Developed by Henk Barendregt,  this characterizes the space between the simply typed lambda calculus and the calculus of constructions.</p>
<p><img src="/files/images/blog/Lambda_Cube_img.svg" alt=""></p>
<p><a href="https://commons.wikimedia.org/wiki/File:Lambda_Cube_img.svg">Image courtesy of Tellofou on Wikipedia</a>.</p>
<p>Each dimension corresponds to an extension of the simply typed lambda calculus:</p>
<ul>
<li>X Axis: Dependent types (Types that depend on terms)</li>
<li>Y Axis: Polymorphic types (Terms that depend on types)</li>
<li>Z Axis: Type Operators (Types that depend on types)</li>
</ul>
<p><strong>Dependent Type</strong></p>
<p>A dependent type is a type that depends on some term. We can use this to, for example, write functions that return entirely different base types depending on the outcome of some conditional.</p>
<p>Here&rsquo;s an example function you can write in Lean 4:</p>
<pre tabindex="0"><code class="language-lean4" data-lang="lean4">def isZeroOrMore (n : Nat) : (if n == 0 then Bool else Nat) :=
  if H: n == 0 then by
    rw [if_pos (by exact H)]
    exact true
  else by
    rw [if_neg (by exact H)]
    exact n
</code></pre><p>The function <code>isZeroOrMore</code> will return <code>true</code> if the parameter <code>n</code> is equal to zero, otherwise it&rsquo;ll return the natural number parameter itself.</p>
<p><strong>Type Operators</strong></p>
<p>A type operator takes a type and produces a type. For example, we can create a triple type that represents the product of three base types.</p>
<pre tabindex="0"><code class="language-lean4" data-lang="lean4">structure Triple {A B C : Type} where
  a: A
  b: B
  c: C
</code></pre><p>Let&rsquo;s say that we want to enforce that all three elements of the triple are of type <code>Int</code>. Then we can create a new type <code>IntTriple</code> as follows:</p>
<pre tabindex="0"><code class="language-Lean" data-lang="Lean">def IntTriple := @Triple Int Int Int
</code></pre><p>From here, we can use <code>IntTriple</code> when type checking values.</p>
<pre tabindex="0"><code>#check (Triple.mk 1 2 3 : IntTriple)
</code></pre><p><strong>Type Polymorphism</strong></p>
<p>Type polymorphism allows us to write one function which covers many different types. There are two common places that we see this often.</p>
<p>Identity function:</p>
<pre tabindex="0"><code class="language-lean4" data-lang="lean4">def iden {α : Type} (x : α) : α := x
</code></pre><p>Here we&rsquo;re saying that the parameter a can be of any arbitrary type α, and the function <code>iden</code> will then just return the parameter itself.</p>
<p>We also see this often when defining operations over lists</p>
<pre tabindex="0"><code class="language-lean4" data-lang="lean4">def map {α β : Type} (f: α → β) (as: List α): List β :=
  match as with
  | [] =&gt; []
  | (head::tail) =&gt; f head :: map f tail
</code></pre><p>The calculus of constructions support all of these three extensions.  We&rsquo;ve introduced enough here to write a more interesting proof.</p>
<pre tabindex="0"><code class="language-lean4" data-lang="lean4">theorem map_iden_idempotent {α : Type} (as: List α) : (map iden as = as) := by
  unfold iden
  induction as
  case nil =&gt;
    unfold map
    rfl
  case cons h t IH =&gt;
    unfold map
    rw [IH]
</code></pre><p>We&rsquo;ve invoked the Lean type checker to verify that for a list of any arbitrary type, when you map over it with the identity function you get back the list itself.</p>
<p>You might ask, why don&rsquo;t all programming languages support this? By adding expressivity to our type system, we sacrifice computational efficiency. For most standard programming tasks, we want our type checker to be as fast as possible. However when we require stronger guarentees of correctness about our code, proof assistants are a great tool for the job. Many of them even generate code for mainstream programming languages.</p>
<p>That&rsquo;s all for today. I&rsquo;d like to thank James Oswald for the inspiration to write this post and some of its examples. This was adapted from a presentation we gave last month to our weekly seminar series.</p>
]]></content:encoded>
  <category>Formal methods</category>
  <category>proof assistant</category>
  <category>Curry-Howard correspondence</category>
  <category>lambda cube</category>
  <category>calculus of constructions</category>
  <category>dependent type</category>
  <category>type theory</category>
  
</item>
  
  <item>
  <title>Is this program safe? Lessons from Type Theory</title>
  <link>https://brandonrozek.com/blog/program-safety-type-theory/</link>
  <pubDate>Sat, 10 May 2025 09:28:07 -0400</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid>https://brandonrozek.com/blog/program-safety-type-theory/</guid>
  <description><![CDATA[<p><em>This blog post is inspired from a lecture that Dr. Ana Milanova gave in her Principles of Program Analysis course.</em></p>
<p>Consider an arbitrary computer program. When we execute it, we expect that it will produce some result and not get <em>stuck</em>.</p>
<p>For example,</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span>id <span style="color:#f92672">=</span> <span style="color:#66d9ef">lambda</span> x: x
</span></span><span style="display:flex;"><span>id <span style="color:#ae81ff">5</span>
</span></span></code></pre></div><p>In the code above, we create an identity function <code>id</code> which takes an argument <code>x</code> and returns that same argument. Therefore, in the second line when we call the function with the value <code>5</code>, we receive the value <code>5</code> as a result.</p>]]></description>
  <content:encoded><![CDATA[<p><em>This blog post is inspired from a lecture that Dr. Ana Milanova gave in her Principles of Program Analysis course.</em></p>
<p>Consider an arbitrary computer program. When we execute it, we expect that it will produce some result and not get <em>stuck</em>.</p>
<p>For example,</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span>id <span style="color:#f92672">=</span> <span style="color:#66d9ef">lambda</span> x: x
</span></span><span style="display:flex;"><span>id <span style="color:#ae81ff">5</span>
</span></span></code></pre></div><p>In the code above, we create an identity function <code>id</code> which takes an argument <code>x</code> and returns that same argument. Therefore, in the second line when we call the function with the value <code>5</code>, we receive the value <code>5</code> as a result.</p>
<p>Now what about the following?</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#ae81ff">5</span> id
</span></span></code></pre></div><p>This program does not make any sense since the value <code>5</code> is not a function and hence does not take anything as an argument. Ideally, we want to catch errors like these before we run our code. In fact, we can by relying on a <em>type checker</em>.</p>
<p>Through this, we only execute programs that have a valid <em>type</em>. If not, then we say that the program is invalid.</p>
<ul>
<li><code>id 5</code> is of type <code>int</code></li>
<li><code>5 id</code> does not have a valid type</li>
</ul>
<p>We won&rsquo;t delve into the formal theory of type systems, however, know that we can design a type system to be as complicated as we&rsquo;d like. We can even go as far as verifying whether the result equals an expected value at the end of program execution. However, the <a href="https://en.wikipedia.org/wiki/Halting_problem">Halting problem</a> from theoretical computer science tells us that we cannot write an algorithm that&rsquo;s guaranteed to eventually end and tell us whether an inputted program will return a specific result.</p>
<p>Due to this, we need to make some compromises in type checkers. We really want it so that if a program passes the type checker, then it will never get stuck during execution by encountering something like <code>5 id</code>. Therefore, instead we compromise by failing programs that will actually never get stuck.</p>
<p><em>Designing a type system is a trade off between runtime and how many valid programs we are able to call type safe.</em></p>
<p>In other words, there will be programs that are valid and produce a result, however our type system will not accept it.</p>


<img alt="Venn Diagram showing that type accepted programs are smaller and within the space of valid programs" src="/files/images/blog/type-safety-venn.svg" width="500px"/>


<p>For example, let us consider one of the simplest type systems. That is the simply typed lambda calculus. We won&rsquo;t go into the formal details of its presentation, but instead highlight how it won&rsquo;t allow all valid programs through an example.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span>id <span style="color:#f92672">=</span> <span style="color:#66d9ef">lambda</span> x : x
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">if</span> (id true) then (id <span style="color:#ae81ff">5</span>) <span style="color:#66d9ef">else</span> (id <span style="color:#ae81ff">6</span>)
</span></span></code></pre></div><p>Consider again our identity function but this time it is used within an if-then-else (ite) expression. When we run this code, it will return the value <code>5</code> which is of type <code>int</code>. However, what does the type checker think?</p>
<p>In the simply typed lambda calculus, the type of an expression may either be a base type like an <code>int</code> or <code> bool</code>, or it can be a function type which takes a type and returns a type (i.e,<code>type</code> $\rightarrow$ <code>type</code>).</p>
<p>From the definition of <code>id</code>, we cannot determine what type it has. Instead we know that for some type variable $t$, it is $t \rightarrow  t$.</p>
<p>Then, we take a look at the conditional part of the ite expression. We derive that <code>id</code> must have type <code>bool</code> $\rightarrow$ <code>bool</code>. However, the other two parts of the ite expression requires that <code>id</code> takes and returns an <code>int</code>!</p>
<p>Since <code>bool</code> and <code>int</code> are two distinct types, a type checker based on the simply typed lambda calculus will not accept this program.</p>
<p>In order for our type checker to accept this program, the underlying type system must support polymorphic types (sometimes called polytypes). An example system that does is System F.</p>
<p>The biggest difference during type inference, is that instead of determining that <code>id</code> has type $t \rightarrow t$ for some type variable $t$. It has type $\forall t, t \rightarrow t$. Thus, allowing for both an identity function that takes a <code>bool</code> and returns a <code>bool</code>, and for an identity function to take an <code>int</code> and return an <code>int</code>.</p>
<p>Even with polytypes, our type checker will still not accept all valid programs! A great overview on the different dimensions of type systems is on the Wikipedia page for <a href="https://en.wikipedia.org/wiki/Lambda_cube">Lambda Cube</a>.</p>
<p>In our examples above, we had our type checker also perform inference to identify what the type of the expressions are. However, we can use more efficient algorithms if we forced the writer of the program to annotate the types instead. This is another trade off to think about when designing a programming language.</p>


<img alt="Venn Diagram showing that simply type accepted programs are smaller and within system f accepted programs which are within space of valid programs" src="/files/images/blog/type-safety-simply-systemf-venn.svg" width="500px"/>


<p>Or, we can throw all caution to the wind and have our program crash and throw exceptions instead.</p>
<p>Example in Python:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#ae81ff">5</span> (<span style="color:#66d9ef">lambda</span> x: x)
</span></span></code></pre></div><pre tabindex="0"><code>Traceback (most recent call last):
  File &#34;&lt;stdin&gt;&#34;, line 1, in &lt;module&gt;
TypeError: &#39;int&#39; object is not callable
</code></pre>]]></content:encoded>
  <category>type theory</category>
  <category>type inference</category>
  
</item>
  
  <item>
  <title>Filesystem as a persistent key-value store in Python</title>
  <link>https://brandonrozek.com/blog/filesystem-as-persistent-kvs-python/</link>
  <pubDate>Sun, 27 Apr 2025 13:39:49 -0400</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid>https://brandonrozek.com/blog/filesystem-as-persistent-kvs-python/</guid>
  <description><![CDATA[<p>The first level within the <a href="https://beza1e1.tuxen.de/config_levels.html">five levels of configuration languages</a> is a string in a file. The example that Andreas gives in his blog post is enabling/disabling energy aware scheduling in the kernel.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># Read the current value</span>
</span></span><span style="display:flex;"><span>cat /proc/sys/kernel/sched_energy_aware
</span></span></code></pre></div><p>This approach does not require using any custom serializers or deserializers. Instead, the user or program only needs to navigate and read/write the filesystem.<sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup></p>
<p>However, having to write filesystem code is tedious. What we want is a dictionary that we can write and read from that handles all of the filesystem procedures for us.</p>]]></description>
  <content:encoded><![CDATA[<p>The first level within the <a href="https://beza1e1.tuxen.de/config_levels.html">five levels of configuration languages</a> is a string in a file. The example that Andreas gives in his blog post is enabling/disabling energy aware scheduling in the kernel.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># Read the current value</span>
</span></span><span style="display:flex;"><span>cat /proc/sys/kernel/sched_energy_aware
</span></span></code></pre></div><p>This approach does not require using any custom serializers or deserializers. Instead, the user or program only needs to navigate and read/write the filesystem.<sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup></p>
<p>However, having to write filesystem code is tedious. What we want is a dictionary that we can write and read from that handles all of the filesystem procedures for us.</p>
<p>In this post, we&rsquo;ll go over how to achieve this in Python. By the end we&rsquo;ll be able to do the following:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># Create key-value store</span>
</span></span><span style="display:flex;"><span>mkdir /tmp/kvs
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Add value &#34;Brandon&#34; to key &#34;name&#34;</span>
</span></span><span style="display:flex;"><span>echo <span style="color:#e6db74">&#34;Brandon&#34;</span> | tee /tmp/kvs/name
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#75715e"># Set /tmp/kvs as the root of our key-value store</span>
</span></span><span style="display:flex;"><span>kvs <span style="color:#f92672">=</span> FSDict(<span style="color:#e6db74">&#34;/tmp/kvs&#34;</span>)
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Read the key &#39;name&#39;</span>
</span></span><span style="display:flex;"><span>print(<span style="color:#e6db74">&#34;Name:&#34;</span>, kvs[<span style="color:#e6db74">&#39;name&#39;</span>])
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Name: Brandon</span>
</span></span></code></pre></div><h2 id="creating-the-library">Creating the library</h2>
<p>To emulate reading and writing from a dictionary, we will create a custom class and implement the <code>__setitem__</code> and <code>__getitem__</code> methods.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">FSDict</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">def</span> __init__(self, base_directory: Optional[str] <span style="color:#f92672">=</span> <span style="color:#66d9ef">None</span>):
</span></span><span style="display:flex;"><span>    self<span style="color:#f92672">.</span>base_directory: Optional[str] <span style="color:#f92672">=</span> <span style="color:#66d9ef">None</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">if</span> base_directory <span style="color:#f92672">is</span> <span style="color:#f92672">not</span> <span style="color:#66d9ef">None</span>:
</span></span><span style="display:flex;"><span>      self<span style="color:#f92672">.</span>set_base_directory(base_directory)
</span></span><span style="display:flex;"><span>  
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">set_base_directory</span>(self, base_directory: str):
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">assert</span> isinstance(base_directory, str)
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">if</span> os<span style="color:#f92672">.</span>path<span style="color:#f92672">.</span>isfile(base_directory):
</span></span><span style="display:flex;"><span>      <span style="color:#66d9ef">raise</span> <span style="color:#a6e22e">Exception</span>(<span style="color:#e6db74">&#34;base_directory is an existing file not a folder.&#34;</span>)
</span></span><span style="display:flex;"><span>    
</span></span><span style="display:flex;"><span>    self<span style="color:#f92672">.</span>base_directory <span style="color:#f92672">=</span> base_directory
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> os<span style="color:#f92672">.</span>path<span style="color:#f92672">.</span>exists(base_directory):
</span></span><span style="display:flex;"><span>      os<span style="color:#f92672">.</span>makedirs(base_directory)
</span></span><span style="display:flex;"><span>  
</span></span><span style="display:flex;"><span>  <span style="color:#75715e"># ...</span>
</span></span></code></pre></div><p>From here, we can declare a folder as the root of our key-value store and if it does not exist then the code will create it for us.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span>kvs <span style="color:#f92672">=</span> FSDict(<span style="color:#e6db74">&#34;/tmp/kvs&#34;</span>)
</span></span></code></pre></div><p>When we write <code>kvs['name']</code>, we want it to read from the file or folder <code>/tmp/kvs/name</code>. Our next method then will create the path.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">get_path</span>(self, key: str) <span style="color:#f92672">-&gt;</span> str:
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">assert</span> self<span style="color:#f92672">.</span>base_directory <span style="color:#f92672">is</span> <span style="color:#f92672">not</span> <span style="color:#66d9ef">None</span>
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> isinstance(key, str):
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">raise</span> <span style="color:#a6e22e">ValueError</span>(<span style="color:#e6db74">&#34;key must be of type str&#34;</span>)
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">return</span> os<span style="color:#f92672">.</span>path<span style="color:#f92672">.</span>join(self<span style="color:#f92672">.</span>base_directory, key)
</span></span></code></pre></div><p>Just like in our initial kernel example, we want a way to have nested folders. Therefore, in this API when we read and write from the KVS, if the value is a <code>str</code> then we&rsquo;re writing it&rsquo;s contents to a file, otherwise if it is a <code>FSDict</code> then we&rsquo;ll create the folder if it does not already exist.</p>
<p>To write to our key-value store:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">def</span> __setitem__(self, key: str, value: Union[str, <span style="color:#e6db74">&#34;FSDict&#34;</span>]):
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">assert</span> isinstance(value, (str, FSDict)), <span style="color:#e6db74">&#34;Value must either be of type str or FSDict&#34;</span>
</span></span><span style="display:flex;"><span>  path <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>get_path(key)
</span></span><span style="display:flex;"><span>  
</span></span><span style="display:flex;"><span>  <span style="color:#75715e"># If we&#39;re writing a FSDict, then create</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e"># a folder if it doesn&#39;t already exist.</span>
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">if</span> isinstance(value, FSDict):
</span></span><span style="display:flex;"><span>    value<span style="color:#f92672">.</span>set_base_directory(path)
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">return</span> <span style="color:#66d9ef">None</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e"># Otherwise, assume we&#39;re writing a</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e"># string to a file</span>
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">with</span> open(path, <span style="color:#e6db74">&#34;w&#34;</span>) <span style="color:#66d9ef">as</span> f:
</span></span><span style="display:flex;"><span>    f<span style="color:#f92672">.</span>write(value)
</span></span></code></pre></div><p>To read from our key-value store:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">def</span> __getitem__(self, key: str) <span style="color:#f92672">-&gt;</span> Union[str, <span style="color:#e6db74">&#34;FSDict&#34;</span>]:
</span></span><span style="display:flex;"><span>  path <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>get_path(key)
</span></span><span style="display:flex;"><span>  
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> os<span style="color:#f92672">.</span>path<span style="color:#f92672">.</span>exists(path):
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">raise</span> <span style="color:#a6e22e">KeyError</span>(key)
</span></span><span style="display:flex;"><span>  
</span></span><span style="display:flex;"><span>  <span style="color:#75715e"># Return a FSDict if it&#39;s a folder</span>
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">if</span> os<span style="color:#f92672">.</span>path<span style="color:#f92672">.</span>isdir(path):
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">return</span> FSDict(path)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e"># Otherwise, assume we&#39;re reading a file</span>
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">with</span> open(path, <span style="color:#e6db74">&#34;r&#34;</span>) <span style="color:#66d9ef">as</span> f:
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">return</span> f<span style="color:#f92672">.</span>read()
</span></span></code></pre></div><p>With that, we have the minimum viable product for reading and writing to our dictionary-like class!</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span>kvs <span style="color:#f92672">=</span> FSDict(<span style="color:#e6db74">&#34;/tmp/kvs&#34;</span>)
</span></span><span style="display:flex;"><span>kvs[<span style="color:#e6db74">&#39;name&#39;</span>] <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;Brandon&#39;</span>
</span></span><span style="display:flex;"><span>print(kvs[<span style="color:#e6db74">&#39;name&#39;</span>])
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Prints &#39;Brandon&#39;</span>
</span></span></code></pre></div><p>The base dictionary class has other methods that make our lives easier. Let&rsquo;s implement a few more.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">def</span> __delitem__(self, key: str):
</span></span><span style="display:flex;"><span>  path <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>get_path(key)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> os<span style="color:#f92672">.</span>path<span style="color:#f92672">.</span>exists(path):
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">raise</span> <span style="color:#a6e22e">KeyError</span>(key)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e"># If the key is a folder, recursively</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e"># remove all contents of that folder</span>
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">if</span> os<span style="color:#f92672">.</span>path<span style="color:#f92672">.</span>isdir(path):
</span></span><span style="display:flex;"><span>    shutil<span style="color:#f92672">.</span>rmtree(path)
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">return</span> <span style="color:#66d9ef">None</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e"># Otherwise, remove the file</span>
</span></span><span style="display:flex;"><span>  os<span style="color:#f92672">.</span>remove(path)
</span></span><span style="display:flex;"><span>    
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">def</span> __contains__(self, key: str) <span style="color:#f92672">-&gt;</span> bool:
</span></span><span style="display:flex;"><span>  path <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>get_path(key)
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">return</span> os<span style="color:#f92672">.</span>path<span style="color:#f92672">.</span>exists(path)
</span></span><span style="display:flex;"><span>    
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">keys</span>(self) <span style="color:#f92672">-&gt;</span> List[str]:
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">assert</span> self<span style="color:#f92672">.</span>base_directory <span style="color:#f92672">is</span> <span style="color:#f92672">not</span> <span style="color:#66d9ef">None</span>
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">return</span> os<span style="color:#f92672">.</span>listdir(self<span style="color:#f92672">.</span>base_directory)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">def</span> __repr__(self) <span style="color:#f92672">-&gt;</span> str:
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">return</span> <span style="color:#e6db74">f</span><span style="color:#e6db74">&#34;FSDict(base_directory=</span><span style="color:#e6db74">{</span>self<span style="color:#f92672">.</span>base_directory<span style="color:#e6db74">}</span><span style="color:#e6db74">)&#34;</span>
</span></span></code></pre></div><p>Extending our last example, this gives us:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#75715e"># Show all keys</span>
</span></span><span style="display:flex;"><span>print(kvs<span style="color:#f92672">.</span>keys())
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Result: [&#39;name&#39;]</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Check if a key is in the key-value store</span>
</span></span><span style="display:flex;"><span>print(<span style="color:#e6db74">&#39;name&#39;</span> <span style="color:#f92672">in</span> kvs)
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Result: True</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Delete a key-value by it&#39;s key</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">del</span> kvs[<span style="color:#e6db74">&#39;name&#39;</span>]
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Check if it still exists in our key-value store</span>
</span></span><span style="display:flex;"><span>print(<span style="color:#e6db74">&#39;name&#39;</span> <span style="color:#f92672">in</span> kvs)
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Result: False</span>
</span></span></code></pre></div><h2 id="conclusion">Conclusion</h2>
<p>The class <code>FSDict</code> provides a simple way in Python to use the filesystem as a persistent key-value store. Unlike storing everything in a single file or database, we do not need special serializers or deserializers to access to data. Outside the program we can use <code>echo</code> and <code>cat</code> in our terminals to interact with the key-value store.</p>
<p>The full code is as follows:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#f92672">from</span> typing <span style="color:#f92672">import</span> List, Optional, Union
</span></span><span style="display:flex;"><span><span style="color:#f92672">import</span> os
</span></span><span style="display:flex;"><span><span style="color:#f92672">import</span> shutil
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">class</span> <span style="color:#a6e22e">FSDict</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">def</span> __init__(self, base_directory: Optional[str] <span style="color:#f92672">=</span> <span style="color:#66d9ef">None</span>):
</span></span><span style="display:flex;"><span>        self<span style="color:#f92672">.</span>base_directory: Optional[str] <span style="color:#f92672">=</span> <span style="color:#66d9ef">None</span>
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> base_directory <span style="color:#f92672">is</span> <span style="color:#f92672">not</span> <span style="color:#66d9ef">None</span>:
</span></span><span style="display:flex;"><span>            self<span style="color:#f92672">.</span>set_base_directory(base_directory)
</span></span><span style="display:flex;"><span>    
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">set_base_directory</span>(self, base_directory: str):
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">assert</span> isinstance(base_directory, str)
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> os<span style="color:#f92672">.</span>path<span style="color:#f92672">.</span>isfile(base_directory):
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">raise</span> <span style="color:#a6e22e">Exception</span>(<span style="color:#e6db74">&#34;base_directory is an existing file not a folder.&#34;</span>)
</span></span><span style="display:flex;"><span>        
</span></span><span style="display:flex;"><span>        self<span style="color:#f92672">.</span>base_directory <span style="color:#f92672">=</span> base_directory
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> os<span style="color:#f92672">.</span>path<span style="color:#f92672">.</span>exists(base_directory):
</span></span><span style="display:flex;"><span>            os<span style="color:#f92672">.</span>makedirs(base_directory)
</span></span><span style="display:flex;"><span>    
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">get_path</span>(self, key: str) <span style="color:#f92672">-&gt;</span> str:
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">assert</span> self<span style="color:#f92672">.</span>base_directory <span style="color:#f92672">is</span> <span style="color:#f92672">not</span> <span style="color:#66d9ef">None</span>
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> isinstance(key, str):
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">raise</span> <span style="color:#a6e22e">ValueError</span>(<span style="color:#e6db74">&#34;Key must be of type str&#34;</span>)
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> os<span style="color:#f92672">.</span>path<span style="color:#f92672">.</span>join(self<span style="color:#f92672">.</span>base_directory, key)
</span></span><span style="display:flex;"><span>    
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">def</span> __setitem__(self, key: str, value: Union[str, <span style="color:#e6db74">&#34;FSDict&#34;</span>]):
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">assert</span> isinstance(value, (str, FSDict)), <span style="color:#e6db74">&#34;Value must either be of type str of FSDict&#34;</span>
</span></span><span style="display:flex;"><span>        path <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>get_path(key)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> isinstance(value, FSDict):
</span></span><span style="display:flex;"><span>            value<span style="color:#f92672">.</span>set_base_directory(path)
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">return</span> <span style="color:#66d9ef">None</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>        <span style="color:#75715e"># Assuming value is a str</span>
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">with</span> open(path, <span style="color:#e6db74">&#34;w&#34;</span>) <span style="color:#66d9ef">as</span> f:
</span></span><span style="display:flex;"><span>            f<span style="color:#f92672">.</span>write(value)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">def</span> __getitem__(self, key: str) <span style="color:#f92672">-&gt;</span> Union[str, <span style="color:#e6db74">&#34;FSDict&#34;</span>]:
</span></span><span style="display:flex;"><span>        path <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>get_path(key)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> os<span style="color:#f92672">.</span>path<span style="color:#f92672">.</span>exists(path):
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">raise</span> <span style="color:#a6e22e">KeyError</span>(key)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> os<span style="color:#f92672">.</span>path<span style="color:#f92672">.</span>isdir(path):
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">return</span> FSDict(path)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>        <span style="color:#75715e"># Assume it&#39;s a file</span>
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">with</span> open(path, <span style="color:#e6db74">&#34;r&#34;</span>) <span style="color:#66d9ef">as</span> f:
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">return</span> f<span style="color:#f92672">.</span>read()
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">def</span> __delitem__(self, key: str):
</span></span><span style="display:flex;"><span>        path <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>get_path(key)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> <span style="color:#f92672">not</span> os<span style="color:#f92672">.</span>path<span style="color:#f92672">.</span>exists(path):
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">raise</span> <span style="color:#a6e22e">KeyError</span>(key)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">if</span> os<span style="color:#f92672">.</span>path<span style="color:#f92672">.</span>isdir(path):
</span></span><span style="display:flex;"><span>            shutil<span style="color:#f92672">.</span>rmtree(path)
</span></span><span style="display:flex;"><span>            <span style="color:#66d9ef">return</span> <span style="color:#66d9ef">None</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>        <span style="color:#75715e"># Assume it&#39;s a file</span>
</span></span><span style="display:flex;"><span>        os<span style="color:#f92672">.</span>remove(path)
</span></span><span style="display:flex;"><span>    
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">def</span> __contains__(self, key: str) <span style="color:#f92672">-&gt;</span> bool:
</span></span><span style="display:flex;"><span>        path <span style="color:#f92672">=</span> self<span style="color:#f92672">.</span>get_path(key)
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> os<span style="color:#f92672">.</span>path<span style="color:#f92672">.</span>exists(path)
</span></span><span style="display:flex;"><span>    
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">def</span> <span style="color:#a6e22e">keys</span>(self) <span style="color:#f92672">-&gt;</span> List[str]:
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">assert</span> self<span style="color:#f92672">.</span>base_directory <span style="color:#f92672">is</span> <span style="color:#f92672">not</span> <span style="color:#66d9ef">None</span>
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> os<span style="color:#f92672">.</span>listdir(self<span style="color:#f92672">.</span>base_directory)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">def</span> __repr__(self) <span style="color:#f92672">-&gt;</span> str:
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> <span style="color:#e6db74">f</span><span style="color:#e6db74">&#34;FSDict(base_directory=</span><span style="color:#e6db74">{</span>self<span style="color:#f92672">.</span>base_directory<span style="color:#e6db74">}</span><span style="color:#e6db74">)&#34;</span>
</span></span></code></pre></div><div class="footnotes" role="doc-endnotes">
<hr>
<ol>
<li id="fn:1">
<p>You likely want to make sure that your program is sufficiently isolated. Either by running it within it&rsquo;s own container or setting up custom permissions on the files.&#160;<a href="#fnref:1" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
</ol>
</div>
]]></content:encoded>
  <category>key-value database</category>
  <category>file system</category>
  <category>Python</category>
  
</item>
  
  <item>
  <title>Quick Lean: if-then-else statement in hypothesis</title>
  <link>https://brandonrozek.com/blog/quick-lean-if-then-else-in-hypothesis/</link>
  <pubDate>Sat, 26 Apr 2025 10:58:42 -0400</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid>https://brandonrozek.com/blog/quick-lean-if-then-else-in-hypothesis/</guid>
  <description><![CDATA[<p>When verifying proofs about code, I often end up with a hypothesis that has an if statement in it. Depending on how long it&rsquo;s been since I last used Lean, I forget how to deal with it. This is a quick post to remind me how.</p>
<p>Example:</p>
<pre tabindex="0"><code class="language-lean" data-lang="lean">example (b: Bool) (n: Nat) (H1: if b then (n = 5) else (n = 3)) : n &gt; 0 := by sorry
</code></pre><p>We want to show that for an arbitrary boolean and natural number <code>n</code>, that <code>n</code> will always be greater than zero.</p>]]></description>
  <content:encoded><![CDATA[<p>When verifying proofs about code, I often end up with a hypothesis that has an if statement in it. Depending on how long it&rsquo;s been since I last used Lean, I forget how to deal with it. This is a quick post to remind me how.</p>
<p>Example:</p>
<pre tabindex="0"><code class="language-lean" data-lang="lean">example (b: Bool) (n: Nat) (H1: if b then (n = 5) else (n = 3)) : n &gt; 0 := by sorry
</code></pre><p>We want to show that for an arbitrary boolean and natural number <code>n</code>, that <code>n</code> will always be greater than zero.</p>
<p>Note that the condition of an arbitrary if statement can take a proposition instead of a boolean. However for this to work the proposition must be <em>decidable</em>. Checking the condition of a boolean is decidable, so we&rsquo;ll use that to simplify our example.</p>
<p>From here, we use <code>by_cases (b = true)</code> to give us two new subgoals. One where it&rsquo;s true and one where it&rsquo;s false.</p>
<pre tabindex="0"><code class="language-lean" data-lang="lean">by_cases H2 : (b = true)
case pos =&gt;
  sorry
case neg =&gt;
  sorry
</code></pre><p>First let&rsquo;s consider the positive case. We can simplify <code>H1</code> to <code>n = 5</code> by using <code>H2</code> which states that <code>b</code> is true.</p>
<pre tabindex="0"><code class="language-lean" data-lang="lean">replace H1 : n = 5 := by
  rwa [if_pos (by exact H2)] at H1
</code></pre><p>For this example, you don&rsquo;t need the parenthesis saying <code>(by exact H2)</code>. However, depending on your setup the proof that <code>b</code> is true might be too difficult for the rewrite system to infer. In those cases, you are required to specify the proof for it to work.</p>
<p>Then, we can substitute <code>n</code> to have our subgoal as <code>5 &gt; 0</code>.</p>
<pre tabindex="0"><code class="language-lean" data-lang="lean">subst n
</code></pre><p>This is the same as showing that <code>0 &lt; 5</code>.</p>
<pre tabindex="0"><code class="language-lean" data-lang="lean">suffices 0 &lt; 5 by exact gt_iff_lt.mpr this
</code></pre><p>From here we can apply one of the builtin theorems</p>
<pre tabindex="0"><code class="language-lean" data-lang="lean">exact Nat.zero_lt_succ 4
</code></pre><p>For the negative case, we will follow a similar pattern except instead of invoking <code>if_pos</code> to eliminate the if-statement, we will invoke <code>if_neg</code>.</p>
<p>Thus, the complete proof for this is</p>
<pre tabindex="0"><code class="language-lean" data-lang="lean">example (b : Bool) (n : Nat) (H1: if b then (n = 5) else (n = 3)) : n &gt; 0 := by
  by_cases H2 : (b = true)
  case pos =&gt;
    replace H1 : n = 5 := by
      rwa [if_pos (by exact H2)] at H1
    subst n
    suffices 0 &lt; 5 by exact gt_iff_lt.mpr this
    exact Nat.zero_lt_succ 4
  case neg =&gt;
    replace H1 : n = 3 := by
      rwa [if_neg (by exact H2)] at H1
    subst n
    suffices 0 &lt; 3 by exact gt_iff_lt.mpr this
    exact Nat.zero_lt_succ 2
</code></pre>]]></content:encoded>
  <category>Lean</category>
  <category>Proof assistant</category>
  
</item>
  
  <item>
  <title>10 Years</title>
  <link>https://brandonrozek.com/blog/10-years/</link>
  <pubDate>Wed, 16 Apr 2025 12:13:29 -0400</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid>https://brandonrozek.com/blog/10-years/</guid>
  <description><![CDATA[<p>On April 16 2015, I wrote my first two <a href="/blog/2015-04-16-function-two-points-theory/">blog</a> <a href="/blog/2015-04-16-responsive-layout-and-animation/">posts</a> on creating responsive layouts in CSS. It&rsquo;s crazy to think that I still have this blog going after 10 years. Since then I&rsquo;ve lived in 9 different places, worked at 6 different organizations, and got to meet many wonderful people including my now fiance.</p>
<p>I thought it would be nice to look back over the last ten years, and talk about my favorite blog posts of each year. What I&rsquo;ve come to realize in this exercise is that I really came a long way. I mean, it&rsquo;s not that hard to beat my first blog post where I just scanned a sheet of paper!</p>]]></description>
  <content:encoded><![CDATA[<p>On April 16 2015, I wrote my first two <a href="/blog/2015-04-16-function-two-points-theory/">blog</a> <a href="/blog/2015-04-16-responsive-layout-and-animation/">posts</a> on creating responsive layouts in CSS. It&rsquo;s crazy to think that I still have this blog going after 10 years. Since then I&rsquo;ve lived in 9 different places, worked at 6 different organizations, and got to meet many wonderful people including my now fiance.</p>
<p>I thought it would be nice to look back over the last ten years, and talk about my favorite blog posts of each year. What I&rsquo;ve come to realize in this exercise is that I really came a long way. I mean, it&rsquo;s not that hard to beat my first blog post where I just scanned a sheet of paper!</p>
<p><em>Disclaimer:</em> Posts before mid-2019 were on WordPress, and let&rsquo;s just say that the migration to Hugo hasn&rsquo;t been perfect&hellip;</p>
<h2 id="2015">2015</h2>
<p><strong>Favorite Post:</strong> <a href="/blog/2015-11-30-limiting-cache-service-workers-revisited3/">Limiting the cache in Service Workers Revisited</a></p>
<p>Service workers was one of the first ways you can have persistent background processing on a website. From my memory, the big use case was that you can get social media notifications without even having the tab open.  I&rsquo;m not sure how, but I ended up on the bleeding edge of this since it was first fully released on Chrome without a feature flag September 2015.</p>
<p>While we all love getting notifications, a more interesting use case to us in the blogging community was that you can use service workers to make your website available offline! I wrote about <a href="/blog/2015-11-14-service-workers/">how to do so</a> and then wrote this update a few weeks later to help address a <a href="https://adactio.com/journal/9844">caching</a> <a href="https://adactio.com/journal/9888">issue</a> that Jeremy Keith identified.</p>
<h2 id="2016">2016</h2>
<p><strong>Favorite Post:</strong> <a href="/blog/2016-08-16-pass-password-manager/">Pass the password manager</a></p>
<p>This is the only blog post I wrote in 2016 so it wins by default. At the time, I used the CLI application <a href="https://www.passwordstore.org/"><code>pass</code></a> to manage my passwords and <a href="https://syncthing.net/">Syncthing</a> to share it between devices. Nowadays, I entrust <a href="https://bitwarden.com/">Bitwarden</a> when it comes to handling my passwords.</p>
<h2 id="2017">2017</h2>
<p><strong>Favorite Post:</strong> <a href="/blog/2017-03-14-monte-carlo-pi/">Approximating Pi using a Monte Carlo Simulation</a></p>
<p>2017 was the year that I got really into statistics and approximation. Not only was I approximating Pi like above, but I was also testing the <a href="https://brandonrozek.com/blog/2017-03-07-uniformity-math-random/">randomness of random number generators</a>, looking at <a href="https://brandonrozek.com/blog/male-vs-female-life-expectancy/">male vs female life expectancy</a>, and building a regression model of the <a href="https://brandonrozek.com/blog/albuquerque/">price of homes in Albuquerque, New Mexico</a>.</p>
<p>Nowadays I don&rsquo;t work with Statistics as often. However, I do think it&rsquo;s cool how we can come up with models to attempt to describe how the world works even when we don&rsquo;t have much data available.</p>
<p>Also being able to make approximations with <a href="/research/reinforcementlearning/notes/mcmethods/">Monte-Carlo methods</a>, and resampling techniques like <a href="https://github.com/Brandon-Rozek/bootstrapr">bootstrapping</a> is awesome.</p>
<h2 id="2018">2018</h2>
<p><strong>Favorite Post:</strong> <a href="/blog/2018-01-22-identifying-misspelled-words-dataset-hunspell/">Identifying Misspelled Words in your Dataset with Hunspell</a></p>
<p>Similar to 2016, this is the winner by default since it&rsquo;s the only blog post I wrote that year. I&rsquo;m happy that I don&rsquo;t currently have to deal with data cleaning.</p>
<h2 id="2019">2019</h2>
<p><strong>Favorite Post:</strong>  <a href="/blog/ctf/">Capture The Flag</a></p>
<p>From this point on, it only gets harder for me to select my favorite! For the first four years I only wrote 30 blog posts total. In the year 2019, I wrote 60! If I had to chose, my favorite would be when I briefly described the challenges I made for a capture the flag competition during my undergraduate days. I also really enjoyed encoding <a href="/blog/pythonsymmetricgroups/">mathematical</a> <a href="/blog/haskellrealsequences/">problems</a> in code.</p>
<h2 id="2020">2020</h2>
<p><strong>Favorite Post:</strong> <a href="https://brandonrozek.com/blog/discgolfpymc/">Disk Golf and PyMC3</a></p>
<p>Somehow in 2020 I wrote 128 blog posts. Many of them are short tidbits of things I&rsquo;ve learned. But still, that&rsquo;s almost a blog post every 3 days! According to my <a href="/stats">stats page</a> this is the current record of blog posts per year by far. We&rsquo;ll see if I ever beat this record.</p>
<p>My favorite out of this batch is a blog post that&rsquo;s a combination of personal life and statistics. In a semi-competitive semi-joking way, I wanted to determine who was the best at disk golf between Clare, Chris, and I based on just one outing. After performing some Bayesian magic, I found that Chris and I pretty much have the same performance (ignore the 0.2 score difference) and Clare is sadly worse than the both of us.</p>
<p>Other great pieces that year was my blog post on <a href="/blog/cryptogames/">Cryptographic Games</a> and <a href="/blog/tcopython/">Tail call optimization in Python</a>.</p>
<h2 id="2021">2021</h2>
<p><strong>Favorite Post:</strong> <a href="/blog/introrfpoweramp/">Introduction to RF Power Amplifiers</a></p>
<p>Before I stopped actively pursuing Amateur radio, I wanted to write some notes in case I ever get back into the hobby. Turns out, radio waves are based on electricity and life is a lot easier if you have an electrical engineering degree to understand all of the terminology used.</p>
<p>That doesn&rsquo;t mean you need a degree to get in the hobby though! In the US, you&rsquo;ll need to at least have a technicians license to get on the air and luckily all the questions and answers for the exam are <a href="https://hamexam.org/">available online</a>. After getting licensed, you can pick up a UHF/VHF radio for $20 and chat with anybody on a <a href="https://www.repeaterbook.com/repeaters/">local repeater</a>.</p>
<p>Though the reason I got into the hobby is that it can be as complicated as you want. At the time I was highly interested in digital modes and software defined radios. This blog post came about as I was trying to figure out what I needed to buy for the annual <a href="https://en.wikipedia.org/wiki/Field_Day_%28amateur_radio%29">Amateur Radio Field Day</a>.</p>
<h2 id="2022">2022</h2>
<p><strong>Favorite Post:</strong> <a href="/blog/finding-cool-people-on-mastodon/">Finding Cool People on Mastodon</a></p>
<p>On August 2022, I joined Mastodon and like all new people had to figure out where all the cool folks are. I&rsquo;m not often on Mastodon nowadays, but it&rsquo;s awesome that an open-source microblogging platform has gotten popular.</p>
<p>This was also the year I introduced the <a href="/tracks">tracks</a> feature on my website. I really enjoy going on walks, and having a section of my website that shows where I walked and the pictures along the way is wicked cool. I fully described the implementation of this feature in the post <a href="/blog/displaying-hikes-with-gpxstudio/">Displaying Hikes with gpx.studio</a>.</p>
<p>Lastly, professionally I was a teaching assistant. A couple of posts were born from seeing student mistakes. My favorites were <a href="/blog/proving-loop-invariants/">Loop Invariants in Dafny</a> and <a href="/blog/common-mistake-induction-proofs/">Most Common Mistake in Induction Proofs</a>.</p>
<h2 id="2023">2023</h2>
<p><strong>Favorite Post:</strong> <a href="/blog/adventures-in-bird-watching/">Adventures in Bird Watching</a></p>
<p>In 2021 I wrote a blog post comparing different RF power amplifiers. Similarly in 2023, I wrote about what considerations you need to make when buying binoculars for bird watching. I never fully got into bird watching as a hobby, but I encourage you to go on a bird tour at least once if you&rsquo;re able. It&rsquo;s fun to learn about the birds that fly above you and live in the trees near you.</p>
<p>I don&rsquo;t often give glimpses of my life, but I shared a <a href="/blog/day-in-brooklyn/">trip to Brooklyn</a> that Clare and I did with my brother.  In terms of more technical posts, I wrote about <a href="/blog/functional-completeness/">functional completeness</a> and an alternative way of <a href="/blog/representing-uncertainty-closed-world-assumption/">representing uncertainty under the closed world assumption</a>.</p>
<p>Since I work on multiple devices, I make more merge conflicts than I like to admit. I wrote a small script to tell me whether the git repository I&rsquo;m working on is <a href="/blog/ahead-behind-git/">ahead or behind</a> the remote one. Lastly, for many years I&rsquo;ve used Syncthing to synchronize my files between my devices. By default it uses public relays and public discovery services, however, I run my own servers so why not use that instead? I describe my setup in the blog post <a href="/blog/private-syncthing-network/">How to set up a private syncthing network</a>.</p>
<h2 id="2024">2024</h2>
<p><strong>Favorite Post:</strong> <a href="/blog/hashing-based-on-word-emoji-lists/">Hashing Based on Word (Emoji?) Lists</a></p>
<p>In contrast to what I said in the <a href="/blog/blog-question-challenge-jan2025/">blog questions challenge</a>, my favorite blog post last year was one where I wrote a hash function based on an Emoji list. I don&rsquo;t use emojis nearly enough in my daily life and there&rsquo;s more than 5042 of them to chose from!</p>
<p>Winters here in New York is cold and I often don&rsquo;t want to go outside. One of the events I look forward to is watching my university&rsquo;s hockey games. Therefore, a close second place for last year is when I wrote about my <a href="/blog/ice-hockey/">experience watching ice hockey</a>. Another yearly tradition of Clare and I is to go <a href="/blog/hunter-gathering-apple-picking/">Apple Picking</a> in the fall.</p>
<p>In terms of software, I wrote about a way you can <a href="/blog/accessing-homelab-services-mtls/">access your homelab remotely using mTLS</a>. Also, I really appreciate the mission of the <a href="/blog/tildeverse/">Tildeverse</a> and last year wrote <a href="/blog/wordguess/">WordGuess: A game for the Tildeverse</a>. Lastly, my favorite writeup related to my research last year is <a href="/blog/safety-constraints-pddl/">Constraints and Safety in PDDL</a></p>
<h2 id="conclusion">Conclusion</h2>
<p>That&rsquo;s a wrap! We&rsquo;re too early in the year 2025 for me to pick, as I&rsquo;ve only written five blog posts so far.</p>
<p>Here&rsquo;s to another 10 years and as always feel <a href="/contact/">free to get in touch</a>.</p>
]]></content:encoded>
  
</item>
  
  <item>
  <title></title>
  <link></link>
  <pubDate>Tue, 15 Apr 2025 03:12:42 +0000</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid></guid>
  <description><![CDATA[<p><span class="h-card" translate="no"><a href="https://universeodon.com/@p" class="u-url mention">@<span>p</span></a></span> Thanks! Let me know once you have it up so that I can check it out :)</p>]]></description>
  <content:encoded><![CDATA[<p><span class="h-card" translate="no"><a href="https://universeodon.com/@p" class="u-url mention">@<span>p</span></a></span> Thanks! Let me know once you have it up so that I can check it out :)</p>]]></content:encoded>
  
</item>
  
  <item>
  <title>Recently: April Showers Bring...</title>
  <link>https://brandonrozek.com/blog/recently-2504-april-showers/</link>
  <pubDate>Sat, 12 Apr 2025 10:38:45 -0400</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid>https://brandonrozek.com/blog/recently-2504-april-showers/</guid>
  <description><![CDATA[<p>I woke up this morning to a small layer of snow outside. In the Northeastern part of the United States, it&rsquo;s said that we have <a href="https://12seasons.nyc/">12 seasons</a>.</p>
<ul>
<li>Winter</li>
<li>Fool&rsquo;s Spring</li>
<li>Second Winter</li>
<li>Spring of Deception</li>
<li>Third Winter</li>
<li>The Pollening</li>
<li>Actual Spring</li>
<li>Summer</li>
<li>Hell&rsquo;s Front Porch</li>
<li>False Fall</li>
<li>Second Summer</li>
<li>Actual Fall</li>
</ul>
<p>At the time of this post, we&rsquo;re at &ldquo;Third Winter&rdquo;. I look forward to warm weather again soon.</p>
<hr>
<p><em>Homelab Updates!</em></p>]]></description>
  <content:encoded><![CDATA[<p>I woke up this morning to a small layer of snow outside. In the Northeastern part of the United States, it&rsquo;s said that we have <a href="https://12seasons.nyc/">12 seasons</a>.</p>
<ul>
<li>Winter</li>
<li>Fool&rsquo;s Spring</li>
<li>Second Winter</li>
<li>Spring of Deception</li>
<li>Third Winter</li>
<li>The Pollening</li>
<li>Actual Spring</li>
<li>Summer</li>
<li>Hell&rsquo;s Front Porch</li>
<li>False Fall</li>
<li>Second Summer</li>
<li>Actual Fall</li>
</ul>
<p>At the time of this post, we&rsquo;re at &ldquo;Third Winter&rdquo;. I look forward to warm weather again soon.</p>
<hr>
<p><em>Homelab Updates!</em></p>
<p><strong>Nextcloud:</strong> I moved away from the Nextcloud all-in-one and instead maintain a LXC container. Unfortunately for me, the all-in-one was too much of a black box. My current deployment is significantly less stateless, but I understand it better.</p>
<p>While I was doing that, I&rsquo;ve been exploring use-cases for MinIO so I thought maybe I&rsquo;ll try <a href="https://docs.nextcloud.com/server/latest/admin_manual/configuration_files/primary_storage.html">configuring my object storage as the primary storage</a>. However, I neglected to read the third paragraph&hellip;</p>
<blockquote>
<p>All metadata (filenames, directory structures, etc) is stored in Nextcloud and not in the object store</p></blockquote>
<p>This makes performing backups significantly harder! So, I switched back to the normal filesystem backend for Nextcloud.</p>
<p><strong>Immich:</strong> Multiple people have told me that Immich is the way to go for viewing your photos. Previously, I was scared to try it out because of the banner at the top of their page.</p>
<blockquote>
<p>The project is under <strong>very active</strong> development. Expect bugs and changes. Do not use it as <strong>the only way</strong> to store your photos and videos.</p></blockquote>
<p>However, I have backups so what am I afraid of?</p>
<p>I have to say, the setup was flawless. The software is not buggy at all, and everything is snappy and works as expected.</p>
<p>To import my photos, I mounted my existing directory on a <em>different</em> mountpoint than the one Immich uses to store files.</p>
<p>Example Docker-Compose Configuration</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#f92672">immich-server</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">container_name</span>: <span style="color:#ae81ff">immich_server</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">image</span>: <span style="color:#ae81ff">ghcr.io/immich-app/immich-server:release</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">env_file</span>:
</span></span><span style="display:flex;"><span>    - <span style="color:#ae81ff">/etc/immich/immich.env</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">volumes</span>:
</span></span><span style="display:flex;"><span>    - <span style="color:#ae81ff">/home/user/immich/pictures:/usr/src/app/upload</span>
</span></span><span style="display:flex;"><span>    - <span style="color:#ae81ff">/home/user/storage/pictures:/pictures:ro</span> <span style="color:#75715e"># Existing photo library</span>
</span></span><span style="display:flex;"><span>    - <span style="color:#ae81ff">/etc/localtime:/etc/localtime:ro</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">depends_on</span>:
</span></span><span style="display:flex;"><span>    - <span style="color:#ae81ff">immich-redis</span>
</span></span><span style="display:flex;"><span>    - <span style="color:#ae81ff">immich-database</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">restart</span>: <span style="color:#ae81ff">unless-stopped</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Copy immich-redis and immich-database from the Github repo</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># ...</span>
</span></span></code></pre></div><p>Then I had to log onto the Immich webapp to create a user and an API key. After that, we can  <code>exec</code> into the container.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>docker exec -it immich_server /bin/bash
</span></span></code></pre></div><p>Login with the API key</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>immich login http://localhost:2283/api &lt;APIKEY&gt;
</span></span></code></pre></div><p>Then upload the photos</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>immich upload --recursive /pictures
</span></span></code></pre></div><p><em>Warning:</em> You need enough space to have two copies of your photos. If you don&rsquo;t then you&rsquo;ll need to iteratively upload and delete as you go instead of doing this all at once.</p>
<p>After a bit, you should see thumbnails on the app!</p>
<p><strong>Music Streaming:</strong> Since I listen to Japanese music, not all music services work for me. Currently I pay for YT Music, though I&rsquo;ve been slowly trying to buy albums directly from Qobuz to (1) better support the artists, and (2) guarantee that it won&rsquo;t disappear from my library. This is only recent, so I don&rsquo;t fully endorse my workflow, but it&rsquo;s been working so far and I think it&rsquo;s great.</p>
<ol>
<li>Buy flac from <a href="https://www.qobuz.com/us-en/shop">Qobuz</a></li>
<li>Transfer the files to my home server</li>
<li>Run <a href="https://beets.io/"><code>beet import</code></a> to copy the music into my library with all the metadata sorted out.</li>
<li>Use <a href="https://www.navidrome.org/">Navidrome</a>, an open-source server software, to provide a subsonic API to stream the music.
<ul>
<li>It even transcodes on the fly for you if your device doesn&rsquo;t support the format it&rsquo;s stored in.</li>
</ul>
</li>
<li>Use <a href="https://symfonium.app/">Symfonium</a> on Android as my music app and set it to search for music on my Navidrome server.</li>
</ol>
<p>Both Immich and setting up this music streaming is very new to me! So if you have any suggestions or comments about your workflow feel free to reach out :)</p>
]]></content:encoded>
  <category>homelab</category>
  
</item>
  
  <item>
  <title>A Modal Logic of Optimality (Student Abstract) </title>
  <link>https://brandonrozek.com/paper/2504.01/</link>
  <pubDate>Fri, 11 Apr 2025 00:00:00 +0000</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid>https://brandonrozek.com/paper/2504.01/</guid>
  <description><![CDATA[]]></description>
  <content:encoded><![CDATA[]]></content:encoded>
  
</item>
  
  <item>
  <title>Setting up Ollama with CUDA on Podman Quadlets</title>
  <link>https://brandonrozek.com/blog/ollama-cuda-podman-quadlets/</link>
  <pubDate>Sat, 29 Mar 2025 09:59:55 -0400</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid>https://brandonrozek.com/blog/ollama-cuda-podman-quadlets/</guid>
  <description><![CDATA[<p><a href="https://www.openwebui.com/">Open WebUI</a> provides a nice chat interface for interacting with LLMs over Ollama and OpenAI compatible APIs. Using <a href="https://ollama.com/">Ollama</a>, we can self-host many different LLMs that are open-sourced! This post documents the steps that I took in order to get Ollama working with CUDA using my Podman setup. However given how fast Machine Learning projects iterate, I wouldn&rsquo;t be surprised if these exact steps no longer work.  In that case, I&rsquo;ll provide links to the official documentation which hopefully can help.</p>]]></description>
  <content:encoded><![CDATA[<p><a href="https://www.openwebui.com/">Open WebUI</a> provides a nice chat interface for interacting with LLMs over Ollama and OpenAI compatible APIs. Using <a href="https://ollama.com/">Ollama</a>, we can self-host many different LLMs that are open-sourced! This post documents the steps that I took in order to get Ollama working with CUDA using my Podman setup. However given how fast Machine Learning projects iterate, I wouldn&rsquo;t be surprised if these exact steps no longer work.  In that case, I&rsquo;ll provide links to the official documentation which hopefully can help.</p>
<p>I&rsquo;ll assume that you have the NVIDIA driver installed on your machine. The steps vary by OS/distribution and how modern of a driver you want, but I generally recommend to stick with what&rsquo;s packaged in your distribution&rsquo;s repository. This is to minimize headaches&hellip;</p>
<p>With that, our first step is to install the <code>nvidia-container-toolkit</code>.  This package contains a collection of libraries and scripts to help us run our GPU inside a container.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>sudo dnf install nvidia-container-toolkit
</span></span></code></pre></div><p>As of this time of writing, instructions for installing the toolkit can be found on <a href="https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html">NVIDIA&rsquo;s website</a>.</p>
<p>We can use this toolkit to generate a Common Device Interface (CDI) file which Podman will use to talk to the GPU.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>sudo nvidia-ctk cdi generate --output<span style="color:#f92672">=</span>/etc/cdi/nvidia.yaml
</span></span></code></pre></div><p><strong>Note:</strong> Every time you update your NVIDIA driver, you&rsquo;ll have to run this command.</p>
<p>NVIDIA also documents the steps for configuring CDI on <a href="https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/cdi-support.html#running-a-workload-with-cdi">their website</a>.</p>
<p>From here, we should make sure that the NVIDIA toolkit found the appropriate GPU(s) and has set up their CDI.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>nvidia-ctk cdi list
</span></span></code></pre></div><p>I only have one GPU on my machine, so it outputs something like the following:</p>
<pre tabindex="0"><code>INFO[0000] Found 3 CDI devices                          
nvidia.com/gpu=0
nvidia.com/gpu=GPU-52785a8a-f8ca-99b9-0312-01a1f59e789b
nvidia.com/gpu=all
</code></pre><p>If you want your container to be able to access all the GPUs, we can use the <code>nvidia.com/gpu=all</code> device interface. Otherwise, we can use a specific one.</p>
<p>Then, we restart Podman so that the CDI files are loaded.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>sudo systemctl restart podman
</span></span></code></pre></div><p>For our first test, we&rsquo;ll make sure that the container can appropriately access the GPU by running the <code>nvidia-smi</code> command.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>sudo podman run --rm <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>	--device nvidia.com/gpu<span style="color:#f92672">=</span>all <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>	docker.io/nvidia/cuda:11.0.3-base-ubuntu20.04 <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>	nvidia-smi
</span></span></code></pre></div><p>For my GPU it outputs:</p>
<pre tabindex="0"><code>+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 570.124.04             Driver Version: 570.124.04     CUDA Version: 12.8     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GeForce RTX 3060        Off |   00000000:02:00.0  On |                  N/A |
|  0%   50C    P8             19W /  170W |    1546MiB /  12288MiB |      0%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+
                                                                                         
+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI              PID   Type   Process name                        GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
+-----------------------------------------------------------------------------------------+
</code></pre><p>Now we are ready to set up Ollama! To save time when running our <code>systemd</code> commands, let&rsquo;s pull the image ahead of time.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>sudo podman pull docker.io/ollama/ollama
</span></span></code></pre></div><p>We&rsquo;ll have to save the models somewhere, so in this example we&rsquo;ll save them to <code>/opt/ollama</code>.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>sudo mkdir /opt/ollama
</span></span></code></pre></div><p>Let&rsquo;s configure the Quadlet. Save the following to <code>/etc/containers/systemd/ollama.container</code>:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ini" data-lang="ini"><span style="display:flex;"><span><span style="color:#66d9ef">[Container]</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">ContainerName</span><span style="color:#f92672">=</span><span style="color:#e6db74">ollama</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">HostName</span><span style="color:#f92672">=</span><span style="color:#e6db74">ollama</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">Image</span><span style="color:#f92672">=</span><span style="color:#e6db74">docker.io/ollama/ollama</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">AutoUpdate</span><span style="color:#f92672">=</span><span style="color:#e6db74">registry</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">Volume</span><span style="color:#f92672">=</span><span style="color:#e6db74">/opt/ollama:/root/.ollama</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">PublishPort</span><span style="color:#f92672">=</span><span style="color:#e6db74">11434:11434</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">AddDevice</span><span style="color:#f92672">=</span><span style="color:#e6db74">nvidia.com/gpu=all</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">[Unit]</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">[Service]</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">Restart</span><span style="color:#f92672">=</span><span style="color:#e6db74">always</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">[Install]</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">WantedBy</span><span style="color:#f92672">=</span><span style="color:#e6db74">default.target</span>
</span></span></code></pre></div><p>This file specifies the flags that we pass to the podman command:</p>
<ul>
<li>Publish the port 11434: This is the port we&rsquo;ll use when sending messages to Ollama from Open WebUI. Of course you&rsquo;re welcome to use other networking tricks to pull that off.</li>
<li>Mount the folder <code>/opt/ollama</code> on the filesystem to <code>/root/.ollama</code> within the container: We don&rsquo;t want to have to re-download the LLM models each time!</li>
</ul>
<p>For the moment of truth, let&rsquo;s start it!</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>sudo systemctl start ollama
</span></span></code></pre></div><p>I won&rsquo;t show in this post how to configure Open WebUI, but we can make sure that everything is working by looking at the Ollama container itself.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>sudo podman exec -it ollama /bin/bash
</span></span></code></pre></div><p>We&rsquo;ll perform a test with a smaller model (1.2 GB):</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>ollama run llama3.2:1b
</span></span></code></pre></div><p>Depending on your Internet connection, this will take a couple minutes to download and load onto the GPU.</p>
<p>When it&rsquo;s done the prompt will be replaced with:</p>
<pre tabindex="0"><code>&gt;&gt;&gt; 
</code></pre><p>From here you can chat with the LLM!</p>
]]></content:encoded>
  <category>Ollama</category>
  <category>Podman</category>
  <category>CUDA</category>
  
</item>
  
  <item>
  <title>Weather Forcecasts on the Command-Line with the National Weather Service API</title>
  <link>https://brandonrozek.com/blog/weather-forcecasts-cli-nws/</link>
  <pubDate>Sun, 16 Mar 2025 15:33:49 -0400</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid>https://brandonrozek.com/blog/weather-forcecasts-cli-nws/</guid>
  <description><![CDATA[<p>The United States National Weather Service (NWS) has a <a href="https://www.weather.gov/documentation/services-web-api">JSON API</a> which provides weather alerts and forecasts for free without having to create an API key<sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup>. We&rsquo;ll use this resource to write a small bash script which gives today and tomorrow&rsquo;s weather forecast given a latitude and longitude.</p>
<p>My goal is to have a small bash script which I can run in the terminal to get the forecast information. We&rsquo;ll use <a href="https://jqlang.org/"><code>jq</code></a> for handling the JSON data.</p>]]></description>
  <content:encoded><![CDATA[<p>The United States National Weather Service (NWS) has a <a href="https://www.weather.gov/documentation/services-web-api">JSON API</a> which provides weather alerts and forecasts for free without having to create an API key<sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup>. We&rsquo;ll use this resource to write a small bash script which gives today and tomorrow&rsquo;s weather forecast given a latitude and longitude.</p>
<p>My goal is to have a small bash script which I can run in the terminal to get the forecast information. We&rsquo;ll use <a href="https://jqlang.org/"><code>jq</code></a> for handling the JSON data.</p>
<p>The NWS API does not provide the forecast directly given a latitude and longitude coordinates. Instead, we need to provide the specific <a href="https://www.weather.gov/srh/nwsoffices">Weather Forecast Office (WFO)</a> responsible for that area plus their grid definitions for the latitude and longitude coordinate.</p>
<p>Luckily, we can query for that information as well.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>POINTS<span style="color:#f92672">=</span><span style="color:#66d9ef">$(</span>curl -Ls <span style="color:#e6db74">&#34;https://api.weather.gov/points/</span>$LAT<span style="color:#e6db74">,</span>$LON<span style="color:#e6db74">&#34;</span><span style="color:#66d9ef">)</span>
</span></span></code></pre></div><details><summary>For 42.7289, -73.6915 it returns:</summary>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&#34;@context&#34;</span>: [
</span></span><span style="display:flex;"><span>        <span style="color:#e6db74">&#34;https://geojson.org/geojson-ld/geojson-context.jsonld&#34;</span>,
</span></span><span style="display:flex;"><span>        {
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">&#34;@version&#34;</span>: <span style="color:#e6db74">&#34;1.1&#34;</span>,
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">&#34;wx&#34;</span>: <span style="color:#e6db74">&#34;https://api.weather.gov/ontology#&#34;</span>,
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">&#34;s&#34;</span>: <span style="color:#e6db74">&#34;https://schema.org/&#34;</span>,
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">&#34;geo&#34;</span>: <span style="color:#e6db74">&#34;http://www.opengis.net/ont/geosparql#&#34;</span>,
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">&#34;unit&#34;</span>: <span style="color:#e6db74">&#34;http://codes.wmo.int/common/unit/&#34;</span>,
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">&#34;@vocab&#34;</span>: <span style="color:#e6db74">&#34;https://api.weather.gov/ontology#&#34;</span>,
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">&#34;geometry&#34;</span>: {
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;@id&#34;</span>: <span style="color:#e6db74">&#34;s:GeoCoordinates&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;@type&#34;</span>: <span style="color:#e6db74">&#34;geo:wktLiteral&#34;</span>
</span></span><span style="display:flex;"><span>            },
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">&#34;city&#34;</span>: <span style="color:#e6db74">&#34;s:addressLocality&#34;</span>,
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">&#34;state&#34;</span>: <span style="color:#e6db74">&#34;s:addressRegion&#34;</span>,
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">&#34;distance&#34;</span>: {
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;@id&#34;</span>: <span style="color:#e6db74">&#34;s:Distance&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;@type&#34;</span>: <span style="color:#e6db74">&#34;s:QuantitativeValue&#34;</span>
</span></span><span style="display:flex;"><span>            },
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">&#34;bearing&#34;</span>: {
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;@type&#34;</span>: <span style="color:#e6db74">&#34;s:QuantitativeValue&#34;</span>
</span></span><span style="display:flex;"><span>            },
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">&#34;value&#34;</span>: {
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;@id&#34;</span>: <span style="color:#e6db74">&#34;s:value&#34;</span>
</span></span><span style="display:flex;"><span>            },
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">&#34;unitCode&#34;</span>: {
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;@id&#34;</span>: <span style="color:#e6db74">&#34;s:unitCode&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;@type&#34;</span>: <span style="color:#e6db74">&#34;@id&#34;</span>
</span></span><span style="display:flex;"><span>            },
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">&#34;forecastOffice&#34;</span>: {
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;@type&#34;</span>: <span style="color:#e6db74">&#34;@id&#34;</span>
</span></span><span style="display:flex;"><span>            },
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">&#34;forecastGridData&#34;</span>: {
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;@type&#34;</span>: <span style="color:#e6db74">&#34;@id&#34;</span>
</span></span><span style="display:flex;"><span>            },
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">&#34;publicZone&#34;</span>: {
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;@type&#34;</span>: <span style="color:#e6db74">&#34;@id&#34;</span>
</span></span><span style="display:flex;"><span>            },
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">&#34;county&#34;</span>: {
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;@type&#34;</span>: <span style="color:#e6db74">&#34;@id&#34;</span>
</span></span><span style="display:flex;"><span>            }
</span></span><span style="display:flex;"><span>        }
</span></span><span style="display:flex;"><span>    ],
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&#34;id&#34;</span>: <span style="color:#e6db74">&#34;https://api.weather.gov/points/42.7289,-73.6915&#34;</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&#34;type&#34;</span>: <span style="color:#e6db74">&#34;Feature&#34;</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&#34;geometry&#34;</span>: {
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&#34;type&#34;</span>: <span style="color:#e6db74">&#34;Point&#34;</span>,
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&#34;coordinates&#34;</span>: [
</span></span><span style="display:flex;"><span>            <span style="color:#ae81ff">-73.6915</span>,
</span></span><span style="display:flex;"><span>            <span style="color:#ae81ff">42.7289</span>
</span></span><span style="display:flex;"><span>        ]
</span></span><span style="display:flex;"><span>    },
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&#34;properties&#34;</span>: {
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&#34;@id&#34;</span>: <span style="color:#e6db74">&#34;https://api.weather.gov/points/42.7289,-73.6915&#34;</span>,
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&#34;@type&#34;</span>: <span style="color:#e6db74">&#34;wx:Point&#34;</span>,
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&#34;cwa&#34;</span>: <span style="color:#e6db74">&#34;ALY&#34;</span>,
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&#34;forecastOffice&#34;</span>: <span style="color:#e6db74">&#34;https://api.weather.gov/offices/ALY&#34;</span>,
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&#34;gridId&#34;</span>: <span style="color:#e6db74">&#34;ALY&#34;</span>,
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&#34;gridX&#34;</span>: <span style="color:#ae81ff">74</span>,
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&#34;gridY&#34;</span>: <span style="color:#ae81ff">67</span>,
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&#34;forecast&#34;</span>: <span style="color:#e6db74">&#34;https://api.weather.gov/gridpoints/ALY/74,67/forecast&#34;</span>,
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&#34;forecastHourly&#34;</span>: <span style="color:#e6db74">&#34;https://api.weather.gov/gridpoints/ALY/74,67/forecast/hourly&#34;</span>,
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&#34;forecastGridData&#34;</span>: <span style="color:#e6db74">&#34;https://api.weather.gov/gridpoints/ALY/74,67&#34;</span>,
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&#34;observationStations&#34;</span>: <span style="color:#e6db74">&#34;https://api.weather.gov/gridpoints/ALY/74,67/stations&#34;</span>,
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&#34;relativeLocation&#34;</span>: {
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">&#34;type&#34;</span>: <span style="color:#e6db74">&#34;Feature&#34;</span>,
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">&#34;geometry&#34;</span>: {
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;type&#34;</span>: <span style="color:#e6db74">&#34;Point&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;coordinates&#34;</span>: [
</span></span><span style="display:flex;"><span>                    <span style="color:#ae81ff">-73.707011</span>,
</span></span><span style="display:flex;"><span>                    <span style="color:#ae81ff">42.724883</span>
</span></span><span style="display:flex;"><span>                ]
</span></span><span style="display:flex;"><span>            },
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">&#34;properties&#34;</span>: {
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;city&#34;</span>: <span style="color:#e6db74">&#34;Watervliet&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;state&#34;</span>: <span style="color:#e6db74">&#34;NY&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;distance&#34;</span>: {
</span></span><span style="display:flex;"><span>                    <span style="color:#f92672">&#34;unitCode&#34;</span>: <span style="color:#e6db74">&#34;wmoUnit:m&#34;</span>,
</span></span><span style="display:flex;"><span>                    <span style="color:#f92672">&#34;value&#34;</span>: <span style="color:#ae81ff">1343.4228258697</span>
</span></span><span style="display:flex;"><span>                },
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;bearing&#34;</span>: {
</span></span><span style="display:flex;"><span>                    <span style="color:#f92672">&#34;unitCode&#34;</span>: <span style="color:#e6db74">&#34;wmoUnit:degree_(angle)&#34;</span>,
</span></span><span style="display:flex;"><span>                    <span style="color:#f92672">&#34;value&#34;</span>: <span style="color:#ae81ff">70</span>
</span></span><span style="display:flex;"><span>                }
</span></span><span style="display:flex;"><span>            }
</span></span><span style="display:flex;"><span>        },
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&#34;forecastZone&#34;</span>: <span style="color:#e6db74">&#34;https://api.weather.gov/zones/forecast/NYZ053&#34;</span>,
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&#34;county&#34;</span>: <span style="color:#e6db74">&#34;https://api.weather.gov/zones/county/NYC083&#34;</span>,
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&#34;fireWeatherZone&#34;</span>: <span style="color:#e6db74">&#34;https://api.weather.gov/zones/fire/NYZ208&#34;</span>,
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&#34;timeZone&#34;</span>: <span style="color:#e6db74">&#34;America/New_York&#34;</span>,
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&#34;radarStation&#34;</span>: <span style="color:#e6db74">&#34;KENX&#34;</span>
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div></details><br/>
<p>That&rsquo;s a lot of output! However, we only need three pieces of information:</p>
<ul>
<li>WFO office (ex: &ldquo;ALY&rdquo;)</li>
<li>Grid-X (ex: 74)</li>
<li>Grid-Y (ex: 67)</li>
</ul>
<p>We can use the following code to store this into variables using <code>jq</code></p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>OFFICE<span style="color:#f92672">=</span><span style="color:#66d9ef">$(</span>echo $POINTS | jq -r .properties.gridId<span style="color:#66d9ef">)</span>
</span></span><span style="display:flex;"><span>X<span style="color:#f92672">=</span><span style="color:#66d9ef">$(</span>echo $POINTS | jq .properties.gridX<span style="color:#66d9ef">)</span>
</span></span><span style="display:flex;"><span>Y<span style="color:#f92672">=</span><span style="color:#66d9ef">$(</span>echo $POINTS | jq .properties.gridY<span style="color:#66d9ef">)</span>
</span></span></code></pre></div><p>From here, we can query for the weather forecast for that grid point.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>WEATHER<span style="color:#f92672">=</span><span style="color:#66d9ef">$(</span>curl -Ls <span style="color:#e6db74">&#34;https://api.weather.gov/gridpoints/</span>$OFFICE<span style="color:#e6db74">/</span>$X<span style="color:#e6db74">,</span>$Y<span style="color:#e6db74">/forecast&#34;</span><span style="color:#66d9ef">)</span>
</span></span></code></pre></div><details><summary>Show output:</summary>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&#34;@context&#34;</span>: [
</span></span><span style="display:flex;"><span>        <span style="color:#e6db74">&#34;https://geojson.org/geojson-ld/geojson-context.jsonld&#34;</span>,
</span></span><span style="display:flex;"><span>        {
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">&#34;@version&#34;</span>: <span style="color:#e6db74">&#34;1.1&#34;</span>,
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">&#34;wx&#34;</span>: <span style="color:#e6db74">&#34;https://api.weather.gov/ontology#&#34;</span>,
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">&#34;geo&#34;</span>: <span style="color:#e6db74">&#34;http://www.opengis.net/ont/geosparql#&#34;</span>,
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">&#34;unit&#34;</span>: <span style="color:#e6db74">&#34;http://codes.wmo.int/common/unit/&#34;</span>,
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">&#34;@vocab&#34;</span>: <span style="color:#e6db74">&#34;https://api.weather.gov/ontology#&#34;</span>
</span></span><span style="display:flex;"><span>        }
</span></span><span style="display:flex;"><span>    ],
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&#34;type&#34;</span>: <span style="color:#e6db74">&#34;Feature&#34;</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&#34;geometry&#34;</span>: {
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&#34;type&#34;</span>: <span style="color:#e6db74">&#34;Polygon&#34;</span>,
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&#34;coordinates&#34;</span>: [
</span></span><span style="display:flex;"><span>            [
</span></span><span style="display:flex;"><span>                [
</span></span><span style="display:flex;"><span>                    <span style="color:#ae81ff">-73.6648</span>,
</span></span><span style="display:flex;"><span>                    <span style="color:#ae81ff">42.7172</span>
</span></span><span style="display:flex;"><span>                ],
</span></span><span style="display:flex;"><span>                [
</span></span><span style="display:flex;"><span>                    <span style="color:#ae81ff">-73.6602</span>,
</span></span><span style="display:flex;"><span>                    <span style="color:#ae81ff">42.7386</span>
</span></span><span style="display:flex;"><span>                ],
</span></span><span style="display:flex;"><span>                [
</span></span><span style="display:flex;"><span>                    <span style="color:#ae81ff">-73.6893</span>,
</span></span><span style="display:flex;"><span>                    <span style="color:#ae81ff">42.742</span>
</span></span><span style="display:flex;"><span>                ],
</span></span><span style="display:flex;"><span>                [
</span></span><span style="display:flex;"><span>                    <span style="color:#ae81ff">-73.694</span>,
</span></span><span style="display:flex;"><span>                    <span style="color:#ae81ff">42.720499999999994</span>
</span></span><span style="display:flex;"><span>                ],
</span></span><span style="display:flex;"><span>                [
</span></span><span style="display:flex;"><span>                    <span style="color:#ae81ff">-73.6648</span>,
</span></span><span style="display:flex;"><span>                    <span style="color:#ae81ff">42.7172</span>
</span></span><span style="display:flex;"><span>                ]
</span></span><span style="display:flex;"><span>            ]
</span></span><span style="display:flex;"><span>        ]
</span></span><span style="display:flex;"><span>    },
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&#34;properties&#34;</span>: {
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&#34;units&#34;</span>: <span style="color:#e6db74">&#34;us&#34;</span>,
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&#34;forecastGenerator&#34;</span>: <span style="color:#e6db74">&#34;BaselineForecastGenerator&#34;</span>,
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&#34;generatedAt&#34;</span>: <span style="color:#e6db74">&#34;2025-03-16T19:59:48+00:00&#34;</span>,
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&#34;updateTime&#34;</span>: <span style="color:#e6db74">&#34;2025-03-16T19:38:29+00:00&#34;</span>,
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&#34;validTimes&#34;</span>: <span style="color:#e6db74">&#34;2025-03-16T13:00:00+00:00/P8D&#34;</span>,
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&#34;elevation&#34;</span>: {
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">&#34;unitCode&#34;</span>: <span style="color:#e6db74">&#34;wmoUnit:m&#34;</span>,
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">&#34;value&#34;</span>: <span style="color:#ae81ff">61.8744</span>
</span></span><span style="display:flex;"><span>        },
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">&#34;periods&#34;</span>: [
</span></span><span style="display:flex;"><span>            {
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;number&#34;</span>: <span style="color:#ae81ff">1</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;name&#34;</span>: <span style="color:#e6db74">&#34;This Afternoon&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;startTime&#34;</span>: <span style="color:#e6db74">&#34;2025-03-16T15:00:00-04:00&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;endTime&#34;</span>: <span style="color:#e6db74">&#34;2025-03-16T18:00:00-04:00&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;isDaytime&#34;</span>: <span style="color:#66d9ef">true</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperature&#34;</span>: <span style="color:#ae81ff">69</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperatureUnit&#34;</span>: <span style="color:#e6db74">&#34;F&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperatureTrend&#34;</span>: <span style="color:#e6db74">&#34;&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;probabilityOfPrecipitation&#34;</span>: {
</span></span><span style="display:flex;"><span>                    <span style="color:#f92672">&#34;unitCode&#34;</span>: <span style="color:#e6db74">&#34;wmoUnit:percent&#34;</span>,
</span></span><span style="display:flex;"><span>                    <span style="color:#f92672">&#34;value&#34;</span>: <span style="color:#66d9ef">null</span>
</span></span><span style="display:flex;"><span>                },
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;windSpeed&#34;</span>: <span style="color:#e6db74">&#34;22 mph&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;windDirection&#34;</span>: <span style="color:#e6db74">&#34;S&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;icon&#34;</span>: <span style="color:#e6db74">&#34;https://api.weather.gov/icons/land/day/wind_ovc?size=medium&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;shortForecast&#34;</span>: <span style="color:#e6db74">&#34;Cloudy&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;detailedForecast&#34;</span>: <span style="color:#e6db74">&#34;Cloudy, with a high near 69. South wind around 22 mph, with gusts as high as 43 mph. New rainfall amounts less than a tenth of an inch possible.&#34;</span>
</span></span><span style="display:flex;"><span>            },
</span></span><span style="display:flex;"><span>            {
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;number&#34;</span>: <span style="color:#ae81ff">2</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;name&#34;</span>: <span style="color:#e6db74">&#34;Tonight&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;startTime&#34;</span>: <span style="color:#e6db74">&#34;2025-03-16T18:00:00-04:00&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;endTime&#34;</span>: <span style="color:#e6db74">&#34;2025-03-17T06:00:00-04:00&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;isDaytime&#34;</span>: <span style="color:#66d9ef">false</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperature&#34;</span>: <span style="color:#ae81ff">50</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperatureUnit&#34;</span>: <span style="color:#e6db74">&#34;F&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperatureTrend&#34;</span>: <span style="color:#e6db74">&#34;&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;probabilityOfPrecipitation&#34;</span>: {
</span></span><span style="display:flex;"><span>                    <span style="color:#f92672">&#34;unitCode&#34;</span>: <span style="color:#e6db74">&#34;wmoUnit:percent&#34;</span>,
</span></span><span style="display:flex;"><span>                    <span style="color:#f92672">&#34;value&#34;</span>: <span style="color:#ae81ff">100</span>
</span></span><span style="display:flex;"><span>                },
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;windSpeed&#34;</span>: <span style="color:#e6db74">&#34;5 to 21 mph&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;windDirection&#34;</span>: <span style="color:#e6db74">&#34;SW&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;icon&#34;</span>: <span style="color:#e6db74">&#34;https://api.weather.gov/icons/land/night/tsra,100?size=medium&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;shortForecast&#34;</span>: <span style="color:#e6db74">&#34;Showers And Thunderstorms&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;detailedForecast&#34;</span>: <span style="color:#e6db74">&#34;A chance of rain showers before 8pm, then showers and thunderstorms. Cloudy, with a low around 50. Southwest wind 5 to 21 mph, with gusts as high as 44 mph. Chance of precipitation is 100%. New rainfall amounts between three quarters and one inch possible.&#34;</span>
</span></span><span style="display:flex;"><span>            },
</span></span><span style="display:flex;"><span>            {
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;number&#34;</span>: <span style="color:#ae81ff">3</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;name&#34;</span>: <span style="color:#e6db74">&#34;Monday&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;startTime&#34;</span>: <span style="color:#e6db74">&#34;2025-03-17T06:00:00-04:00&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;endTime&#34;</span>: <span style="color:#e6db74">&#34;2025-03-17T18:00:00-04:00&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;isDaytime&#34;</span>: <span style="color:#66d9ef">true</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperature&#34;</span>: <span style="color:#ae81ff">53</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperatureUnit&#34;</span>: <span style="color:#e6db74">&#34;F&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperatureTrend&#34;</span>: <span style="color:#e6db74">&#34;&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;probabilityOfPrecipitation&#34;</span>: {
</span></span><span style="display:flex;"><span>                    <span style="color:#f92672">&#34;unitCode&#34;</span>: <span style="color:#e6db74">&#34;wmoUnit:percent&#34;</span>,
</span></span><span style="display:flex;"><span>                    <span style="color:#f92672">&#34;value&#34;</span>: <span style="color:#ae81ff">60</span>
</span></span><span style="display:flex;"><span>                },
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;windSpeed&#34;</span>: <span style="color:#e6db74">&#34;5 to 12 mph&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;windDirection&#34;</span>: <span style="color:#e6db74">&#34;NW&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;icon&#34;</span>: <span style="color:#e6db74">&#34;https://api.weather.gov/icons/land/day/rain_showers,60/rain_showers,50?size=medium&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;shortForecast&#34;</span>: <span style="color:#e6db74">&#34;Rain Showers Likely&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;detailedForecast&#34;</span>: <span style="color:#e6db74">&#34;Rain showers likely. Cloudy. High near 53, with temperatures falling to around 46 in the afternoon. Northwest wind 5 to 12 mph. Chance of precipitation is 60%. New rainfall amounts between a half and three quarters of an inch possible.&#34;</span>
</span></span><span style="display:flex;"><span>            },
</span></span><span style="display:flex;"><span>            {
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;number&#34;</span>: <span style="color:#ae81ff">4</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;name&#34;</span>: <span style="color:#e6db74">&#34;Monday Night&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;startTime&#34;</span>: <span style="color:#e6db74">&#34;2025-03-17T18:00:00-04:00&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;endTime&#34;</span>: <span style="color:#e6db74">&#34;2025-03-18T06:00:00-04:00&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;isDaytime&#34;</span>: <span style="color:#66d9ef">false</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperature&#34;</span>: <span style="color:#ae81ff">31</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperatureUnit&#34;</span>: <span style="color:#e6db74">&#34;F&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperatureTrend&#34;</span>: <span style="color:#e6db74">&#34;&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;probabilityOfPrecipitation&#34;</span>: {
</span></span><span style="display:flex;"><span>                    <span style="color:#f92672">&#34;unitCode&#34;</span>: <span style="color:#e6db74">&#34;wmoUnit:percent&#34;</span>,
</span></span><span style="display:flex;"><span>                    <span style="color:#f92672">&#34;value&#34;</span>: <span style="color:#ae81ff">30</span>
</span></span><span style="display:flex;"><span>                },
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;windSpeed&#34;</span>: <span style="color:#e6db74">&#34;7 to 10 mph&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;windDirection&#34;</span>: <span style="color:#e6db74">&#34;NW&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;icon&#34;</span>: <span style="color:#e6db74">&#34;https://api.weather.gov/icons/land/night/rain_showers,30/bkn?size=medium&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;shortForecast&#34;</span>: <span style="color:#e6db74">&#34;Chance Rain Showers then Mostly Cloudy&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;detailedForecast&#34;</span>: <span style="color:#e6db74">&#34;A chance of rain showers before 8pm. Mostly cloudy, with a low around 31. Northwest wind 7 to 10 mph. Chance of precipitation is 30%. New rainfall amounts between a tenth and quarter of an inch possible.&#34;</span>
</span></span><span style="display:flex;"><span>            },
</span></span><span style="display:flex;"><span>            {
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;number&#34;</span>: <span style="color:#ae81ff">5</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;name&#34;</span>: <span style="color:#e6db74">&#34;Tuesday&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;startTime&#34;</span>: <span style="color:#e6db74">&#34;2025-03-18T06:00:00-04:00&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;endTime&#34;</span>: <span style="color:#e6db74">&#34;2025-03-18T18:00:00-04:00&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;isDaytime&#34;</span>: <span style="color:#66d9ef">true</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperature&#34;</span>: <span style="color:#ae81ff">56</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperatureUnit&#34;</span>: <span style="color:#e6db74">&#34;F&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperatureTrend&#34;</span>: <span style="color:#e6db74">&#34;&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;probabilityOfPrecipitation&#34;</span>: {
</span></span><span style="display:flex;"><span>                    <span style="color:#f92672">&#34;unitCode&#34;</span>: <span style="color:#e6db74">&#34;wmoUnit:percent&#34;</span>,
</span></span><span style="display:flex;"><span>                    <span style="color:#f92672">&#34;value&#34;</span>: <span style="color:#66d9ef">null</span>
</span></span><span style="display:flex;"><span>                },
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;windSpeed&#34;</span>: <span style="color:#e6db74">&#34;7 mph&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;windDirection&#34;</span>: <span style="color:#e6db74">&#34;NW&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;icon&#34;</span>: <span style="color:#e6db74">&#34;https://api.weather.gov/icons/land/day/few?size=medium&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;shortForecast&#34;</span>: <span style="color:#e6db74">&#34;Sunny&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;detailedForecast&#34;</span>: <span style="color:#e6db74">&#34;Sunny, with a high near 56. Northwest wind around 7 mph.&#34;</span>
</span></span><span style="display:flex;"><span>            },
</span></span><span style="display:flex;"><span>            {
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;number&#34;</span>: <span style="color:#ae81ff">6</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;name&#34;</span>: <span style="color:#e6db74">&#34;Tuesday Night&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;startTime&#34;</span>: <span style="color:#e6db74">&#34;2025-03-18T18:00:00-04:00&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;endTime&#34;</span>: <span style="color:#e6db74">&#34;2025-03-19T06:00:00-04:00&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;isDaytime&#34;</span>: <span style="color:#66d9ef">false</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperature&#34;</span>: <span style="color:#ae81ff">35</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperatureUnit&#34;</span>: <span style="color:#e6db74">&#34;F&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperatureTrend&#34;</span>: <span style="color:#e6db74">&#34;&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;probabilityOfPrecipitation&#34;</span>: {
</span></span><span style="display:flex;"><span>                    <span style="color:#f92672">&#34;unitCode&#34;</span>: <span style="color:#e6db74">&#34;wmoUnit:percent&#34;</span>,
</span></span><span style="display:flex;"><span>                    <span style="color:#f92672">&#34;value&#34;</span>: <span style="color:#66d9ef">null</span>
</span></span><span style="display:flex;"><span>                },
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;windSpeed&#34;</span>: <span style="color:#e6db74">&#34;1 to 5 mph&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;windDirection&#34;</span>: <span style="color:#e6db74">&#34;NE&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;icon&#34;</span>: <span style="color:#e6db74">&#34;https://api.weather.gov/icons/land/night/few?size=medium&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;shortForecast&#34;</span>: <span style="color:#e6db74">&#34;Mostly Clear&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;detailedForecast&#34;</span>: <span style="color:#e6db74">&#34;Mostly clear, with a low around 35.&#34;</span>
</span></span><span style="display:flex;"><span>            },
</span></span><span style="display:flex;"><span>            {
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;number&#34;</span>: <span style="color:#ae81ff">7</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;name&#34;</span>: <span style="color:#e6db74">&#34;Wednesday&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;startTime&#34;</span>: <span style="color:#e6db74">&#34;2025-03-19T06:00:00-04:00&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;endTime&#34;</span>: <span style="color:#e6db74">&#34;2025-03-19T18:00:00-04:00&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;isDaytime&#34;</span>: <span style="color:#66d9ef">true</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperature&#34;</span>: <span style="color:#ae81ff">65</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperatureUnit&#34;</span>: <span style="color:#e6db74">&#34;F&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperatureTrend&#34;</span>: <span style="color:#e6db74">&#34;&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;probabilityOfPrecipitation&#34;</span>: {
</span></span><span style="display:flex;"><span>                    <span style="color:#f92672">&#34;unitCode&#34;</span>: <span style="color:#e6db74">&#34;wmoUnit:percent&#34;</span>,
</span></span><span style="display:flex;"><span>                    <span style="color:#f92672">&#34;value&#34;</span>: <span style="color:#66d9ef">null</span>
</span></span><span style="display:flex;"><span>                },
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;windSpeed&#34;</span>: <span style="color:#e6db74">&#34;2 to 9 mph&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;windDirection&#34;</span>: <span style="color:#e6db74">&#34;SE&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;icon&#34;</span>: <span style="color:#e6db74">&#34;https://api.weather.gov/icons/land/day/sct?size=medium&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;shortForecast&#34;</span>: <span style="color:#e6db74">&#34;Mostly Sunny&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;detailedForecast&#34;</span>: <span style="color:#e6db74">&#34;Mostly sunny, with a high near 65.&#34;</span>
</span></span><span style="display:flex;"><span>            },
</span></span><span style="display:flex;"><span>            {
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;number&#34;</span>: <span style="color:#ae81ff">8</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;name&#34;</span>: <span style="color:#e6db74">&#34;Wednesday Night&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;startTime&#34;</span>: <span style="color:#e6db74">&#34;2025-03-19T18:00:00-04:00&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;endTime&#34;</span>: <span style="color:#e6db74">&#34;2025-03-20T06:00:00-04:00&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;isDaytime&#34;</span>: <span style="color:#66d9ef">false</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperature&#34;</span>: <span style="color:#ae81ff">45</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperatureUnit&#34;</span>: <span style="color:#e6db74">&#34;F&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperatureTrend&#34;</span>: <span style="color:#e6db74">&#34;&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;probabilityOfPrecipitation&#34;</span>: {
</span></span><span style="display:flex;"><span>                    <span style="color:#f92672">&#34;unitCode&#34;</span>: <span style="color:#e6db74">&#34;wmoUnit:percent&#34;</span>,
</span></span><span style="display:flex;"><span>                    <span style="color:#f92672">&#34;value&#34;</span>: <span style="color:#66d9ef">null</span>
</span></span><span style="display:flex;"><span>                },
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;windSpeed&#34;</span>: <span style="color:#e6db74">&#34;9 mph&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;windDirection&#34;</span>: <span style="color:#e6db74">&#34;SE&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;icon&#34;</span>: <span style="color:#e6db74">&#34;https://api.weather.gov/icons/land/night/bkn?size=medium&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;shortForecast&#34;</span>: <span style="color:#e6db74">&#34;Mostly Cloudy&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;detailedForecast&#34;</span>: <span style="color:#e6db74">&#34;Mostly cloudy, with a low around 45.&#34;</span>
</span></span><span style="display:flex;"><span>            },
</span></span><span style="display:flex;"><span>            {
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;number&#34;</span>: <span style="color:#ae81ff">9</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;name&#34;</span>: <span style="color:#e6db74">&#34;Thursday&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;startTime&#34;</span>: <span style="color:#e6db74">&#34;2025-03-20T06:00:00-04:00&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;endTime&#34;</span>: <span style="color:#e6db74">&#34;2025-03-20T18:00:00-04:00&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;isDaytime&#34;</span>: <span style="color:#66d9ef">true</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperature&#34;</span>: <span style="color:#ae81ff">61</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperatureUnit&#34;</span>: <span style="color:#e6db74">&#34;F&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperatureTrend&#34;</span>: <span style="color:#e6db74">&#34;&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;probabilityOfPrecipitation&#34;</span>: {
</span></span><span style="display:flex;"><span>                    <span style="color:#f92672">&#34;unitCode&#34;</span>: <span style="color:#e6db74">&#34;wmoUnit:percent&#34;</span>,
</span></span><span style="display:flex;"><span>                    <span style="color:#f92672">&#34;value&#34;</span>: <span style="color:#ae81ff">50</span>
</span></span><span style="display:flex;"><span>                },
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;windSpeed&#34;</span>: <span style="color:#e6db74">&#34;8 to 14 mph&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;windDirection&#34;</span>: <span style="color:#e6db74">&#34;S&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;icon&#34;</span>: <span style="color:#e6db74">&#34;https://api.weather.gov/icons/land/day/bkn/rain_showers,50?size=medium&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;shortForecast&#34;</span>: <span style="color:#e6db74">&#34;Mostly Cloudy then Chance Rain Showers&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;detailedForecast&#34;</span>: <span style="color:#e6db74">&#34;A chance of rain showers after 2pm. Mostly cloudy, with a high near 61. Chance of precipitation is 50%.&#34;</span>
</span></span><span style="display:flex;"><span>            },
</span></span><span style="display:flex;"><span>            {
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;number&#34;</span>: <span style="color:#ae81ff">10</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;name&#34;</span>: <span style="color:#e6db74">&#34;Thursday Night&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;startTime&#34;</span>: <span style="color:#e6db74">&#34;2025-03-20T18:00:00-04:00&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;endTime&#34;</span>: <span style="color:#e6db74">&#34;2025-03-21T06:00:00-04:00&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;isDaytime&#34;</span>: <span style="color:#66d9ef">false</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperature&#34;</span>: <span style="color:#ae81ff">33</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperatureUnit&#34;</span>: <span style="color:#e6db74">&#34;F&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperatureTrend&#34;</span>: <span style="color:#e6db74">&#34;&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;probabilityOfPrecipitation&#34;</span>: {
</span></span><span style="display:flex;"><span>                    <span style="color:#f92672">&#34;unitCode&#34;</span>: <span style="color:#e6db74">&#34;wmoUnit:percent&#34;</span>,
</span></span><span style="display:flex;"><span>                    <span style="color:#f92672">&#34;value&#34;</span>: <span style="color:#ae81ff">70</span>
</span></span><span style="display:flex;"><span>                },
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;windSpeed&#34;</span>: <span style="color:#e6db74">&#34;8 to 12 mph&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;windDirection&#34;</span>: <span style="color:#e6db74">&#34;SW&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;icon&#34;</span>: <span style="color:#e6db74">&#34;https://api.weather.gov/icons/land/night/rain_showers,70/snow,70?size=medium&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;shortForecast&#34;</span>: <span style="color:#e6db74">&#34;Rain Showers Likely then Chance Rain And Snow Showers&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;detailedForecast&#34;</span>: <span style="color:#e6db74">&#34;Rain showers likely before 2am, then a chance of rain and snow showers. Mostly cloudy, with a low around 33. Chance of precipitation is 70%.&#34;</span>
</span></span><span style="display:flex;"><span>            },
</span></span><span style="display:flex;"><span>            {
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;number&#34;</span>: <span style="color:#ae81ff">11</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;name&#34;</span>: <span style="color:#e6db74">&#34;Friday&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;startTime&#34;</span>: <span style="color:#e6db74">&#34;2025-03-21T06:00:00-04:00&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;endTime&#34;</span>: <span style="color:#e6db74">&#34;2025-03-21T18:00:00-04:00&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;isDaytime&#34;</span>: <span style="color:#66d9ef">true</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperature&#34;</span>: <span style="color:#ae81ff">41</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperatureUnit&#34;</span>: <span style="color:#e6db74">&#34;F&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperatureTrend&#34;</span>: <span style="color:#e6db74">&#34;&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;probabilityOfPrecipitation&#34;</span>: {
</span></span><span style="display:flex;"><span>                    <span style="color:#f92672">&#34;unitCode&#34;</span>: <span style="color:#e6db74">&#34;wmoUnit:percent&#34;</span>,
</span></span><span style="display:flex;"><span>                    <span style="color:#f92672">&#34;value&#34;</span>: <span style="color:#ae81ff">50</span>
</span></span><span style="display:flex;"><span>                },
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;windSpeed&#34;</span>: <span style="color:#e6db74">&#34;12 to 17 mph&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;windDirection&#34;</span>: <span style="color:#e6db74">&#34;NW&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;icon&#34;</span>: <span style="color:#e6db74">&#34;https://api.weather.gov/icons/land/day/snow,50/snow,30?size=medium&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;shortForecast&#34;</span>: <span style="color:#e6db74">&#34;Chance Rain And Snow Showers&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;detailedForecast&#34;</span>: <span style="color:#e6db74">&#34;A chance of rain and snow showers. Partly sunny, with a high near 41. Chance of precipitation is 50%.&#34;</span>
</span></span><span style="display:flex;"><span>            },
</span></span><span style="display:flex;"><span>            {
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;number&#34;</span>: <span style="color:#ae81ff">12</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;name&#34;</span>: <span style="color:#e6db74">&#34;Friday Night&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;startTime&#34;</span>: <span style="color:#e6db74">&#34;2025-03-21T18:00:00-04:00&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;endTime&#34;</span>: <span style="color:#e6db74">&#34;2025-03-22T06:00:00-04:00&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;isDaytime&#34;</span>: <span style="color:#66d9ef">false</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperature&#34;</span>: <span style="color:#ae81ff">30</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperatureUnit&#34;</span>: <span style="color:#e6db74">&#34;F&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperatureTrend&#34;</span>: <span style="color:#e6db74">&#34;&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;probabilityOfPrecipitation&#34;</span>: {
</span></span><span style="display:flex;"><span>                    <span style="color:#f92672">&#34;unitCode&#34;</span>: <span style="color:#e6db74">&#34;wmoUnit:percent&#34;</span>,
</span></span><span style="display:flex;"><span>                    <span style="color:#f92672">&#34;value&#34;</span>: <span style="color:#66d9ef">null</span>
</span></span><span style="display:flex;"><span>                },
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;windSpeed&#34;</span>: <span style="color:#e6db74">&#34;9 to 16 mph&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;windDirection&#34;</span>: <span style="color:#e6db74">&#34;NW&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;icon&#34;</span>: <span style="color:#e6db74">&#34;https://api.weather.gov/icons/land/night/snow/sct?size=medium&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;shortForecast&#34;</span>: <span style="color:#e6db74">&#34;Slight Chance Snow Showers then Partly Cloudy&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;detailedForecast&#34;</span>: <span style="color:#e6db74">&#34;A slight chance of snow showers before 8pm. Partly cloudy, with a low around 30.&#34;</span>
</span></span><span style="display:flex;"><span>            },
</span></span><span style="display:flex;"><span>            {
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;number&#34;</span>: <span style="color:#ae81ff">13</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;name&#34;</span>: <span style="color:#e6db74">&#34;Saturday&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;startTime&#34;</span>: <span style="color:#e6db74">&#34;2025-03-22T06:00:00-04:00&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;endTime&#34;</span>: <span style="color:#e6db74">&#34;2025-03-22T18:00:00-04:00&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;isDaytime&#34;</span>: <span style="color:#66d9ef">true</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperature&#34;</span>: <span style="color:#ae81ff">52</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperatureUnit&#34;</span>: <span style="color:#e6db74">&#34;F&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperatureTrend&#34;</span>: <span style="color:#e6db74">&#34;&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;probabilityOfPrecipitation&#34;</span>: {
</span></span><span style="display:flex;"><span>                    <span style="color:#f92672">&#34;unitCode&#34;</span>: <span style="color:#e6db74">&#34;wmoUnit:percent&#34;</span>,
</span></span><span style="display:flex;"><span>                    <span style="color:#f92672">&#34;value&#34;</span>: <span style="color:#66d9ef">null</span>
</span></span><span style="display:flex;"><span>                },
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;windSpeed&#34;</span>: <span style="color:#e6db74">&#34;9 to 13 mph&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;windDirection&#34;</span>: <span style="color:#e6db74">&#34;NW&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;icon&#34;</span>: <span style="color:#e6db74">&#34;https://api.weather.gov/icons/land/day/sct?size=medium&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;shortForecast&#34;</span>: <span style="color:#e6db74">&#34;Mostly Sunny&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;detailedForecast&#34;</span>: <span style="color:#e6db74">&#34;Mostly sunny, with a high near 52.&#34;</span>
</span></span><span style="display:flex;"><span>            },
</span></span><span style="display:flex;"><span>            {
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;number&#34;</span>: <span style="color:#ae81ff">14</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;name&#34;</span>: <span style="color:#e6db74">&#34;Saturday Night&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;startTime&#34;</span>: <span style="color:#e6db74">&#34;2025-03-22T18:00:00-04:00&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;endTime&#34;</span>: <span style="color:#e6db74">&#34;2025-03-23T06:00:00-04:00&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;isDaytime&#34;</span>: <span style="color:#66d9ef">false</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperature&#34;</span>: <span style="color:#ae81ff">34</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperatureUnit&#34;</span>: <span style="color:#e6db74">&#34;F&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;temperatureTrend&#34;</span>: <span style="color:#e6db74">&#34;&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;probabilityOfPrecipitation&#34;</span>: {
</span></span><span style="display:flex;"><span>                    <span style="color:#f92672">&#34;unitCode&#34;</span>: <span style="color:#e6db74">&#34;wmoUnit:percent&#34;</span>,
</span></span><span style="display:flex;"><span>                    <span style="color:#f92672">&#34;value&#34;</span>: <span style="color:#66d9ef">null</span>
</span></span><span style="display:flex;"><span>                },
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;windSpeed&#34;</span>: <span style="color:#e6db74">&#34;3 to 9 mph&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;windDirection&#34;</span>: <span style="color:#e6db74">&#34;NW&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;icon&#34;</span>: <span style="color:#e6db74">&#34;https://api.weather.gov/icons/land/night/bkn?size=medium&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;shortForecast&#34;</span>: <span style="color:#e6db74">&#34;Mostly Cloudy&#34;</span>,
</span></span><span style="display:flex;"><span>                <span style="color:#f92672">&#34;detailedForecast&#34;</span>: <span style="color:#e6db74">&#34;Mostly cloudy, with a low around 34.&#34;</span>
</span></span><span style="display:flex;"><span>            }
</span></span><span style="display:flex;"><span>        ]
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div></details><br/>
<p>The National Weather Service packs in so much weather information in just one API call! My favorite part is that they have a <code>detailedForecast</code> field which provides a nice human-readable description of the weather.</p>
<p>I don&rsquo;t know about you, but at any given time, I&rsquo;m mostly curious about today and tomorrow&rsquo;s weather. Unless I&rsquo;m planning a trip or need to be aware of an extreme weather event, the day&rsquo;s forecast mostly influences the clothes I wear.</p>
<p>The final part of this script is to grab the next three &ldquo;periods&rdquo; and display its <code>detailedForecast</code> field.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#66d9ef">for</span> i in <span style="color:#ae81ff">0</span> <span style="color:#ae81ff">1</span> 2; <span style="color:#66d9ef">do</span>
</span></span><span style="display:flex;"><span>    echo <span style="color:#e6db74">&#34;</span>$WEATHER<span style="color:#e6db74">&#34;</span> | jq .properties.periods<span style="color:#f92672">[</span>$i<span style="color:#f92672">]</span> | jq -r <span style="color:#e6db74">&#39;
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">  &#34;\(.name)
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">  \(.detailedForecast)
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">  &#34; 
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">&#39;</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">done</span>
</span></span></code></pre></div><p>Instead of having to read an entire JSON message to get the weather, we now have a description of the forecast coming up.</p>
<pre tabindex="0"><code>This Afternoon
  Cloudy, with a high near 69. South wind around 22 mph, with gusts as high as 43 mph. New rainfall amounts less than a tenth of an inch possible.
  
Tonight
  A chance of rain showers before 8pm, then showers and thunderstorms. Cloudy, with a low around 50. Southwest wind 5 to 21 mph, with gusts as high as 44 mph. Chance of precipitation is 100%. New rainfall amounts between three quarters and one inch possible.
  
Monday
  Rain showers likely. Cloudy. High near 53, with temperatures falling to around 46 in the afternoon. Northwest wind 5 to 12 mph. Chance of precipitation is 60%. New rainfall amounts between a half and three quarters of an inch possible.
</code></pre><p>Look how short and sweet that output is! With that, we have all the steps needed in our script to grab the upcoming forecast using the NWS API. I created an alias called <code>myweather</code> so that I don&rsquo;t have to memorize the latitude or longitude of where I live.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>alias myweather<span style="color:#f92672">=</span><span style="color:#e6db74">&#39;usweather 42.7289, -73.6915&#39;</span>
</span></span></code></pre></div><p>Here is the script that I call <code>usweather</code> in its entirety. I placed it in <code>~/.local/bin</code>.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e">#!/bin/sh
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#75715e"># Script to query the US National Weather Forecast Office (WFO)</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>set -o errexit
</span></span><span style="display:flex;"><span>set -o nounset
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>show_usage<span style="color:#f92672">()</span> <span style="color:#f92672">{</span>
</span></span><span style="display:flex;"><span>    echo <span style="color:#e6db74">&#34;Usage: usweather [lat] [lon]&#34;</span>
</span></span><span style="display:flex;"><span>    exit <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Check Argument Count</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">if</span> <span style="color:#f92672">[</span> <span style="color:#e6db74">&#34;</span>$#<span style="color:#e6db74">&#34;</span> -ne <span style="color:#ae81ff">2</span> <span style="color:#f92672">]</span>; <span style="color:#66d9ef">then</span>
</span></span><span style="display:flex;"><span>    show_usage
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">fi</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">if</span> ! command -v jq &amp;&gt; /dev/null; <span style="color:#66d9ef">then</span>
</span></span><span style="display:flex;"><span>    echo <span style="color:#e6db74">&#34;jq is not installed&#34;</span>
</span></span><span style="display:flex;"><span>    exit <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">fi</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># We need to figure out WFO specific parameters</span>
</span></span><span style="display:flex;"><span>POINTS<span style="color:#f92672">=</span><span style="color:#66d9ef">$(</span>curl -Ls <span style="color:#e6db74">&#34;https://api.weather.gov/points/</span>$1<span style="color:#e6db74">,</span>$2<span style="color:#e6db74">&#34;</span><span style="color:#66d9ef">)</span>
</span></span><span style="display:flex;"><span>OFFICE<span style="color:#f92672">=</span><span style="color:#66d9ef">$(</span>echo $POINTS | jq -r .properties.gridId<span style="color:#66d9ef">)</span>
</span></span><span style="display:flex;"><span>X<span style="color:#f92672">=</span><span style="color:#66d9ef">$(</span>echo $POINTS | jq .properties.gridX<span style="color:#66d9ef">)</span>
</span></span><span style="display:flex;"><span>Y<span style="color:#f92672">=</span><span style="color:#66d9ef">$(</span>echo $POINTS | jq .properties.gridY<span style="color:#66d9ef">)</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">if</span> <span style="color:#f92672">[</span> <span style="color:#e6db74">&#34;</span>$OFFICE<span style="color:#e6db74">&#34;</span> <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;null&#34;</span> <span style="color:#f92672">]</span> <span style="color:#f92672">||</span> <span style="color:#f92672">[</span> <span style="color:#e6db74">&#34;</span>$X<span style="color:#e6db74">&#34;</span> <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;null&#34;</span> <span style="color:#f92672">]</span> <span style="color:#f92672">||</span> <span style="color:#f92672">[</span> <span style="color:#e6db74">&#34;</span>$Y<span style="color:#e6db74">&#34;</span> <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;null&#34;</span> <span style="color:#f92672">]</span>; <span style="color:#66d9ef">then</span>
</span></span><span style="display:flex;"><span>	echo -e <span style="color:#e6db74">&#34;Error:\n </span>$POINTS<span style="color:#e6db74">&#34;</span>
</span></span><span style="display:flex;"><span>	exit <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">fi</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>WEATHER<span style="color:#f92672">=</span><span style="color:#66d9ef">$(</span>curl -Ls <span style="color:#e6db74">&#34;https://api.weather.gov/gridpoints/</span>$OFFICE<span style="color:#e6db74">/</span>$X<span style="color:#e6db74">,</span>$Y<span style="color:#e6db74">/forecast&#34;</span><span style="color:#66d9ef">)</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Provide the detailed forecast for the next three weather periods</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">for</span> i in <span style="color:#ae81ff">0</span> <span style="color:#ae81ff">1</span> 2; <span style="color:#66d9ef">do</span>
</span></span><span style="display:flex;"><span>    echo <span style="color:#e6db74">&#34;</span>$WEATHER<span style="color:#e6db74">&#34;</span> | jq .properties.periods<span style="color:#f92672">[</span>$i<span style="color:#f92672">]</span> | jq -r <span style="color:#e6db74">&#39;
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">  &#34;\(.name)
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">  \(.detailedForecast)
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">  &#34; 
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">&#39;</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">done</span>
</span></span></code></pre></div><div class="footnotes" role="doc-endnotes">
<hr>
<ol>
<li id="fn:1">
<p>In this day and age, it almost feels too good to be true.&#160;<a href="#fnref:1" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
</ol>
</div>
]]></content:encoded>
  <category>Command-line interface</category>
  <category>National Weather Service</category>
  <category>Bash</category>
  <category>jq</category>
  
</item>
  
  <item>
  <title>Adventures in Rust WebAssembly</title>
  <link>https://brandonrozek.com/blog/adventures-in-rust-webassembly/</link>
  <pubDate>Fri, 21 Feb 2025 10:13:17 -0500</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid>https://brandonrozek.com/blog/adventures-in-rust-webassembly/</guid>
  <description><![CDATA[<p>For two years now, my friend and colleague <a href="https://jamesoswald.dev">James Oswald</a> has told me to check out <a href="https://webassembly.org/">WebAssembly</a>. I avoided it all this time because I thought it would be too complicated to get started with. In one of our study sessions, my friends Chris and Ethan both said they wanted to look into it. I have to say, that getting started with WebAssembly is far simpler than I&rsquo;ve previously imagined and it makes me wish I listened to James earlier.</p>]]></description>
  <content:encoded><![CDATA[<p>For two years now, my friend and colleague <a href="https://jamesoswald.dev">James Oswald</a> has told me to check out <a href="https://webassembly.org/">WebAssembly</a>. I avoided it all this time because I thought it would be too complicated to get started with. In one of our study sessions, my friends Chris and Ethan both said they wanted to look into it. I have to say, that getting started with WebAssembly is far simpler than I&rsquo;ve previously imagined and it makes me wish I listened to James earlier.</p>
<p>In this post, I&rsquo;ll show how to use Rust + Webassembly to create both a CLI application and a Web application. <a href="https://rustwasm.github.io/docs/book/">The Rust and Webassembly Book</a> is a great resource, however like <a href="https://dzfrias.dev/blog/rust-wasm-minimal-setup/">Diego</a>, I found the recommended setup to be a bit too heavy for my liking. I&rsquo;ll do anything to avoid using <code>npm</code> in personal projects.</p>
<h3 id="setup">Setup</h3>
<p>I assume that you have the <a href="https://www.rust-lang.org/tools/install"><code>rustup</code></a> command available.</p>
<p>First, we&rsquo;ll need to have the <code>wasm</code> toolchains installed.</p>
<ul>
<li>For CLI applications: <code>rustup target add wasm32-wasi</code></li>
<li>For Web applications: <code>rustup target add wasm32-unknown-unknown</code></li>
</ul>
<p>For the web, we&rsquo;ll also need <code>wasm-bindgen</code> to create the JavaScript glue code which ingests the <code>.wasm</code> file.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>cargo install wasm-bindgen-cli
</span></span></code></pre></div><p>Now we can create our Rust project!</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>cargo new rustwasm
</span></span></code></pre></div><p>This will create the following directory structure</p>
<pre tabindex="0"><code>rustwasm
├── Cargo.toml
└── src
    └── main.rs
</code></pre><p>To compile WebAssembly for the Web, edit the <code>Cargo.toml</code> to set the crate-type and add the dependencies.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-toml" data-lang="toml"><span style="display:flex;"><span>[<span style="color:#a6e22e">package</span>]
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">name</span> = <span style="color:#e6db74">&#34;rustwasm&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">version</span> = <span style="color:#e6db74">&#34;0.1.0&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">edition</span> = <span style="color:#e6db74">&#34;2021&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>[<span style="color:#a6e22e">lib</span>]
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">crate-type</span> = [<span style="color:#e6db74">&#34;cdylib&#34;</span>, <span style="color:#e6db74">&#34;rlib&#34;</span>]
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>[<span style="color:#a6e22e">dependencies</span>]
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">wasm-bindgen</span> = <span style="color:#e6db74">&#34;0.2.84&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">js-sys</span> = <span style="color:#e6db74">&#34;0.3.77&#34;</span>
</span></span></code></pre></div><p>In the following Rust examples, there will be snippets of <code>wasm_bindgen</code> scattered about. This is to create the JavaScript glue code. If you&rsquo;re only running on the CLI then those lines are not needed, but it doesn&rsquo;t hurt to include them.</p>
<p>Let&rsquo;s add a greeter function that returns the string <code>&quot;Hello World&quot;</code> in <code>src/lib.rs</code></p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-rust" data-lang="rust"><span style="display:flex;"><span><span style="color:#66d9ef">use</span> wasm_bindgen::prelude::<span style="color:#f92672">*</span>;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">#[wasm_bindgen]</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">pub</span> <span style="color:#66d9ef">fn</span> <span style="color:#a6e22e">greeting</span>() -&gt; String {
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">return</span> String::from(<span style="color:#e6db74">&#34;Hello World&#34;</span>);
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><h3 id="cli-application">CLI Application</h3>
<p>For our CLI application, we&rsquo;ll create a <code>main</code> function that calls our new <code>greeting</code> function. This will live in <code>src/main.rs</code></p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-rust" data-lang="rust"><span style="display:flex;"><span><span style="color:#66d9ef">use</span> rustwasm;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">fn</span> <span style="color:#a6e22e">main</span>() {
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">let</span> _args <span style="color:#f92672">=</span> std::env::args();
</span></span><span style="display:flex;"><span>    println!(<span style="color:#e6db74">&#34;</span><span style="color:#e6db74">{}</span><span style="color:#e6db74">&#34;</span>, rustwasm::greeting());
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>I include the <code>_args</code> variable to show how you would obtain the command-line arguments, however we won&rsquo;t do anything with those in this example.</p>
<p>To run this in the CLI, we first need to compile the <code>wasm</code> file.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>cargo build --target wasm32-wasi --release
</span></span></code></pre></div><p>Then we can use <a href="https://wasmtime.dev/"><code>wasmtime</code></a> to execute the file</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>wasmtime target/wasm32-wasi/release/rustwasm.wasm
</span></span></code></pre></div><p>Feel free to distribute <code>rustwasm.wasm</code> among your friends to run on their machines as well!</p>
<h3 id="web-application">Web application</h3>
<p>Now let&rsquo;s show how we would run this in the web! First let&rsquo;s create a <code>public</code> folder at the base of the Rust project which we&rsquo;ll use to host the website code.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>mkdir public
</span></span></code></pre></div><p>Within <code>public/index.html</code> include the following:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-html" data-lang="html"><span style="display:flex;"><span><span style="color:#75715e">&lt;!DOCTYPE html&gt;</span>
</span></span><span style="display:flex;"><span>&lt;<span style="color:#f92672">html</span>&gt;
</span></span><span style="display:flex;"><span>  &lt;<span style="color:#f92672">head</span>&gt;
</span></span><span style="display:flex;"><span>    &lt;<span style="color:#f92672">meta</span> <span style="color:#a6e22e">charset</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;utf-8&#34;</span>&gt;
</span></span><span style="display:flex;"><span>    &lt;<span style="color:#f92672">title</span>&gt;Hello wasm!&lt;/<span style="color:#f92672">title</span>&gt;
</span></span><span style="display:flex;"><span>  &lt;/<span style="color:#f92672">head</span>&gt;
</span></span><span style="display:flex;"><span>  &lt;<span style="color:#f92672">body</span>&gt;
</span></span><span style="display:flex;"><span>    &lt;<span style="color:#f92672">script</span> <span style="color:#a6e22e">type</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;module&#34;</span> <span style="color:#a6e22e">src</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;index.js&#34;</span>&gt;&lt;/<span style="color:#f92672">script</span>&gt;
</span></span><span style="display:flex;"><span>  &lt;/<span style="color:#f92672">body</span>&gt;
</span></span><span style="display:flex;"><span>&lt;/<span style="color:#f92672">html</span>&gt;
</span></span></code></pre></div><p><em>Note the <code>type=&quot;module&quot;</code> within the script tag.</em></p>
<p>The JavaScript code we have to write luckily is minimal since <code>rust-bindgen</code> does the majority of the work for us. Note that we&rsquo;re not running the<code>main</code> function within <code>main.rs</code>. Instead, we only have access to the methods, structs, etc that are public and annotated with <code>#[rust_bindgen]</code> beforehand.</p>
<p>Recall in <code>lib.rs</code> that we have the <code>greeting</code> function. We would incorporate that into our web application through the following code within <code>public/index.js</code></p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span><span style="color:#66d9ef">import</span> <span style="color:#a6e22e">init</span>, <span style="color:#f92672">*</span> <span style="color:#a6e22e">as</span> <span style="color:#a6e22e">wasm</span> <span style="color:#a6e22e">from</span> <span style="color:#e6db74">&#34;./rustwasm.js&#34;</span>;
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">await</span> <span style="color:#a6e22e">init</span>();
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">console</span>.<span style="color:#a6e22e">log</span>(<span style="color:#a6e22e">wasm</span>.<span style="color:#a6e22e">greeting</span>());
</span></span></code></pre></div><p>Now, we need to compile our codebase and use <code>wasm-bindgen</code> to generate the glue code.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>cargo build --target wasm32-unknown-unknown --release
</span></span><span style="display:flex;"><span>wasm-bindgen target/wasm32-unknown-unknown/release/rustwasm.wasm --out-dir public --target web
</span></span></code></pre></div><p><em>Note: Everytime you update your Rust code, you&rsquo;ll need to run both those commands</em></p>
<p>To test this, we can quickly spin up a Python web server.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>cd public
</span></span><span style="display:flex;"><span>python -m http.server
</span></span></code></pre></div><p>By default your web application would be served at https://localhost:8000. If you open up your console and refresh, you should see the <code>&quot;Hello World&quot;</code> message printed.</p>
<h2 id="more-web-examples">More Web Examples</h2>
<p>Through the magic of <code>wasm-bindgen</code>, we were able to create a function in Rust that returns a string, and without having to think about the internals of Webassembly, get a JavaScript string on the other side.</p>
<p>The primary usecase of WebAssembly in my mind, is to offload heavier computations. You can edit the DOM directly using the <a href="https://rustwasm.github.io/wasm-bindgen/api/web_sys/"><code>web-sys</code></a> crate. However, I&rsquo;ll focus my remaining examples and getting data in and out of the compiled Rust code.</p>
<p><strong>Example:</strong> Calling a Rust-wasm function with a primitive argument</p>
<p>Let&rsquo;s create a small Rust function that takes an integer and outputs the integer plus one.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-rust" data-lang="rust"><span style="display:flex;"><span><span style="color:#75715e">#[wasm_bindgen]</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">pub</span> <span style="color:#66d9ef">fn</span> <span style="color:#a6e22e">plusone</span>(x: <span style="color:#66d9ef">i32</span>) -&gt; <span style="color:#66d9ef">i32</span> {
</span></span><span style="display:flex;"><span>    x <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span>
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>Remember to mark the function as public (<code>pub</code>) and annotate it with <code>#[wasm_bindgen]</code> in order for it to be available in the JavaScript.</p>
<p>Recompile the Rust code using the two commands from earlier, and edit the <code>public/index.js</code> function to log an example output of the function.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span><span style="color:#a6e22e">console</span>.<span style="color:#a6e22e">log</span>(<span style="color:#a6e22e">wasm</span>.<span style="color:#a6e22e">plusone</span>(<span style="color:#ae81ff">5</span>))
</span></span></code></pre></div><p>Be careful with what primitive types we use in Rust. If you were to change <code>i32</code> to <code>u32</code> and call the function in JavaScript with a negative number, then the Rust Wasm side will reinterpret the negative number as a large <code>u32</code>.</p>
<p><strong>Example:</strong> Taking in arbitrary JavaScript values (Dictionaries, arrays, etc.)</p>
<p>Using the <a href="https://rustwasm.github.io/wasm-bindgen/api/js_sys/index.html"><code>js-sys</code></a> crate, we can take an arbitrary JavaScript value as a parameter and use the <code>Reflect</code> module to access field names or interpret the data.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-rust" data-lang="rust"><span style="display:flex;"><span><span style="color:#75715e">#[wasm_bindgen]</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">pub</span> <span style="color:#66d9ef">fn</span> <span style="color:#a6e22e">get_name</span>(obj: <span style="color:#a6e22e">JsValue</span>) -&gt; String {
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">let</span> key <span style="color:#f92672">=</span> JsValue::from_str(<span style="color:#e6db74">&#34;name&#34;</span>);
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">let</span> value_option <span style="color:#f92672">=</span> js_sys::Reflect::get(<span style="color:#f92672">&amp;</span>obj, <span style="color:#f92672">&amp;</span>key)
</span></span><span style="display:flex;"><span>        .ok()
</span></span><span style="display:flex;"><span>        .and_then(<span style="color:#f92672">|</span>v<span style="color:#f92672">|</span> v.as_string());
</span></span><span style="display:flex;"><span>    value_option.unwrap_or_else(<span style="color:#f92672">||</span> String::from(<span style="color:#e6db74">&#34;Error encountered&#34;</span>))
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>In the example above, we take a JavaScript value called <code>obj</code> and attempt to access the <code>name</code> field as a string. Since <code>obj</code> can be any arbitrary JavaScript value, we need to include error handling within our code. There are three possible error conditions:</p>
<ul>
<li><code>obj</code> is not a JavaScript object (within <code>js_sys::Reflect::get</code>)</li>
<li><code>&quot;name&quot;</code> is not a field in the object (also within <code>js_sys::Reflect::get</code>)</li>
<li><code>obj.name</code> is not a string (within <code>.as_string()</code>)</li>
</ul>
<p>It&rsquo;s a little burdensome to write this code. But given that JavaScript isn&rsquo;t a typed language, it&rsquo;s amazing we can process arbitrary JavaScript values at all.</p>
<p><strong>Example:</strong> Returning a <code>struct</code> from Rust-wasm</p>
<p>Say we have a <code>Person</code> struct.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-rust" data-lang="rust"><span style="display:flex;"><span><span style="color:#75715e">#[wasm_bindgen]</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">pub</span> <span style="color:#66d9ef">struct</span> <span style="color:#a6e22e">Person</span> {
</span></span><span style="display:flex;"><span>    name: String,
</span></span><span style="display:flex;"><span>    age: <span style="color:#66d9ef">u32</span>,
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>In order for this struct to be accessible in the JavaScript, we&rsquo;ll need to make it public (<code>pub</code>) and add the <code>#[wasm_bindgen]</code> annotation.</p>
<p>Additionally, JavaScript objects have constructors and getter functions. We&rsquo;ll need to implement those publicly within Rust and add the right annotations.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-rust" data-lang="rust"><span style="display:flex;"><span><span style="color:#75715e">#[wasm_bindgen]</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">impl</span> Person {
</span></span><span style="display:flex;"><span>    <span style="color:#75715e">#[wasm_bindgen(constructor)]</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">pub</span> <span style="color:#66d9ef">fn</span> <span style="color:#a6e22e">new</span>(name: String, age: <span style="color:#66d9ef">u32</span>) -&gt; <span style="color:#a6e22e">Person</span> {
</span></span><span style="display:flex;"><span>        Person { name, age }
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>     
</span></span><span style="display:flex;"><span>    <span style="color:#75715e">// Getter for name field
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>    <span style="color:#66d9ef">pub</span> <span style="color:#66d9ef">fn</span> <span style="color:#a6e22e">name</span>(<span style="color:#f92672">&amp;</span>self) -&gt; String {
</span></span><span style="display:flex;"><span>        self.name.clone()
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>    
</span></span><span style="display:flex;"><span>    <span style="color:#75715e">// Getter for the age field
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>    <span style="color:#66d9ef">pub</span> <span style="color:#66d9ef">fn</span> <span style="color:#a6e22e">age</span>(<span style="color:#f92672">&amp;</span>self) -&gt; <span style="color:#66d9ef">u32</span> {
</span></span><span style="display:flex;"><span>        self.age
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>Lastly, let&rsquo;s create a small function that returns a  specific <code>Person</code> struct.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-rust" data-lang="rust"><span style="display:flex;"><span><span style="color:#75715e">#[wasm_bindgen]</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">pub</span> <span style="color:#66d9ef">fn</span> <span style="color:#a6e22e">bob</span>() -&gt; <span style="color:#a6e22e">Person</span> {
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">return</span> Person::new(String::from(<span style="color:#e6db74">&#34;Bob&#34;</span>), <span style="color:#ae81ff">22</span>)
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>Now within <code>public/index.js</code>, we can call <code>wasm.bob()</code> and bring over the new person object. From there, we can access its fields using the getter methods.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">person</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">wasm</span>.<span style="color:#a6e22e">bob</span>();
</span></span><span style="display:flex;"><span><span style="color:#a6e22e">console</span>.<span style="color:#a6e22e">log</span>(<span style="color:#e6db74">&#34;Name: &#34;</span> <span style="color:#f92672">+</span> <span style="color:#a6e22e">person</span>.<span style="color:#a6e22e">name</span>() <span style="color:#f92672">+</span> <span style="color:#e6db74">&#34;, Age: &#34;</span> <span style="color:#f92672">+</span> <span style="color:#a6e22e">person</span>.<span style="color:#a6e22e">age</span>);
</span></span></code></pre></div><p>That&rsquo;s all for today! From here the world is our oyster. We can leverage the type safe and efficient properties of Rust and write code that&rsquo;s not only available on the Web, but also through the CLI; all while being architecture-independent.</p>
]]></content:encoded>
  <category>WebAssembly</category>
  <category>Rust</category>
  
</item>
  
  <item>
  <title></title>
  <link></link>
  <pubDate>Thu, 30 Jan 2025 03:17:13 +0000</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid></guid>
  <description><![CDATA[<p>Blog Question Challenge: Complete! Thanks <span class="h-card" translate="no"><a href="https://fosstodon.org/@markpitblado" class="u-url mention">@<span>markpitblado</span></a></span> for the tag ⚡ </p><p><a href="https://brandonrozek.com/blog/blog-question-challenge-jan2025/" target="_blank" rel="nofollow noopener noreferrer" translate="no"><span class="invisible">https://</span><span class="ellipsis">brandonrozek.com/blog/blog-que</span><span class="invisible">stion-challenge-jan2025/</span></a></p>]]></description>
  <content:encoded><![CDATA[<p>Blog Question Challenge: Complete! Thanks <span class="h-card" translate="no"><a href="https://fosstodon.org/@markpitblado" class="u-url mention">@<span>markpitblado</span></a></span> for the tag ⚡ </p><p><a href="https://brandonrozek.com/blog/blog-question-challenge-jan2025/" target="_blank" rel="nofollow noopener noreferrer" translate="no"><span class="invisible">https://</span><span class="ellipsis">brandonrozek.com/blog/blog-que</span><span class="invisible">stion-challenge-jan2025/</span></a></p>]]></content:encoded>
  
</item>
  
  <item>
  <title>Blog Question Challenge (Jan 2025)</title>
  <link>https://brandonrozek.com/blog/blog-question-challenge-jan2025/</link>
  <pubDate>Wed, 29 Jan 2025 21:18:03 -0500</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid>https://brandonrozek.com/blog/blog-question-challenge-jan2025/</guid>
  <description><![CDATA[<p>Catching up on my RSS feeds, <a href="https://blog.avas.space/bear-blog-challenge/">Ava&rsquo;s bear blog question challenge</a> has been making the rounds. The last blogging trend I remember going viral was <a href="https://defaults.rknight.me/">App Defaults</a> inspired by an episode of <a href="https://listen.hemisphericviews.com/097">Hemispheric Views</a> back in November 2023. I felt too awkward last time around to take part, and I wouldn&rsquo;t have said anything this time either, except that I got tagged by <a href="https://www.markpitblado.me/blog/blog-question-challenge-2025">Mark Pitblado</a>.</p>
<p>Nothing makes you feel more cool on the Internet than getting tagged to participate.</p>]]></description>
  <content:encoded><![CDATA[<p>Catching up on my RSS feeds, <a href="https://blog.avas.space/bear-blog-challenge/">Ava&rsquo;s bear blog question challenge</a> has been making the rounds. The last blogging trend I remember going viral was <a href="https://defaults.rknight.me/">App Defaults</a> inspired by an episode of <a href="https://listen.hemisphericviews.com/097">Hemispheric Views</a> back in November 2023. I felt too awkward last time around to take part, and I wouldn&rsquo;t have said anything this time either, except that I got tagged by <a href="https://www.markpitblado.me/blog/blog-question-challenge-2025">Mark Pitblado</a>.</p>
<p>Nothing makes you feel more cool on the Internet than getting tagged to participate.</p>
<h2 id="why-did-you-start-blogging">Why did you start blogging?</h2>
<p>In the sappiest way possible, I&rsquo;m not sure where I would be in life if the Internet didn&rsquo;t exist. It&rsquo;s really the generosity of people that share the things they&rsquo;ve learned and the life they&rsquo;ve lived, that helps guide me through mine.</p>
<p>For this reason, blogging for me has originally served two purposes:</p>
<ol>
<li>To give back to the community by sharing what I&rsquo;ve learned;</li>
<li>To serve as a second-brain for myself, lest I forget.</li>
</ol>
<p>As time progresses, I&rsquo;ve been slowly exploring blogging from a more social context. A recent addition to my website is <code>/postroll</code>, where I give shout-outs to <a href="https://brandonrozek.com/postroll/">blog posts I&rsquo;ve enjoyed</a>. Previously, I&rsquo;ve written a couple <a href="blog/on-earbuds/">reply</a> <a href="/blog/re-static-plus/">posts</a>, and I&rsquo;m less shy on reaching out to fellow bloggers over email.</p>
<p>To the last point, I&rsquo;m always ecstatic when a reader reaches out to me. <a href="https://brandonrozek.com/contact/">That could be you!</a></p>
<h2 id="what-platforms-are-you-using-for-your-blog-and-why">What platforms are you using for your blog, and why?</h2>
<p>I currently use the static site generator <a href="https://gohugo.io/">Hugo</a> which takes my blog posts written in Markdown, and presents this great HTML that you&rsquo;re reading right now!</p>
<p>My website files are hosted on two servers.  One in New York City hosted by <a href="https://easyvm.net/">EasyVM</a> and another in Singapore hosted by <a href="https://greencloudvps.com/">GreenCloud</a>. The server you&rsquo;re talking to right now is hopefully the one closest to you. Check out my <a href="/blog/implementing-cdn-geodns/">GeoDNS post</a> to learn more.</p>
<p>For all I know though, you dear reader are from the distant unforeseeable future. If so, hello! I can&rsquo;t guarantee that anything from this section is correct anymore. This website may be <em>quantum powered</em> instead.</p>
<h2 id="have-you-blogged-on-other-platforms-before">Have you blogged on other platforms before?</h2>
<p>In what feels like an eternity ago, my blog used to run on a self-hosted version of Wordpress. Unfortunately, the server provider I was with has faded from my memory. Exactly when the switch occurred is lost to the sands of time as well. According to the <a href="https://web.archive.org/web/20190901000000*/brandonrozek.com">Internet Archive</a>, I started using Hugo sometime between April to July 2019.<sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup></p>
<p>On a separate note, even though I don&rsquo;t actively use them myself, I&rsquo;m a huge fan of <a href="/blog/tildeverse/">tildespaces</a>. I first discovered them during my undergraduate days, and unfortunately that page has since been taken down. Nowadays, I currently have one at my <a href="https://www.cs.rpi.edu/~rozekb">graduate institution</a> and you can also find me on <a href="https://tilde.club/~brozek/">Tilde Club</a>.</p>
<h2 id="how-do-you-write-your-posts">How do you write your posts?</h2>
<p>Since I write my posts in Markdown, I open up <a href="https://typora.io/">Typora</a> and button smash until the words stop coming out. I use <code>hugo serve</code> to check that the page renders fine, and then I commit the Markdown file to my website&rsquo;s <a href="https://github.com/brandon-rozek/website">GitHub repository</a>. From there, some <a href="/blog/deploying-hugo-website-through-gh-actions/">automation</a> kicks off which rebuilds my website.</p>
<p>I like to tell myself that I <a href="/blog/vale-linter-human-prose/">lint my blog posts</a>, but let&rsquo;s be real. Who likes having their computer tell them they&rsquo;re wrong? Most of the time these posts escape that extra scrutiny.</p>
<h2 id="when-do-you-feel-most-inspired-to-write">When do you feel most inspired to write?</h2>
<p>Usually after I&rsquo;ve learned or done something cool. Honestly, there&rsquo;s a slight pressure for me to keep trying  new things, since the reward is that I can create a shiny new blog post. I&rsquo;m far from consistent with writing. I passively collect ideas I want to play around with, and then spend an evening going through my backlog.  This results in my publishing happening in bursts.</p>
<h2 id="do-you-normally-publish-immediately-after-writing-or-do-you-let-it-simmer-a-bit">Do you normally publish immediately after writing, or do you let it simmer a bit?</h2>
<p>In an effort to get posts out of the door, I rarely spend over one session in drafting them. I let these drafts rest a day and give them a quick proof-read when my mind is clear. Since I go through my backlog in batches, I try to keep myself to a one-post-a-day rule. I personally don&rsquo;t like receiving a bunch of updates all at once, so I try my best to not subject my readers to that.</p>
<p>This post happens to be an exception! I created this over <em>two</em> whole sessions.</p>
<h2 id="whats-your-favorite-post-on-your-blog">What&rsquo;s your favorite post on your blog?</h2>
<p>Writing for many years now, I won&rsquo;t say that I have an absolute favorite. If forced to pick from 2024, I would probably say my post on <a href="/blog/ice-hockey/">Ice Hockey</a>. It gives a little taste of my personal life while also cataloging what I&rsquo;ve learn so far about the sport. My favorite technical deep-dive post of 2024 has to be <a href="https://brandonrozek.com/blog/safety-constraints-pddl/">Constraints and Safety in PDDL</a>.</p>
<h2 id="any-future-plans-for-the-blog">Any future plans for the blog?</h2>
<p>My blog is coming up on its 10-year anniversary this April which is mind-boggling to me. The vast majority of my posts are technical pieces, and some are <a href="/blog/paying-for-things/">opinion</a> <a href="/blog/ai-fearmongering-regulatory-moat/">pieces</a>, and <a href="/blog/day-in-brooklyn/">travel</a> <a href="/blog/circling-around-vancouver/">logs</a>. Thinking about it now, I want to add two other types of pieces to my repertoire:</p>
<p><strong>Retrospectives:</strong> With the blog anniversary coming up, I&rsquo;m thinking about looking at some older pieces and see how my perspective has changed over time. I&rsquo;m also open to talking more about my life in general.</p>
<p><strong>State of TOPIC:</strong> Back in 2019, what services did I run on my homelab? Unfortunately, I can&rsquo;t recall! With all the technical posts, we can likely infer that I ran a service that I talked about.  However, it would be much simpler and likely more useful to people if I cataloged everything that I&rsquo;m doing at a particcular moment for TOPIC. Currently thinking of my website and homelab.</p>
<h2 id="who-will-participate-next">Who will participate next?</h2>
<p>I tag <a href="https://emar10.dev/">Ethan Martin</a>, <a href="https://html-chunder.neocities.org/">Zak</a>, and <a href="https://bacardi55.io/">bacardi55</a>. Hopefully you&rsquo;ll take part, and if you do, I&rsquo;ll link your response below.</p>
<p><strong>Update</strong>:</p>
<ul>
<li><a href="https://bacardi55.io/2025/01/31/blog-question-challenge-jan-2025/">bacardi55&rsquo;s response</a></li>
<li><a href="https://html-chunder.neocities.org/blog/blogging/">Zak&rsquo;s response</a></li>
<li><a href="https://emar10.dev/posts/blog-question-challenge-jan2025/">Ethan&rsquo;s response</a></li>
</ul>
<div class="footnotes" role="doc-endnotes">
<hr>
<ol>
<li id="fn:1">
<p>Makes me wish I wrote one of those &ldquo;I switched my website to Hugo!&rdquo; blog posts&#160;<a href="#fnref:1" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
</ol>
</div>
]]></content:encoded>
  <category>blogging</category>
  
</item>
  
  <item>
  <title></title>
  <link></link>
  <pubDate>Sun, 05 Jan 2025 16:50:02 +0000</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid></guid>
  <description><![CDATA[]]></description>
  <content:encoded><![CDATA[]]></content:encoded>
  
</item>
  
  <item>
  <title></title>
  <link></link>
  <pubDate>Sun, 05 Jan 2025 01:12:26 +0000</pubDate>
  <author>brozek@brandonrozek.com (Brandon Rozek)</author>
  <guid></guid>
  <description><![CDATA[<p><span class="h-card" translate="no"><a href="https://mathstodon.xyz/@ejk" class="u-url mention">@<span>ejk</span></a></span> Gotta fill out the hobbydex!</p>]]></description>
  <content:encoded><![CDATA[<p><span class="h-card" translate="no"><a href="https://mathstodon.xyz/@ejk" class="u-url mention">@<span>ejk</span></a></span> Gotta fill out the hobbydex!</p>]]></content:encoded>
  
</item>
  
  </channel>
</rss>