<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<rss version="2.0">
  <channel>
    <title>Haylin's blog</title>
    <link>https://hayl.in/posts/</link>
    <description>Haylin's writings, rambles, and sometimes tutorials</description>
    <language>en-us</language>
    <pubDate>Fri, 4 Dec 2026 00:34:00 +0000</pubDate>
    <generator>https://github.com/haylinmoore/www</generator>
    <ttl>1440</ttl>
    <item>
      <title>Custom AMQ Filter for Fast Substring Search</title>
      <guid>https://hayl.in/posts/substring</guid>
      <link>https://hayl.in/posts/substring</link>
      <description><![CDATA[<h2>The Problem</h2>
<p>Recently, my friend <a href="https://zptr.cc/">Yui</a> asked me to help find a way to search for all elements that included a given word on her site <a href="https://infinibrowser.wiki/">infinibrowser.wiki</a>, which has ~10 million elements.
As part of the problem this substring search needed to <a href="https://docs.google.com/spreadsheets/d/1PRtlXvjbHs4ulct6gSbYc6VYrQegU7HZ5SdhThkHuoY/edit?gid=965823706#gid=965823706">support all unicode characters</a> we could throw at it, with there being projects to uncover a recipe for every unicode character in Infinicraft.
Everything she tried was either slow (500ms+ per search) or didn't handle unicode properly with lots of solutions stripping away various parts of unicode.</p>
<h2>Enter AMQ Filters</h2>
<p>I'd heard of Approximate Membership Query (AMQ) filters before but never had a good excuse to build one.
Turns out this was perfect - an AMQ can quickly tell you &quot;might this element be in the set?&quot;
You get one of two answers: &quot;definitely not&quot; (which is always right) or &quot;maybe&quot; (which might be wrong).</p>
<p>What makes AMQs so useful here is that they never lie when they say no.
If an AMQ says &quot;nope, not there&quot;, you can trust it completely.
But if it says &quot;maybe&quot;, well, you gotta double-check because it might be getting excited over nothing.
They're also tiny compared to storing everything, and checking them is super fast.</p>
<p>So here's the plan: use the AMQ as a bouncer.
If it says &quot;definitely not&quot;, we skip that string entirely.
If it says &quot;maybe&quot;, we do the actual substring search to be sure.</p>
<h2>Our Custom AMQ Design</h2>
<p>For substring search, we need an AMQ that can answer: &quot;could this string contain this substring?&quot;</p>
<p>The trick is pretty simple: if a character shows up in a substring, it has to show up in the full string too.
So we can make a little fingerprint for each string based on what characters it has.</p>
<p>I decided to use a 64-bit number as the fingerprint.
For each character in a string, we set a bit:</p>
<pre><code class="language-rust">for each character c in string:
    bit_position = (c as u32) % 64
    amq_filter |= (1 &lt;&lt; bit_position)
</code></pre>
<h2>How the Query Works</h2>
<p>When someone searches for something, we make a fingerprint for their query the same way.
We generate a fingerprint for every element in our dataset and iterate over each of them, checking to see if the query fingerprint passes the check:</p>
<pre><code class="language-rust">if (element_filter &amp; query_filter) == query_filter {
    // All query characters are present in the string
    // Might contain substring - do full string search
    if element.contains(query) {
        results.push(element);
    }
} else {
    // Query contains characters not in the string
    // Definitely doesn't contain substring - skip entirely
}
</code></pre>
<h2>Why This Works</h2>
<p>The whole thing hinges on a simple fact: you can't have a substring without having all its characters.
If a string is missing even one character from your query, there's no way it can contain that substring.</p>
<p>That bitwise check <code>(element_filter &amp; query_filter) == query_filter</code> is doing all the heavy lifting.
Instead of checking every character in every string, we just do one 64-bit operation and know immediately if we can skip it.</p>
<h2>Results</h2>
<p>It worked way better than I expected.
Searches went from taking hundreds of milliseconds down to single digits.
The AMQ filter threw out most strings without doing a costly substring, leaving just a tiny handful that needed the full substring check.</p>]]></description>
      <pubDate>Sun, 8 Jun 2025 00:00:00 +0800</pubDate>
    </item>
    <item>
      <title>CDMA</title>
      <guid>https://hayl.in/posts/cdma-example</guid>
      <link>https://hayl.in/posts/cdma-example</link>
      <description><![CDATA[<h2>CDMA Interactive Demo</h2>
<style>
  td {
    width: 1.5rem;
  }
</style>
<div style="font-family: monospace">
  <br>
  <input type="range" id="walsh_depth" name="walsh" min="1" max="4" value="1" />
  <label for="walsh">Senders: <span id="senders_count">2</span></label>
  <br>
  First the desired sender count must be chosen so that sender codes can be calculated.
  <h4>Walsh Table</h4>
  A <a href="https://en.wikipedia.org/wiki/Walsh_matrix">Walsh matrix</a> is used to generate orthogonal codes
  <table id="walsh" border="1">
    <tbody align="right"></tbody>
  </table>
  <h4>Per Sender Code</h4>
  Each sender's orthogonal is taken from the relevant row on the Walsh table
  <pre id="senders_list">
  </pre>
  <h4>Encoded Message</h4>
  Each sender can send one trit (-1, 0, 1) at a time.
  The first input corresponds to sender 0's data point, the second one is sender 1, etc
  <div id="inputs"></div>
  <br>
  <input id="calculate" type="button" value="Calculate" />
  <div id="calculation" style="display: none">
    <h4>Per Sender Transmission</h4>
    The sender's data (input i) multiplied by the senders code
    <pre id="transmission"></pre>
    <h4>Received Transmission</h4>
    This is the sum of the transmissions, as the waves from each sender constructively and destructively collide
    <pre id="received"></pre>
    <h4>Decoded Transmission</h4>
    By multiplying the received transmission by the sender's code, the original data can be recovered
    <pre id="decoded"></pre>
  </div>
</div>
<script>
const arrayLength = (n) => new Array(n).fill(undefined);

/*
  Making a Walsh table
  W1 = [1]
  W2i = [ Wi Wi ]
        [ Wi WiC]
*/
const walsh_round = (matrix) => {
  const len = matrix.length
  let out = arrayLength(len*2).map(v=>arrayLength(len*2))

  matrix.forEach((line, row) => {
    line.forEach((v, col) => {
      out[row][col] = v;
      out[row][col + len] = v;
      out[row + len][col] = v;
      out[row + len][col + len] = v * -1;
    })
  })
  return out;
}

const walsh = (n) => arrayLength(n).reduce((inc)=>walsh_round(inc), [[1]])

let state = {
  depth: 1,
  senders: 2,
  codes: [],
}

const tritSameLength = (v) => String(v).padStart(2, " ")
const swapTableBody = (table, array2D) => table.querySelector('tbody').innerHTML = array2D.map(row => `<tr>${row.map(cell => `<td>${tritSameLength(cell)}</td>`).join('')}</tr>`).join('');

const updateWalsh = (v) => {
  state.depth = v;
  state.senders = Math.pow(2, state.depth)

  // Generate the walsh matrix
  state.codes = walsh(state.depth);

  // Display the walsh matrix
  swapTableBody(document.getElementById("walsh"), state.codes)
  document.getElementById("senders_count").innerHTML = state.senders;
  document.getElementById("senders_list").innerHTML = state.codes.map((v, i)=>`Sender ${String(i).padStart(state.senders > 9? 2: 1, " ")}: [${v.map(tritSameLength).join(" ")} ]`).join("\n")
  document.getElementById("inputs").innerHTML = state.codes.map(()=>`<input type="number" min="-1" max="1" value="0">`).join(" ")
}

const walshDepth = document.getElementById("walsh_depth").addEventListener("change", (elm)=>{
  updateWalsh(Number(elm.target.value))
})

updateWalsh(1)

document.getElementById("calculate").addEventListener("click", ()=>{
  // Get the sender's data from the inputs
  const code = [...document.getElementById("inputs").children].map(v=>Number(v.value))

  // Multiply the sender's data by their code to get their transmission
  const transmit = state.codes.map((chip, sender_index)=>chip.map(v=>v * code[sender_index]))



  // Simulate the transmission by summing the transmissions from each sender
  const recv = arrayLength(state.senders)
    .map(
      (_, i) => transmit.reduce((acc, sender)=>acc+sender[i], 0)
    )

  // Recover the data by multiplying the received transmission by the sender's code
  const recovered_data = arrayLength(state.senders)
    .map((_, senderIndex)=> {
      const senderCode = state.codes[senderIndex];
      const multi = senderCode.map((v, j)=>v*recv[j]);
      // Sum each sender's matrix into a single value
      const val = multi.reduce((a, v)=>a+v, 0);

      return `Sender ${senderIndex}: [${recv.map(tritSameLength).join(" ")} ] * [${senderCode.map(tritSameLength).join(" ")} ] = [${multi.map(tritSameLength).join(" ")} ]\n\t- Sum: ${val}, Value: ${val/state.senders}\n`
  })

  // Display the results
  document.getElementById("received").innerHTML = `[ ${recv.join(" ")} ]`
  document.getElementById("transmission").innerHTML = transmit.map((v, i)=>`Sender ${String(i).padStart(state.senders > 9? 2: 1, " ")}: ${tritSameLength(code[i])} * [${state.codes[i].map(tritSameLength).join(" ")} ] = [${v.map(tritSameLength).join(" ")} ]`).join("\n")
  document.getElementById("decoded").innerHTML = recovered_data.join("\n");
  document.getElementById("calculation").style.display = "block";
})

</script>
<h2>Why</h2>
<p>Recently, in my wireless networking class we were covering CDMA, and I found it difficult to understand how the encoding and decoding process worked.
I made this interactive example to help me understand it better.
I felt that having something interactive could have better helped me understand the concept, and I hope it helps you too.</p>]]></description>
      <pubDate>Thu, 22 Feb 2024 00:00:00 +0800</pubDate>
    </item>
    <item>
      <title>nvim keybind for rendering markdown in glow</title>
      <guid>https://hayl.in/posts/nvim-glow</guid>
      <link>https://hayl.in/posts/nvim-glow</link>
      <description><![CDATA[<p>Some lua I wrote to let me render markdown in <a href="https://github.com/charmbracelet/glow">glow</a>.
It was my first time experimenting with hooking into the neovim APIs
and I'm pretty happy with how it turned out.
Hopefully it will be useful to someone else as guidance,
though I'm sure there are better ways to do this.</p>
<pre><code class="language-lua">local function render_markdown_with_glow()
  local tempfile = vim.fn.tempname() .. &quot;.md&quot;
  vim.cmd(&quot;write! &quot; .. tempfile)

  vim.cmd(&quot;enew&quot;)
  local bufnr = vim.api.nvim_get_current_buf()

  local command = &quot;terminal glow -p &quot; .. tempfile

  vim.cmd(command)

  vim.cmd(&quot;startinsert!&quot;)

  vim.api.nvim_create_autocmd(&quot;TermClose&quot;, {
    buffer = bufnr,
    callback = function()
      vim.loop.fs_unlink(tempfile)
      pcall(vim.api.nvim_buf_delete, bufnr, { force = true })
    end,
  })
end

vim.api.nvim_create_autocmd(&quot;FileType&quot;, {
  pattern = &quot;markdown&quot;,
  callback = function()
    vim.keymap.set(
      &quot;n&quot;,
      &quot;&lt;leader&gt;md&quot;,
      render_markdown_with_glow,
      { silent = true, buffer = true, desc = &quot;render markdown with glow&quot; }
    )
  end,
})
</code></pre>]]></description>
      <pubDate>Sun, 18 Feb 2024 00:00:00 +0800</pubDate>
    </item>
    <item>
      <title>SysDB and gNMI</title>
      <guid>https://hayl.in/posts/sysdb-and-gnmi</guid>
      <link>https://hayl.in/posts/sysdb-and-gnmi</link>
      <description><![CDATA[<h3>Exploring Sysdb with TerminAttr and REST API</h3>
<ol>
<li><strong>Enable TerminAttr</strong>: Begin by enabling the TerminAttr daemon on your device. This can be done with the following configuration commands:</li>
</ol>
<pre><code class="language-bash">spine1#config
spine1(config)#daemon TerminAttr
spine1(config-daemon-TerminAttr)#exec /usr/bin/TerminAttr -grpcaddr 0.0.0.0:6042
spine1(config-daemon-TerminAttr)#no shutdown
spine1(config-daemon-TerminAttr)#bash
</code></pre>
<p>This configuration initializes the TerminAttr service, which provides a REST API to explore its data, including Sysdb.</p>
<ol start="2">
<li><strong>Access Sysdb via REST API</strong>: Once TerminAttr is running, use the REST API to explore Sysdb. Start by checking available paths:</li>
</ol>
<pre><code class="language-bash">bash-4.2# curl localhost:6060/rest/Sysdb
{
    &quot;config&quot;: {
        &quot;_ptr&quot;: &quot;/Sysdb/sys/net/config&quot;
    }
}
</code></pre>
<p>This command will return a JSON structure with various Sysdb paths, each having a <code>_ptr</code> reference.</p>
<ol start="3">
<li><strong>Browse Sysdb Paths</strong>: Use the REST API to navigate through the Sysdb paths. For example, to access network configuration data, you might use:</li>
</ol>
<pre><code class="language-bash">bash-4.2# curl localhost:6060/rest/Sysdb/sys/net/config
{
    &quot;dnsCacheCountersUpdateInterval&quot;: 3,
    &quot;dnsCacheSize&quot;: 4096,
    &quot;domainList&quot;: {},
    &quot;domainListMetadata&quot;: {
        &quot;head&quot;: 0,
        &quot;tail&quot;: 0
    },
    &quot;domainName&quot;: &quot;&quot;,
    &quot;dscpValue&quot;: 0,
    &quot;externalDnsProxy&quot;: false,
    &quot;hostAddr&quot;: {},
    &quot;hostname&quot;: &quot;n1&quot;,
    &quot;hostnameTimeout&quot;: 20,
    &quot;name&quot;: &quot;config&quot;,
    &quot;nameServer&quot;: {
        &quot;1.1.1.1_default&quot;: {
            &quot;priority&quot;: 0,
            &quot;vrfIpPair&quot;: {
                &quot;ip&quot;: &quot;1.1.1.1&quot;,
                &quot;vrfName&quot;: {
                    &quot;value&quot;: &quot;default&quot;
                }
            }
        }
    },
    &quot;sourceIntf&quot;: {},
    &quot;v6NameServer&quot;: {}
}
</code></pre>
<p>You will receive a JSON response with the relevant Sysdb data.</p>
<h3>Streaming Sysdb Data Over gNMI</h3>
<p>After identifying the desired Sysdb paths using TerminAttr and the REST API, you can proceed to stream this data over gNMI. For non-openconfig paths, use the <code>eos_native</code> prefix and enable it on the device.</p>
<pre><code class="language-cisco">management api gnmi
   transport grpc default
       no shutdown
   provider eos-native
</code></pre>
<p>If we try to get the hostname directly, we get an empty response:</p>
<pre><code class="language-bash">bash-4.2# gnmic -a 0.0.0.0:6030 -u admin -p admin --insecure --gzip get --path &quot;eos_native:/Sysdb/sys/net/config/hostname&quot;
[]
</code></pre>
<p>This is because when pulling from Sysdb via gNMI, we need to use the closest <code>_ptr</code> reference, as only entire objects can be pulled. In this case, we can use the last <code>_ptr</code> we saw in the REST API output:</p>
<pre><code class="language-bash">bash-4.2# gnmic -a 0.0.0.0:6030 -u admin -p admin --insecure --gzip get --path &quot;eos_native:/Sysdb/sys/net/config&quot; --format flat
dnsCacheCountersUpdateInterval: {}
eos_native:Sysdb/sys/net/config/dnsCacheSize: 4096
eos_native:Sysdb/sys/net/config/domainListMetadata/head: 0
eos_native:Sysdb/sys/net/config/domainListMetadata/tail: 0
eos_native:Sysdb/sys/net/config/domainName:
eos_native:Sysdb/sys/net/config/dscpValue: 0
eos_native:Sysdb/sys/net/config/externalDnsProxy: false
eos_native:Sysdb/sys/net/config/hostname: spine1
eos_native:Sysdb/sys/net/config/name: config
hostnameTimeout: {}
</code></pre>
]]></description>
      <pubDate>Sat, 20 Jan 2024 00:00:00 +0800</pubDate>
    </item>
    <item>
      <title>Github Actions and Kubernetes</title>
      <guid>https://hayl.in/posts/github-actions-k8s</guid>
      <link>https://hayl.in/posts/github-actions-k8s</link>
      <description><![CDATA[<p>Recently, I migrated my site to being built and deployed using GitHub Actions, this approach is useful if you're experiencing slow docker cross-compilation speeds, like those on M1 Macs. Typically my local flow for building new images involves a Makefile that builds the Docker image, pushes it to a registry, and then issues the <code>kubectl rollout restart deployment DEPLOYMENT_NAME</code> command. There are already ample resources on how to build and push a Docker image using Github Actions (<a href="https://github.com/marketplace/actions/build-and-push-docker-images">here</a>, <a href="https://docs.github.com/en/actions/creating-actions/creating-a-docker-container-action">here</a>, and <a href="https://docs.docker.com/build/ci/github-actions/">here</a>), so I won't cover that here, but I will cover how to restart a deployment or trigger a kubernetes command using Github Actions.</p>
<p>To replicate <code>rollout restart</code> part of the deploy flow, the first step is understanding Kubernetes Service Accounts. Here's an example of a service account setup that allows GitHub Actions to restart a deployment:</p>
<pre><code class="language-yaml">apiVersion: v1
kind: ServiceAccount
metadata:
  name: github-actions-deployer
  namespace: default
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: deployment-restart-role
rules:
  - apiGroups: [&quot;apps&quot;]
    resources: [&quot;deployments&quot;]
    verbs: [&quot;get&quot;, &quot;patch&quot;]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: deployment-restart-binding
subjects:
  - kind: ServiceAccount
    name: github-actions-deployer
    namespace: default
roleRef:
  kind: ClusterRole
  name: deployment-restart-role
  apiGroup: rbac.authorization.k8s.io
</code></pre>
<p>These configurations comprise three parts:</p>
<ol>
<li>The service account itself, identified by a name and a namespace.</li>
<li>A ClusterRole, allowing the service account to get and patch deployments.
<ol>
<li>One could optionally use a Role to limit the scope of the services account to specific deployments.</li>
</ol>
</li>
<li>A ClusterRoleBinding, binding the service account to the ClusterRole.
Next, generate a token for the service account using:</li>
</ol>
<pre><code class="language-bash">kubectl create token github-actions-deployer --duration=262800h
</code></pre>
<p>With the token, create a kubeconfig file. A typical configuration looks like this:</p>
<pre><code class="language-yaml">apiVersion: v1
clusters:
  - cluster:
      certificate-authority-data: CA_DATA
      server: https://K8SENDPOINT:6443
    name: default
contexts:
  - context:
      cluster: default
      user: default
    name: default
current-context: default
kind: Config
preferences: {}
users:
  - name: default
    user:
      token: TOKEN
</code></pre>
<p>Test the configuration locally with:</p>
<pre><code class="language-bash">kubectl --kubeconfig=kubeconfig.yaml get deployment/DEPLOYMENT_NAME
</code></pre>
<p>Once verified, set up the Github Action by adding the following to your workflow after the image build step:</p>
<pre><code class="language-yaml">- uses: actions-hub/kubectl@master
env:
    KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
with:
    args: rollout restart deployment DEPLOYMENT_NAME
</code></pre>
<p>Finally, base64 encode the kubeconfig and store it in the Github Actions secrets as<code>KUBE_CONFIG</code> in the repository settings. This will allow the Github Action to authenticate with the Kubernetes cluster and restart the deployment.</p>
<p>Looking at the full workflow file, it should look something like this:</p>
<pre><code class="language-yaml">name: Docker Build and Push
on:
  push:
    branches:
      - main
    tags:
      - &quot;v*&quot;
env:
  REGISTRY: REGISTRY_URL
  IMAGE_NAME: IMAGE_NAME

jobs:
  build-and-push:
    runs-on: ubuntu-latest

    steps:
      - name: Check out the repo
        uses: actions/checkout@v3

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2

      - name: Login to the Docker registry
        uses: docker/login-action@v2
        with:
          registry: ${{ env.REGISTRY }}
          username: ${{ secrets.REGISTRY_USERNAME }}
          password: ${{ secrets.REGISTRY_PASSWORD }}
      - name: Build and push
        uses: docker/build-push-action@v5
        with:
          context: .
          push: true
          tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
          cache-from: type=gha
          cache-to: type=gha,mode=max
      - uses: actions-hub/kubectl@master
        env:
          KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
        with:
          args: rollout restart deployment DEPLOYMENT_NAME
</code></pre>
<p>This workflow will build and push the Docker image, then restart the deployment. This is a simple example, but it can be expanded to do more complex tasks, such as deploying to multiple clusters or running tests on the deployment.</p>
<h2>Hitless Deployments</h2>
<p>One of the most useful features of Kubernetes is the ability to do hitless deployments. This means that when a new version of a deployment is deployed, the old version is not taken down until the new version is ready. This is done by having multiple replicas of the deployment running at once. This allows for a new version to be deployed, and then the old version to be taken down once the new version is ready.</p>
<p>To do this, a deployment configuation similar to the following can be used:</p>
<pre><code class="language-yaml">apiVersion: apps/v1
kind: Deployment
metadata:
  name: APP_NAME
spec:
  selector:
    matchLabels:
      app: APP_NAME
  replicas: 2
  minReadySeconds: 1
  template:
    metadata:
      labels:
        app: APP_NAME
    spec:
      containers:
        - name: APP_NAME
          image: IMAGE_URL
          imagePullPolicy: Always
          ports:
            - containerPort: 3000
          livenessProbe:
            httpGet:
              path: /health
              port: 3000
</code></pre>
<p>This will create a deployment with two replicas. This means that when a new version is deployed, the old version will not be taken down until the new version is ready. Using the livenessProbe, Kubernetes will know when the new version is ready, and then take down the old version.</p>
]]></description>
      <pubDate>Tue, 16 Jan 2024 00:00:00 +0800</pubDate>
    </item>
    <item>
      <title>PunyTLD</title>
      <guid>https://hayl.in/posts//assets/pdfs/punytld.pdf</guid>
      <link>https://hayl.in/posts//assets/pdfs/punytld.pdf</link>
      <description><![CDATA[]]></description>
      <pubDate>Tue, 23 Mar 2021 00:00:00 +0800</pubDate>
    </item>
    <item>
      <title>Invalid UTF8 characters as SSIDs</title>
      <guid>https://hayl.in/posts/weird-wifi-names-cont</guid>
      <link>https://hayl.in/posts/weird-wifi-names-cont</link>
      <description><![CDATA[<p>This is a continuation of my previous post <a href="/posts/weird-wifi-name-display/">Comparing how different devices display the SSID &quot;á̶̛̛̓̿̈͐͆̐̇̒̑̈́͘͝aaa&quot;</a>. After posting it on HackerNews I got lots of feedback. The key one was something that I had sadly missed when I originally started this project. When the WiFi name of &quot;á̶̛̛̓̿̈͐͆̐̇̒̑̈́͘͝aaa&quot; got shortened down to a one byte before the second &quot;a&quot; due to the 32 byte/octet limit of SSIDs. The issue was this character is actually two bytes wide, so the first part of the character stayed, with the second byte of it missing. The character in question was ◌̈́, with the hex codepoint cd84. Looking at the raw hex of the SSID you can see it ends in cd, <code>61ccb6cc81cc93ccbfcc88cc9bcc9bcd90cd98cd86cc90cd9dcc87cc92cc91cd</code>. For those curious about how that would be rendered on your device here it is &quot;á̶̛̛̓̿̈͐͆̐̇̒̑͘͝�&quot;. After realizing this I decided my previous comparisons of how devices reacted to my weird unicode SSID was unfair. The SSID this time is &quot;á̶̛̛̓̿̈͐͆̐̇̒̑͘͝a&quot; which is almost the exact same but that last two byte long character was replaced with an &quot;a&quot;. This was to keep the SSID at 32 octets long.
Looking at the new hex of the SSID <code>61ccb6cc81cc93ccbfcc88cc9bcc9bcd90cd98cd86cc90cd9dcc87cc92cc9161</code> you can see that is is identical baring the <code>61</code> instead of a <code>cd</code> at the end.</p>
<p>Below are the previous photos of the previous SSID &quot;á̶̛̛̓̿̈͐͆̐̇̒̑͘͝�&quot; with the new SSID &quot;á̶̛̛̓̿̈͐͆̐̇̒̑͘͝a&quot; under it. They are also grouped the same as previously to keep continuity.</p>
<p>Galaxy S8 running Android 9 with Kernel 4.4.153
<img src="/assets/img/iosWifiBug/android.jpg" alt="" />
<img src="/assets/img/iosWifiBug/d2/android.jpg" alt="" /></p>
<p>Amazon Firestick
<img src="/assets/img/iosWifiBug/firestick.jpg" alt="" />
<img src="/assets/img/iosWifiBug/d2/firestick.jpg" alt="" /></p>
<p>As before the Galaxy S8 and the Firestick both handled it perfectly with there being no issues with how it rendered besides vertical cutoff which makes sense.</p>
<p>iPhone running iOS 13.5.1
<img src="/assets/img/iosWifiBug/iphone-ios1351.jpg" alt="" />
<img src="/assets/img/iosWifiBug/d2/iphone-ios1351.jpg" alt="" /></p>
<p>Apple TV Second Generation
<img src="/assets/img/iosWifiBug/appletvgen2.jpg" alt="" />
<img src="/assets/img/iosWifiBug/d2/appletvgen2.jpg" alt="" /></p>
<p>These results were interesting. It showed that if the UTF-8 character in an SSID is invalid then IOS falls back to the <a href="https://en.wikipedia.org/wiki/Mac_OS_Roman">Mac OS Roman</a> character set, but since the new SSID is valid UTF-8 iOS properly renderers the SSID.</p>
<p>2012 Macbook running High Sierra 10.13.6
<img src="/assets/img/iosWifiBug/d2/macos.jpg" alt="" /></p>
<p>Unlike last time the Macbook actually showed the network. I believe last time instead of falling back to Mac OS Roman like iOS the Macbook just treated the SSID as spam or noise and dropped it</p>
<p>Windows 10 Pro 10.0.19041
<img src="/assets/img/iosWifiBug/windows10.png" alt="" />
<img src="/assets/img/iosWifiBug/d2/windows10.jpg" alt="" /></p>
<p>Windows was able to properly handle this SSID as opposed to falling back to <a href="https://en.wikipedia.org/wiki/Windows-1252">Windows-1252</a> like it did previously.</p>
<p>Chromebook running ChromeOS 83.0.4103.97
<img src="/assets/img/iosWifiBug/chromeos.jpg" alt="" />
<img src="/assets/img/iosWifiBug/d2/chromeos.jpg" alt="" /></p>
<p>Unlike last time the Chromebook was able to render this perfectly with no question marks.</p>
<p>Kindle Paperwhite running Firmware 5.10.2
<img src="/assets/img/iosWifiBug/kindlepaperwhite.jpg" alt="" />
<img src="/assets/img/iosWifiBug/d2/kindlepaperwhite.jpg?" alt="" /></p>
<p>Vizio M55-C2 TV
<img src="/assets/img/iosWifiBug/viziom55-c2.jpg" alt="" />
<img src="/assets/img/iosWifiBug/d2/viziom55-c2.jpg" alt="" /></p>
<p>Unlike last time the kindle was able to show the SSID without escape any of the characters.
Sadly the Vizio was not able to show the SSID and just fell back to escaped hex.</p>
<p>The results from changing the SSID showed a couple things, namely devices really do not like it when they are given invalid or incomplete UTF-8 codes and lots of devices handle UTF-8 text much better than I thought they would.
It also showed that some devices fallback to their native 8 bit encoding formats when they see an invalid UTF-8 codepoint, there is probably some room for exploitation here like inserting escape keys.
I originally was not expecting the kindle to work at all, nor the chromebook after seeing the slew of question marks originally. Android was also found to be at handling text with invalid UTF-8 characters it just removed them as opposed to switching up formatting, falling back to hex, or erroring out with all question marks.</p>
<p>Thank you to everyone who provided valuable feedback on the previous post. I have more research I plan ond doing with this in the future.</p>
<p>Lastly if anyone would like to run this test themselves and send me the comparison results to be added my email is <code>me (at) haylinmoore (This key &gt; not shifted) com</code>.</p>]]></description>
      <pubDate>Fri, 3 Jul 2020 00:00:00 +0800</pubDate>
    </item>
    <item>
      <title>The SSID "á̶̛̛̓̿̈͐͆̐̇̒̑̈́͘͝aaa"</title>
      <guid>https://hayl.in/posts/weird-wifi-name-display</guid>
      <link>https://hayl.in/posts/weird-wifi-name-display</link>
      <description><![CDATA[<p>After my recent post <a href="/posts/fios-home-router-emoji">Setting the SSID of a Fios Home Router to an emoji</a> I decided to set my WiFis SSID to &quot;á̶̛̛̓̿̈͐͆̐̇̒̑̈́͘͝aaa&quot;.
That name is <a href="https://mothereff.in/byte-counter#a%CC%B6%CC%81%CC%93%CC%BF%CC%88%CC%9B%CC%9B%CD%90%CD%98%CD%86%CC%90%CD%9D%CC%87%CC%92%CC%91%CD%84aaa">36 octets</a> making it over the 32 octets maximum specified in the 2012 standard of 802.11 Section 6.3.11.2.2.
My router just cut the name down to 32 octets though to stay compliant.</p>
<p>I decided to see how this showed up on different devices and got some pretty strange results. Below are the devices tested sorted roughly to how they acted.</p>
<p>Galaxy S8 running Android 9 with Kernel 4.4.153
<img src="/assets/img/iosWifiBug/android.jpg" alt="" /></p>
<p>Amazon Firestick
<img src="/assets/img/iosWifiBug/firestick.jpg" alt="" /></p>
<p>Both the s8 and the Firestick are rendering the result in what I deem as the correct way with it showing the name just with some of the vertical characters cutoff.</p>
<p>iPhone running iOS 13.5.1
<img src="/assets/img/iosWifiBug/iphone-ios1351.jpg" alt="" /></p>
<p>Apple TV Second Generation
<img src="/assets/img/iosWifiBug/appletvgen2.jpg" alt="" /></p>
<p>Next comes the iPhone and Apple TV. At first I had no idea what they were rending these characters as. At first I thought it was just extended ascii but that third character, ∂, was not in extended ASCII. After asking around on the Apple discord server someone said it might be using the <a href="https://en.wikipedia.org/wiki/Mac_OS_Roman">Mac OS Roman</a> character set. It turns out it which is strange because iOS used UTF-8 internally and not Mac OS Roman as that was phased out with the release of Mac OS X.</p>
<p>Speaking of Apple devices, there will not be any photos of MacOS though not from a lack of trying.
I could not get either of my Macbook to acknowledge that this WiFi network existed.
Neither the Wifi dropdown nor the airport command-line utility would show it.</p>
<p>Windows 10 Pro 10.0.19041
<img src="/assets/img/iosWifiBug/windows10.png" alt="" /></p>
<p>~~Windows 10 is rendering it using what I believe to be the UTF-8 characters of each octet. This matches what the raw hex of the wifi name would become if you split it up into 8bit bytes and used that as UTF-8 chars.~~
It was pointed out by <a href="https://twitter.com/theFerdi265">@theFerdi265</a> that this is not the first set of UTF-8 chars like I thought. Instead it is <a href="https://en.wikipedia.org/wiki/Windows-1252">Windows-1252</a>, a single-byte character encoding of the Latin alphabet, used by default in the legacy components of Microsoft Windows for English and some other European languages.</p>
<p>Chromebook running ChromeOS 83.0.4103.97
<img src="/assets/img/iosWifiBug/chromeos.jpg" alt="" /></p>
<p>ChromeOS is just freaking out not knowing how to render any of the characters besides the singular a.</p>
<p>Kindle Paperwhite running Firmware 5.10.2
<img src="/assets/img/iosWifiBug/kindlepaperwhite.jpg" alt="" /></p>
<p>Vizio M55-C2 TV
<img src="/assets/img/iosWifiBug/viziom55-c2.jpg" alt="" /></p>
<p>Both the Kindle and Vizio TV are showing what <code>iw</code> returned with the <code>a</code> and then escaped hexademical characters.</p>
<p>I have now published a follow up to this post, <a href="/posts/weird-wifi-names-cont/">here</a>.</p>
<p>Discuss this post on Hacker News <a href="https://news.ycombinator.com/item?id=23708056">here</a></p>]]></description>
      <pubDate>Wed, 1 Jul 2020 00:00:00 +0800</pubDate>
    </item>
    <item>
      <title>FIOS Home Router Emoji</title>
      <guid>https://hayl.in/posts/fios-home-router-emoji</guid>
      <link>https://hayl.in/posts/fios-home-router-emoji</link>
      <description><![CDATA[<p>Setting the name/SSID of your WiFi to an emoji is fairly simple for the Fios Home Router.
Simply log into the router, and go the page for setting the SSID.</p>
<p>Once you are there open the developer console using <code>Ctrl+Shift+I</code> or by right clicking and clicking  the option labeled along the lines of <code>Inspect Element</code> or <code>Inspect</code>.
After this simply paste the following code into the console.</p>
<pre><code class="language-javascript">validSSID = function(){return true}
</code></pre>
<p>This overrides the current validSSID function which is used to make sure that your SSID is made of the Fios required 1-32 alphanumerical ascii characters.
This is not an actual technical requirements for SSIDs with the 2012 standard of 802.11 (Section 6.3.11.2.2) stating SSIDs simply have to be a max of 32 bytes.
Once this script is ran you should be able to type anything less than 32 bytes.
This tends to be at most 32 characters, but depending on the size of the Unicode characters used it can be much less.
For instance the fire emoji, <code>🔥</code>, is actually 4 bytes because of how UTF-8 works.
This means that only 8 fire emojis could be used.
To get the size of a string simply use the site <a href="https://mothereff.in/byte-counter">https://mothereff.in/byte-counter</a>.</p>
<p>Have fun setting unusal SSIDs</p>]]></description>
      <pubDate>Wed, 24 Jun 2020 00:00:00 +0800</pubDate>
    </item>
    <item>
      <title>Shrinking this site's docker image</title>
      <guid>https://hayl.in/posts/shrinking-docker-images</guid>
      <link>https://hayl.in/posts/shrinking-docker-images</link>
      <description><![CDATA[<p>Recently, I moved my static <a href="https://www.11ty.dev/">Eleventy</a> site over to a docker container. This was one of the first docker images I have made in a while so it started inefficient.</p>
<pre><code>FROM nginx:1.17.10-alpine
RUN apk add --update nodejs npm
RUN npm install -g @11ty/eleventy
COPY . /app
WORKDIR /app
RUN npm install
RUN eleventy .
RUN rm -r /usr/share/nginx/html/
RUN cp /app/_site/ /usr/share/nginx/html/ -r
EXPOSE 80
</code></pre>
<p>This docker image resulted in a 419MB final image and took about 3 minutes to build. There are some obvious issues with this. For instance every-time I change any file it must go through and reinstall all of my node_modules. Secondly, I was installing Eleventy globally while at the same time installing it during the second npm install.</p>
<pre><code>FROM nginx:1.17.10-alpine as npmpackages
RUN apk add --update nodejs npm
WORKDIR /app
COPY package.json .
RUN npm install

FROM nginx:1.17.10-alpine
RUN apk add --update nodejs npm
WORKDIR /app
COPY --from=npmpackages /app /app
COPY . .
RUN npm run build
RUN rm -r /usr/share/nginx/html/
RUN cp /app/_site/ /usr/share/nginx/html/ -r
EXPOSE 80
</code></pre>
<p>This build was segmented into two portions, at first it just copied the package.json and ran npm install. This means that assuming that the package.json file did not change at all then after the first docker build it would cache the node_modules so that it did not have to npm install on each build. This shrunk the docker image down to 329MB, which was a little better, but still heavily bloated. After poking around in the docker image I saw the issue, I was keeping the /app folder even though it was not being used after the _site folder was copied to the nginx serve directory.</p>
<pre><code>FROM nginx:1.17.10-alpine as npmpackages
RUN apk add --update nodejs npm
WORKDIR /app
COPY package.json .
RUN npm install

FROM nginx:1.17.10-alpine as builder
RUN apk add --update nodejs npm
WORKDIR /app
COPY --from=npmpackages /app /app
COPY . .
RUN npm run build
RUN rm -r /usr/share/nginx/html/
RUN cp /app/_site/ /usr/share/nginx/html/ -r

FROM nginx:1.17.10-alpine
COPY --from=builder /app/_site/ /usr/share/nginx/html/
EXPOSE 80
</code></pre>
<p>This is the final image that I ended up with, note how the final layer does not install NPM or NodeJS. This is to save space as at that point the <code>builder</code> and <code>npmpackage</code> layers have already done everything related to NodeJS. This image only took up 69.1MB which is pretty good considering the compiled version of my site is over 50MB due to various images. The next step in shrinking my site's docker image will be compressing the images down, but that is unrelated to the docker image itself.</p>
<pre><code>FROM node:10-alpine3.9 as npmpackages
WORKDIR /app
COPY package.json .
RUN npm install

FROM node:10-alpine3.9 as builder
WORKDIR /app
COPY --from=npmpackages /app /app
COPY . .
RUN npm run build

FROM nginx:1.17.10-alpine
RUN rm -r /usr/share/nginx/html/
COPY --from=builder /app/_site/ /usr/share/nginx/html/

EXPOSE 80
</code></pre>
<p>EDIT: After compression of all of the images and WaifuCraft resource pack the whole site is 19MB with the image being 39MB</p>
<p>EDIT #2: After posting this on Hacker News I got quite a few suggestions, the main one being that since I am using build layers I should be using the node docker image instead of a modified nginx-alpine. I have taken that suggestion with the new Dockerfile looking this this.</p>
<p>EDIT #3: The Waifucraft images and resources have been moved to an external CDN, with the final image now being 20MB, with 5.6MB coming from alpine, 14.3MB coming from nginx, and a whole 40KB coming from my site itself. Future plans include swapping out nginx without something less bloated like <a href="https://tools.suckless.org/quark/">Quark by Suckless</a>.</p>
<p>EDIT #4: This site has been moved to Jekyll. The new Dockerfile looks like this. Notice how like the Eleventy Dockerfile it copies the dependency listings, gemfile and gemspec, installs the dependancies, then copies the rest of the site's source code.</p>
<pre><code>FROM jekyll/jekyll as jekyll
LABEL stage=jekyll
WORKDIR /home/jekyll
COPY Gemfile* ./
COPY the-plain.gemspec .
RUN bundle install
COPY . .
RUN jekyll b


FROM nginx:alpine
COPY --from=jekyll /home/jekyll/_site /usr/share/nginx/html
EXPOSE 80
</code></pre>
]]></description>
      <pubDate>Sun, 3 May 2020 00:00:00 +0800</pubDate>
    </item>
    <item>
      <title>AI Recolors New Mexico State Flag</title>
      <guid>https://hayl.in/posts/new-mexico</guid>
      <link>https://hayl.in/posts/new-mexico</link>
      <description><![CDATA[<p>I'm bad at design, but good at programming. Which means I am very good at design. If your first response to that was &quot;That makes no sense, you just said you are bad&quot; then you are kinda correct. I really liked the results of this, but that is likely due to my personal bias.</p>
<h3>Backstory</h3>
<p>I was looking at state flags one day and came to the realization that the New Mexico flag one of the only good looking flags. I only had one issue with it, the coloring. I don’t know what about it I did not like, but I just knew I did not particularly like the color scheme. After a bit of time, I had an idea. Since I don’t know what I like, why not have a computer do it for me.</p>
<h3>How?</h3>
<p>It is super simple. First, it generates 2 random colors, then renders it onto the user's screen. Then the user has four choices, Love it, Like it, Meh, and Hate it. It then feeds the Neural Network a value, 1 for Love it all the way to 0 for Hate it. It uses this in the future to find the perfect color scheme. The user then continues to do this for as long as they wish. Once they think it has been long enough it gets tired, then click the dandy “Generate” button. That runs 200 thousand rounds of generating random colors, sending it to the trained and personalized neural network, and save it to an array. After all the simulations finish, it then finds the color scheme with the higher score and displays it to the user.</p>
<p><svg xmlns="http://www.w3.org/2000/svg" width="400" height="300" xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 0 1200 800" style="max-width: 100%;">
<rect class="nm_flag" fill="#fff700" width="1200" height="800" />
<g transform="translate(600,400)" stroke="#bf0a30" class="nm_star">
<path id="lin"
d="M157.344,38.2812H-157.344M191.375,12.75H-191.375M191.375-12.75H-191.375M157.344-38.2812H-157.344"
stroke-width="17" stroke-linecap="round" />
<use transform="rotate(90)" xlink:href="#lin" />
<circle class="nm_flag" fill="#ffd700" r="64.3125" stroke-width="10.625" />
</g>
</svg>
<br>
<button onclick="rank(1)">Love It</button>
<button onclick="rank(0.4)">Like it</button>
<button onclick="rank(0.1)">Meh</button>
<button onclick="rank(0)">Hate It</button>
<button onclick="bestFlag(100000)">Generate Good Looking</button></p>
<h3 id="data"></h3>
<p>Just click your thought on the image, the more you click the better it looks!</p>
<script src='https://unpkg.com/brain.js@1.1.2/browser.min.js'></script>
<script>
    var net = new brain.NeuralNetwork();

    var data = [{
        input: [0, 0, 0, 0, 0, 0],
        output: [0]
    }, {
        input: [1, 1, 1, 1, 1, 1],
        output: [0]
    }];

    net.train(data);

    var times = 0;

    const getRandomColorValue = (maxVal) => {
        return Math.floor(Math.random() * maxVal);
    };

    function rank(value) {

        times++;

        data.push({
            input: colors,
            output: [value]
        });

        if (times === 1) {
            net.train(data);
        }

        colors = [getRandomColorValue(255) / 255, getRandomColorValue(255) / 255, getRandomColorValue(255) / 255, getRandomColorValue(255) / 255, getRandomColorValue(255) / 255, getRandomColorValue(255) / 255];

        setStarColor([colors[0], colors[1], colors[2]]);

        setFlagColor([colors[3], colors[4], colors[5]]);

        updateUser(net.run(colors));

    }

    function setStarColor(color) {
        document.getElementsByClassName("nm_star")[0].style.stroke = `rgb(${color[0]*255},${color[1]*255},${color[2]*255})`;
    }

    function updateUser(data) {
        document.getElementById("data").innerHTML = "Chance You May Like it " + (data[0] * 100).toFixed(1) + "%";
    }

    function setFlagColor(color) {
        document.getElementsByClassName("nm_flag")[0].style.fill = `rgb(${color[0]*255},${color[1]*255},${color[2]*255})`;
        document.getElementsByClassName("nm_flag")[1].style.fill = `rgb(${color[0]*255},${color[1]*255},${color[2]*255})`;
    }

    var colors = [0.74901960784, 0.03921568627, 0.18823529412, 1, 0.8431372549, 0];

    setStarColor([colors[0], colors[1], colors[2]]);

    setFlagColor([colors[3], colors[4], colors[5]]);

    updateUser(net.run(colors));


    function bestFlag(loops) {
        net.train(data);
        var results = [];
        for (let i = 0; i < loops; i++) {
            colors = [getRandomColorValue(255) / 255, getRandomColorValue(255) / 255, getRandomColorValue(255) / 255,
                getRandomColorValue(255) / 255, getRandomColorValue(255) / 255, getRandomColorValue(255) / 255
            ];
            const [score] = net.run(colors);
            results.push({
                ...colors,
                score
            });
        }

        const sortedResults = results.sort((a, b) => b.score - a.score);



        colors = sortedResults[0];

        delete colors.score;

        colors = [sortedResults[0][0], sortedResults[0][1], sortedResults[0][2], sortedResults[0][3], sortedResults[0][4], sortedResults[0][5]];

        setStarColor([colors[0], colors[1], colors[2]]);

        setFlagColor([colors[3], colors[4], colors[5]]);

        updateUser(net.run(colors));

    }
</script>]]></description>
      <pubDate>Thu, 18 Oct 2018 00:00:00 +0800</pubDate>
    </item>
  </channel>
</rss>