<?xml version="1.0" encoding="utf-8"?>
<?xml-model href="../atom.xsd"?>
<?xml-stylesheet href="/atom.xsl" type="text/xsl"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title>nleanba’s website</title>
  <id>https://nleanba.ch/</id>

  <author>
    <name>nleanba</name>
    <uri>https://nleanba.ch/</uri>
  </author>

  <link href="https://nleanba.ch/" rel="alternate" />
  <link href="https://nleanba.ch/feed.xml" rel="self" />

  <icon>/img/favicon.svg</icon>

  <updated>2025-08-06T15:10:00+02:00</updated>

  <!-- NEW ITEMS HERE -->
  <!-- remember to set <updated> above -->
  <!-- remember to remove <embed>, swap <n-code> for <pre>, and fix relative links -->

  <entry>
    <title>Fairphone</title>
    <updated>2026-08-29T17:10:00+02:00</updated>
    <id>https://nleanba.ch/txt/2026-08-29-fairphone.html</id>
    <link rel="alternate" href="https://nleanba.ch/txt/2026-08-29-fairphone.html" />
    <summary type="html"><![CDATA[
      My thoughts after two months of <em>The Fairphone (Gen. 6)</em>
    ]]></summary>
  </entry>

  <entry>
    <title>Rendering Equations with Typst</title>
    <updated>2025-06-05T19:50:00+02:00</updated>
    <id>https://nleanba.ch/txt/2025-06-05-typst-equations.html</id>
    <link rel="alternate" href="https://nleanba.ch/txt/2025-06-05-typst-equations.html" />
    <content type="html"><![CDATA[
<article>
  <hgroup>
    <h1>Rendering Equations with Typst</h1>
    <p>2025-06-05</p>
  </hgroup>
  <p>
    I wanted to be able to have nice math formulas on my blog, and I wanted them to be written in typst.
    With the power of computers, I have achieved it:
    <img alt=" L(x,lambda) = f(x) + sum_(i in [n]) lambda_i g_i (x) " src="https://nleanba.ch/img/eq/2025-06-05-typst-equations-0.svg" style="vertical-align: -2.086680555555555mm;" class="equation">!
  <p role=note>
    You can find <a href="https://github.com/nleanba/equation-maker">the code on GitHub</a>.
    Note that the styling is hardcoded.
  </p>
  <p>
    To do this, I have written a script which looks for instances of three <code>[</code>s enclosing a formula,
    optionally starting with a <code>!</code> to indicate block-equations.
    It then (more or less) runs it through the following commands:
    <pre>
      $ typst compile template.typ - --format svg --input d=IS_BLOCK --input eq="FORMULA"
      $ typst query template.typ "&lt;down>" --input d=IS_BLOCK --input eq="FORMULA" --field value --one
    </pre>
  <p>
    The first command creates the svg, which gets added some styling to make the text-color match my blog and work in dark-mode:
    <pre>
      &lt;style>
      :root { color-scheme: light dark; }
      .typst-text use { fill: light-dark(oklch(0.35 0.035 215), oklch(0.98 0.015 215)) !important; }
      .typst-shape { stroke: light-dark(oklch(0.35 0.035 215), oklch(0.98 0.015 215)) !important; }
      &lt;/style>
    </pre>
  <p>
    The second command simply outputs the baseline height (in millimeters). This is used as
    <code>vertical-align: -___mm;</code>  on the <code>&lt;img></code> to properly align the equation with the surrounding text.
  <p>
    The typst <code>template.typ</code> is as follows:
    <pre>
      #{
        let display = eval(mode: "code", sys.inputs.at("d", default: "true"))
        let equation = eval(mode: "math", sys.inputs.at("eq", default: "quest.double"))
        let eq = math.equation(block: display, equation)
        set text(top-edge: "bounds", size: 13pt)
        show math.equation: set text(font: "IBM Plex Math")
        context {
          let rendered-tight = measure(eq).height
          set text(bottom-edge: "bounds")
          context {
            let rendered-loose = measure(eq).height
            let diff = rendered-loose - rendered-tight

            set page(
              width: auto,
              height: auto,
              margin: 0pt,
              fill: none,
            )
            [#metadata(diff.mm())&lt;down>]
            eq
          }
        }
      }
    </pre>
    Most of the complications here come from calculating the baseline height relative to the image boundary.
</article>
			]]></content>
  </entry>

  <entry>
    <title>Introducing my Bookmarks Feed</title>
    <updated>2025-05-28T01:00:00+02:00</updated>
    <id>https://nleanba.ch/txt/2025-05-28-bookmarks-feed.html</id>
    <link rel="alternate" href="https://nleanba.ch/txt/2025-05-28-bookmarks-feed.html" />
    <content type="html"><![CDATA[
<article>
  <hgroup>
    <h1>Introducing my Bookmarks Feed</h1>
    <p>2025-05-28</p>
  </hgroup>
  <p>
    In a blatant rip-off of <a href="https://dotat.at/:/">Tony Finch’s link log</a>,
    I have decided to also create a feed of “bookmarks” / links to interesting articles and such.
    <a href="https://nleanba.ch/bookmarks/">You can see it here.</a>
  <p>
    It is generated by a quick and dirty rust script <small>(if one can call any rust program a “script”)</small>
    from a <a href="https://kdl.dev/">KDL</a> file containing the metadata (<a href="https://nleanba.ch/bookmarks/source.kdl" style="font-family: monospace;">source.kdl</a>).
  <p role=note>
    The script currently completely hard-codes the “templates”, if I have the motivation I might make it more extensible and make it publicly available.
    If you’d be interested in it, do tell me, as that might motivate me to actually do it.
  </p>
  <p>
    The feed will probably get a lot of updates in the beginning, while I add a various articles I’ve saved previously.
</article>
			]]></content>
  </entry>

  <entry>
    <title>PDF Note-Taking Templates</title>
    <updated>2025-05-24T18:34:00+02:00</updated>
    <id>https://nleanba.ch/txt/2025-05-24-pdf-templates.html</id>
    <link rel="alternate" href="https://nleanba.ch/txt/2025-05-24-pdf-templates.html" />
    <content type="html"><![CDATA[
<article>
  <hgroup>
    <h1>PDF Templates</h1>
    <p>2025-05-24</p>
  </hgroup>
  <p>
    I like to take handwritten notes for my classes.
    (I use Goodnotes for this.)
  <p>
    A while ago, I made these templates for me to write on, in an effort to make my notes look better and more consistent.
    They might be useful for other people too…
  <p role=note>I generated them with a python script that places the lines on the page in a loop. It is not elegant enough for me to share here.</p>
  <ul>
    <li><a href="https://nleanba.ch/misc/Legal+ Yellow A4.pdf">Yellow A4</a>
    <li><a href="https://nleanba.ch/misc/Legal+ White A4.pdf">White A4</a>
    <li><a href="https://nleanba.ch/misc/Legal+ Yellow A5.pdf">Yellow A5</a>
    <li><a href="https://nleanba.ch/misc/Legal+ White A5.pdf">White A5</a>
    <li><a href="https://nleanba.ch/misc/Legal+Grid Yellow A4.pdf">Yellow A4 with square grid</a>
    <li><a href="https://nleanba.ch/misc/Legal+Grid Yellow A5.pdf">Yellow A5 with square grid</a>
  </ul>
  <p> Some Examples how this looks when I take notes:
  <div>
    <img style="width: 100%;" alt="(Example image showing my notes on some math exercise sheet)" src="https://nleanba.ch/img/pdf-template-example-1.png">
    <img style="width: 100%;" alt="(Example image showing my notes on a geometry class)" src="https://nleanba.ch/img/pdf-template-example-2.png">
  </div>
</article>
			]]></content>
  </entry>

  <entry>
    <title>New Website</title>
    <updated>2025-05-01T19:51:00+02:00</updated>
    <id>https://nleanba.ch/txt/2025-05-21-new-website.html</id>
    <link rel="alternate" href="https://nleanba.ch/txt/2025-05-21-new-website.html" />
    <content type="html"><![CDATA[
<article>
  <hgroup>
    <h1>New Website</h1>
    <p>2025-05-21</p>
  </hgroup>
  <p>
    I have decided to make a new website for myself.
    I used to have a blog that was generated with hugo (and had a whooping 2 posts, both now moved here),
    but I don't like markdown and am becoming less and less of a fan of anything that requires a build step.
  <p>
    So I am now writing a website directly in html.
    This was prompted by the general state of the world, and <a href="https://lmnt.me/blog/how-to-make-a-damn-website.html">a post on LMNT</a>.
    It is currently very plain, but I plan on adding fancy css and some progressive-enhancement javascript.
  <p>
    In particular, my wishlist includes:
  <ol>
    <li> Syntax highlighting
    <li>
      <del>"Copy" button for code blocks</del>
      <p role=note>2025-06-04: Added a <code>&lt;n-code></code> custom element which does this.</p>
    <li> a way to render equations, preferably using typst
  </ol>
</article>
			]]></content>
  </entry>

  <entry>
    <title>Factorial by Proxy</title>
    <updated>2024-04-16T00:00:00+02:00</updated>
    <id>https://nleanba.ch/txt/2024-04-16-factorial-by-proxy.html</id>
    <link rel="alternate" href="https://nleanba.ch/txt/2024-04-16-factorial-by-proxy.html" />
    <content type="html"><![CDATA[
<article>
  <hgroup>
    <h1>Factorial by Proxy</h1>
    <p>2024-04-16</p>
  </hgroup>
  <p>
    A cool snippet I came up with for calculating recursively defined sequences
    with built-in memoization.
  </p>
  <pre><code>const factorial = new Proxy([1], {
    get(f, n) {
      return f[n] ?? (f[n] = this.get(f, n-1) * n);
    }
});</code></pre>
  <p>Use like this:</p>
  <pre><code>factorial[0] // 1
factorial[1] // 1
factorial[2] // 2
factorial[3] // 6
             // ...</code></pre>
  <h2>Explanation:</h2>
  <p>
    The proxy allows us to overwrite property access on the array using a
    <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/Proxy/get">custom
      get function,</a>
    which we <del>abuse</del> use here to get a seemingly infinite array
    containing the entire sequence.
  </p>
  <p>
    Within it, we can <em>set</em> and <em>get</em> properties of the underlying
    array normally: <code>f[k] = 3</code> and <code>return f[n]</code> work as
    expected (the array is available as <code>f</code>). However, for recursion
    to work we want to use our new get, so we use <code>this.get(f, k)</code> to
    call the new getter recursively, calculating unknown
    (<code>undefined</code>) values along the way.
  </p>
  <p>
    Our get function does the following: if <code>f[n]</code> is already set—i.e.
    not undefined (or false)—it is returned instantly. Otherwise, we calculate it
    recursively, assign the calculated value to <code>f[n]</code> and return
    that value.
  </p>
  <p>
    Note that we don’t overwrite anything to do with iterators, so
    <code>factorial.forEach(...)</code> will only iterate over previously
    calculated values. If you want to be fancy, you could make it so that
    iterating works, that the underlying array cannot be modified other than
    from within the getter and maybe some handling for very large inputs or
    inputs &lt; 0.
  </p>
  <p>
    Judging by the
    <a
      href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/Proxy/get#browser_compatibility">browser
      compatibility for handler.get() listed on mdn</a>,
    this should work everywhere in browsers updated since 2016.
  </p>
  <h2>Other sequences:</h2>
  <p>
    Here’s how it looks for the Fibonacci numbers:
  </p>
  <pre><code>const fibonacci = new Proxy([0,1], {
    get(f, n) {
      return f[n] ?? (f[n] = this.get(f, n-2) + this.get(f, n-1));
    }
});

fibonacci[0] // 1
fibonacci[1] // 1
fibonacci[2] // 2
fibonacci[3] // 5
             // ...</code></pre>
  <p>
    Build your own:
  </p>
  <pre><code>const yourSequence = new Proxy([/* array containing the first elements of the sequence */], {
    get(f, n) {
      return f[n] ?? (f[n] = /* formula to calculate the n-th element,
                                use `this.get(f, k)` instead of `f[k]` or `yourSequence[k]` */);
    }
});</code></pre>
</article>
			]]></content>
  </entry>

  <entry>
    <title>Blocking the new .zip TLD on Fedora</title>
    <updated>2023-05-20T00:00:00+02:00</updated>
    <id>https://nleanba.ch/txt/2023-05-20-blocking-zip-tld-on-fedora.html</id>
    <link rel="alternate" href="https://nleanba.ch/txt/2023-05-20-blocking-zip-tld-on-fedora.html" />
    <content type="html"><![CDATA[
<article>
  <hgroup>
    <h1>Blocking the new .zip TLD on Fedora</h1>
    <p>2023-05-20</p>
  </hgroup>
  <h2>Why:</h2>
  <p>
    Because it seems like it might provide some (idk) security benefits, and because
    it seemed like an interesting exercise, I wanted to figure out how to block any
    requests to a .zip url from my laptop.
  </p>
  <h2>How:</h2>
  <p>Trying to do so using the bind-DNS server</p>
  <ol>
    <li>
      <p>Installing bind:</p>
      <pre><code>dnf install bind</code></pre>
    </li>
    <li>
      <p>Updating/Creating various Config files:</p>
      <ol>
        <li>
          <p>Adding a zip zone to <code>/etc/named.conf</code>:</p>
          <pre><code>//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//

options {
	listen-on port 53 { 127.0.0.1; };
	listen-on-v6 port 53 { ::1; };
	directory 	"/var/named";
	dump-file 	"/var/named/data/cache_dump.db";
	statistics-file "/var/named/data/named_stats.txt";
	memstatistics-file "/var/named/data/named_mem_stats.txt";
	secroots-file	"/var/named/data/named.secroots";
	recursing-file	"/var/named/data/named.recursing";
	allow-query     { localhost; };

	recursion yes;

	dnssec-validation yes;
	managed-keys-directory "/var/named/dynamic";
	geoip-directory "/usr/share/GeoIP";

	pid-file "/run/named/named.pid";
	session-keyfile "/run/named/session.key";

	/* https://fedoraproject.org/wiki/Changes/CryptoPolicy */
	include "/etc/crypto-policies/back-ends/bind.config";

	/* nope -- pointless */
	// response-policy { zone "zip"; };
};

logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};

// This is new:
zone "zip" IN {
	type master;
	file "zip-rpz";
	allow-update { none; };
};

zone "." IN {
	type hint;
	file "named.ca";
};

include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";

</code></pre>
        </li>
        <li>
          <p>Added <code>/var/named/zip-rpz</code>:</p>
          <pre><code>$TTL 1D ; default expiration time of all RRs without their own TTL value
@       IN  SOA     ns.zip. postmaster.ns.zip. ( 2020091025 7200 3600 1209600 3600 )
@       IN  NS      ns                     ; nameserver
*       IN  A       127.0.0.1              ; localhost
        IN  AAAA    ::                     ; localhost
</code></pre>
        </li>
      </ol>
    </li>
    <li>
      <p>Apply temporarily</p>
      <pre><code>sudo systemctl enable named
sudo service named restart
resolvectl dns wlp0s20f3 127.0.0.1
</code></pre>
      <p role=note>Note: this applies it <em>very</em> temporarily (ca 2 mins, idk why)</p>
      <p>Various other commands, some useful:</p>
      <pre><code>journalctl -xeu named.service

dig url.zip
dig example.com

# ??
sudo firewall-cmd --add-service=dns --perm
sudo firewall-cmd --reload

# ??
sudo chgrp named -R /var/named
sudo chown -v root:named /etc/named.conf
sudo restorecon -rv /var/named
sudo restorecon /etc/named.conf
</code></pre>
    </li>
    <li>
      <p>Apply persistently</p>
      <pre><code># ...
[Resolve]
# ... add the following line inside the [Resolve] section:
DNS=127.0.0.1
# ...</code></pre>
      <p>After rebooting, it now “fails” to resolve any .zip url.<br>They are redirected to <code>127.0.0.1</code> (or
        <code>::</code>) where nobody is listening…
      </p>
    </li>
    <li>
      <p><del>Profit</del></p>
    </li>
  </ol>
</article>
			]]></content>
  </entry>

</feed>
