Friday, 24 April 2026

Troubleshooting WSL2 Memory Hogging

WSL2 hogs memory and doesn't release it even when all consoles are closed. Do wsl --shutdown to free up memory.

Why does TypeScript feel a bit C-Sharpy?

TypeScript was created by Anders Hejlsberg, a Danish software engineer, in 2012. He formerly created C# around the year 2000. He is also known for Turbo Pascal and Delphi, both extraordinary products in their time. Deservedly he is a Microsoft Technical Fellow (a list of whom appear here).

Types in TypeScript

The basic types are called primitives: 
  • boolean
  • number (which represents integers and floating points)
  • string  
There is also:
  •  BigInt (ES2020+) to represent whole numbers larger than 2^53 -1, and
  •  symbol to create unique identifiers
Starting with ES2015, symbol is a primitive type, whose values are created by calling the Symbol constructor.

Examples:

let sym1 = Symbol();
let sym2 = Symbol("keyname");

Symbols are immutable and unique, which can result in what may be initially feel like strange behaviour, but on reflection makes sense.

let sym2 = Symbol("key");
let sym3 = Symbol("key");

sym2 === sym3; // triple equality - false, Symbols are unique.

Node Version Manager - Strongly Recommended

The Node version manager, nvm, is strongly recommended to manage your version of Node.js and npm. 

It also allows switching between various versions of Node (Nodejs and npm) for testing purposes. 

As per official docs, nvm is designed to be installed per-user and invoked per-shell. It works on "any POSIX compliant shell" - including on Unix, macOS and WSL.

Once you install nvm (by wget'ing the installation shell script and piping it to bash) you can restart WSL and start using nvm.

Some nvm commands to know:

nvm install node   # install latest version

nvm install --lts     # install latest LTS version

nvm use node        # switches to latest version

nvm use <version>    #switch to a specific version

To see all Node versions, do nvm ls.   Node uses semantic versioning, following the pattern MAJOR.MINOR.PATCH.

nvm ls shows the version active in shell in blue, and installed versions in green. Yellow are versions referenced by aliases but not installed.

Installing a Transpiler

Do install a transpiler in WSL as follows.

sudo npm install -g typescript

The -g option to npm install is short for --global and means install the said package globally (global npm directory) as opposed to the local node_modules folder of a project.

Binaries are then also exposed on your PATH, so you can run tsc conveniently.

Note that you need an up-to-date installation of Node to run TypeScript. If not, some of the modern operators (e.g. null coalescing operator) will not work when running tsc.

Dawn of the Transpiler

The term "transpiler" (referring to a source-to-source translation tool, or "translating compiler") gained popularity around 2013 with the proliferation of translators from TypeScript and other abstractions (CoffeeScript, Dart) into JavaScript.  

JavaScript at the time was becoming a "universal runtime".

Babel is a popular transpiler. tsc is the official transpiler. It can be installed via npm.

Thursday, 23 April 2026

Downsampling from a Data Science Perspective

Downsampling in data science and data processing is as follows (this excludes the DSP, or digital signal processing, technical definition of downsampling - which is similar in spirit but differently defined).

Downsampling involves reducing the number of data points in a data set to enable comparability (sometimes referred to as "balancing the data").  This helps machine learning models avoid bias towards a dominant class.

Various approaches to downsampling (e.g. random downsampling) are described in this IBM article.