Today I learned

Hugo's Syntax Highlighting is static


Unlinke many other static site generators, the syntax highlighting of Hugo does not use client-side JavaScript, which is great!

The underlying library is available as Go module github.com/alecthomas/chroma.

Overriding internal Hugo templates


You can override internal Hugo templates with your own templates.

Simply create it in the layouts folder and you are done!

That’s how I overrode _internal/google_analytics_async.html with my own template - to not use GA! That way I could avoid forking athul’s archie template.

Templates for specific folders in Hugo


In Hugo you can simply create a folder within content/ and a template within layouts/_default/. It will be used for the index route of that folder - even if your template did not specify a layout.

This allowed me to create a separate template for all my learnings / til section!

Ultra-fast Hugo GitHub actions


I created a GitHub workflow to automatically build and deploy my website to GitHub Pages.

It uses peaceiris/actions-hugo@v2 to build the website with Hugo and peaceiris/actions-gh-pages@v3 to deploy it to GitHub Pages.

Angular *ngFor trackBy


When iterating over an array of objects in Angular, the change detection compares the references of the objects to detect changes.

If the object reference now change too, like when updating local data from the network, Angular will discard the identity of all nested components within the ngFor and re-render the entire list. Even if the objects deeply equal, the change detection will still detect the change.

To help our loop caching components and instead changing their inputs, we can add a trackBy function to the ngFor directive.

<div
  class="checkbox-row"
  *ngFor="let option of field.options; trackBy: fieldOptionTrackBy"
></div>

And in TypeScript, we add identity tracking function:

fieldOptionTrackBy(index: number, option: AssistantStepOption): string {
  return option.identifier;
}

Background: Angular did reset my mat-checkbox within the ngFor. That lead to a discard of the freshly changed values.

Go Data Race Detector


You can run your Go program or your tests with the Data Race detection enabled. This might cost some performance and memory, but in case a data race is being detected, that’s worth it!

Perfect for your CI!

go run --race ./cmd/app
go test --race ./...

Kubernetes Overview for Beginners


I have never done anything productive with Kubernetes before. But it is a really tough topic to get started with. It’s overwhelming.

Luckily I found an excellent Kubernetes tutorial on Youtube.

I made some personal notes while watching. Mostly to keep some overview for all the different concepts.

Today I haven’t finished the video, so the overview is only a rough draft. Some missing concepts are Storage Classes, Ingress Controllers and more!

Kubernetes Concepts

  • a Pod is an abstraction of usually one container.
  • all IP addresses are assigned and changed with every restart
  • Pods communicate using Services
  • External Services are accessible by IP and port
  • Ingress is used for external access using domains
  • A ConfigMap holds configuration data. Changing the config map prevents whole rebuilds and redeploys of specifc pods
  • Secrets are like ConfigMaps, but for sensitive data. Values are by default base64 encoded in the YAML.
  • Volumes connect storage (local or remote) to a Pod
  • Kubernetes does not handle storage!
  • LoadBalancers are a type of Services
  • Replicas are the amount of Deployments.
  • Deployments are blueprints for Pods

StatefulSets are like Deployments, but stateful.

  • They are designed to databases etc to avoid data inconsistency.
  • Harder to get right than a simple Deployment.
  • Databases are often deployed outside the cluster.

StatefulSet has volume claim templates, to create independent storage for each replica.

volumeClaimTemplates create a volume claim for each replica.

Kubernetes Architecture

Master nodes and worker nodes are kept separate to keep the cluster controllable. Imagine you couldn’t manage your cluster to increase the number of worker nodes or replicas.

Worker Nodes Runs multiple pods.

3 processes are running on each node:

  • container runtime
  • the Kubelet connects container runtime and the configuration
  • the kube proxy routes requests to services)

Master Nodes Manage the worker nodes.

Runs 4 processes:

  • Api Server / cluster gateway / authentication
  • the Scheduler that decides which worker node gets workload
  • Controller Manager observes the state of the cluster and makes changes
  • etcd is a Key-Value-Store for k8n

Iterating over a map in Go


Iterating over a map in Go is not predictable. This is a design decision to avoid relying on memory layout.

for k, v := range map {
    // always prints different results!
    fmt.Printf("%s: %s\n", k, v)
}

NSDataAsset reduces Code signing overhead


I had completely forgotten about NSDataAsset. Maybe I should move some of my JSON files into asset catalogs. According to @emergetools that should remove some code signing overhead from the app size.

Tweet by @simonbs

Attaching to UIScrollView's parent with Auto Layout


When using auto layout with a UIScrollView, subviews may not attach to the top edge of the scroll view’s parent. Else you cannot scroll, but the handle shrinks the more you scroll.

Setting left and right is ok to fix the width if you do not plan to scroll horizontally.