Scaffolding jekyll posts with little bit of bash


Jekyll blogs are quite awesome. Really simple to set-up, relatively straightforward to customize, and generally a pleasure to work with. Their only downside I’ve noticed is a slightly annoying new-post story. You need to create a file at a specific location, correctly lower-case and sanitize its name - that should correspond to the title, and fill the date - twice.

Luckily, we can spend hours perfecting automation of this menial task and save a negative amount of time even assuming we’ll continue blogging at a reasonable pace.

A quick google revealed at least two existing scaffolding projects for jekyll posts but one didn’t fit my needs - as it only works with normal posts, and another required jeoman and was generally larger in scope.

For those reasons, I decided to write my own little bash script. In its current form it is capable of scaffolding new posts and new items of my special TIL items (a normal Jekyll collection with specific attributes and format). It could, however, be very easily customized to handle any type of jekyll content. Apart from just creating new files, it automatically handles all the dates, sanitizing title and using it as the file-name, and supports custom templating in case your content is more specialized.

It’s built on top of two principles:

  • The first argument specifies command. The command determines what hand...
Read More

Asserts with custom messages in Burst Unity


While helping with little something that uses Unity I came across another interesting thing. If you try to use normal UnityEngine.Assertions.* in your Burst jobs you’ll find out they’re (as of Burst 1.3.3 and Unity 2020.1.0b9) being silently optimized away and are not checked, not even in debug Builds.

A quick google search for unity burst assert will yield you this amazing blog-post about making your own asserts that work well with Burst. I encourage everyone to read it. Unfortunately, there’s one small deficiency with the code suggested, it doesn’t allow custom assertion-failed messages.

No log message:

using System;
using UnityEngine;
using Unity.Collections;

static class BurstAssert
    // based on:
    public static void IsTrue(bool condition)
        if (!condition)
            throw new Exception("Assertion failed");

What doesn’t work:

While it is possible to instantiate and throw an Exception with a custom message directly from a burst’ed method (see the "Assertion failed" message), you can’t pass a managed string to a method, even if it is onl...

Read More

Async in C#, .NET, and Unity: Allocation and state machine builders


While helping with little something that uses Unity I came across the rabbit hole async/await support is in Unity. Historically Unity used generators (known as coroutines in Unity’s world) to support async/multiple-frames-spanning computation. In 2017 they added initial support for async/await but without any meaningful libraries support and with potential performance pitfalls (hello GC, how are you?). To be fair, at that time async had performance implications even in mainland .NET (Core), mainly around allocations which - (un)fortunately aren’t anywhere as problematic for (mostly) throughput oriented .NET Core apps as they can be for near-real-time applications like Unity games.

Luckily for .NET, with the release of .NET Core 2.1 in 2018 a lot of those issues got solved and allocations were decreased substantially. But what was the change actually about? And how does it relate to Unity and/or 3rd party Unity focused async/await libraries such as UniTask or UnityAsync? Let’s find out.

I’ll assume some (relatively deep) knowledge about async/await. If you’re not sure you have it, be sure to check this awesome blog-post about the topic.

State machine rewrite:

When you write an async method, Roslyn will rewrite it to a method that does following. As this rewrite is done by the compiler it will happen regardless of your runtime, be it full framework, .NET Core 2.1, or Unity.

  1. Compiler synthesizes an IAsyncStateMachine struct containing the original implementation of the method cut into a state machine (as its MoveNext(..) method) and locals lifted as fields.
  2. Compiler generated IAsyncStateMachine struct is initialized (stateMachine) with:
    • This pointer.
    • Parameters.
    • Newly initialized XYZMethodBuilder (methodBuilder) struct corresponding to the Task-like object that ...
Read More

Managed personal VPN between your devices through Azure


Let’s say you have a few Windows devices, for example, a powerful desktop and laptop. You mostly work on the desktop but when being remote on the laptop you want to be able to remote to the desktop and harvest it’s power / avoid having to sync data.

Unfortunately, your ISP NATs you into oblivion and/or doesn’t provide static IP so RDP/SSH’ing directly is out of the question. Self-hosted Visual Studio Codespace works for most things but don’t cut it for everything. At the same time, you neither want to rent a VM and manage your own VPN (too much work) nor want to use off the shelf 3rd party product s.a. hamachi/TeamViewer/Parsec because you have this irrational detest towards 3rd party remoting software (I know, I know…1).

This brings you to a situation in which you’re looking for a managed VPN, ideally one payable with your free Azure credits. Luckily, it’s a situation that has a relatively easy solution.

  1. Follow this Point-to-Site VPN tutorial.
    • Basic SKU should be perfectly fine and will run you < ~30 USD/month.
  2. Distribute client certificates created in 1) to your devices, download VPN configuration.
  3. Connect on all desired devices to the VPN.
  4. Find the IP address of each device within the VPN.
    • Run ipconfig /all and find the assigned address within the correct Network interface on every device. Beware, the list might contain the true VPN network interface’s HyperV relay.
    • Run arp -a, identify the correct network device, and guess the association of IP addresses and devices.
    • Go to Azure Portal/<Your VPN_gateway>/User VPN Configuration/Allocated IP addresses and guess the association of IP addresses and devices.
  5. Use the IP address to SSH/RDP to your desired device.

For RDP two more things might be relevant.

  • By default the VPN’s network interface doesn’t have DNS configured and so connecting via Computer names won’t work. You’ll either have to configure DNS or just use IP addresses directly.
  • I was unable to login into a Windows 10 2004 that was configured as passwordless despite both computers using Microsoft account and Windows hello authentication. I believe it should be possible to make it work, as I know it can work in enterprise setting but just wasn’t worth it for me.

  1. I’m also fully aware that VSCode Codespace is essentially 3rd party remote software, somehow I’m fine with that ¯\(ツ)/¯. 

Read More

Gated linear networks


This post if from a series of notes written for personal usage while reading random ML/SWE/CS papers. The notes weren’t originally intended for the eyes of other people and therefore might be incomprehensible and/or flat out wrong.

Paper in question: 1910.01526

  • Series of linear filters (weights) on input with non-linearity at the end
    • Non-linearities are on each layer (neuron) but they cancel each other out
  • Set of weights per each neuron
    • Specific weight vector selected via context func. from input (side information)
    • Each neuron different set of weights, different context function
    • Same side information for all neurons in all layers
    • Weights adjusted during training, only the one weight vector for current input
  • Context function:
    • Usually set of half-space functions (similarity with side inf)
    • Don’t change during training, need to be sample correctly
    • Similar data will (through context func.) force same weights for neurons -> sim. outputs
    • Unsimilar data won’t use the same weights -> less forgetting
  • Each neuron is geometric mixture of outputs of previous layer (through weights)
    • Weights initialized randomly, updated via training
  • Essentially a multilevel mixture of KNN and linear transformation with point non-lin.
Read More