Monthly Shaarli

All links of one month in a single page.

January, 2025

20 lines of code that will beat A/B testing every time

Treat an A/B test as an multi-armed bandit problem. First we need to record the performance for each option. Then every time we are faced with a decision, calculate the reward for each option, pick the best one. Leave a small chance (e.g. 10%) for exploration where a random option is selected.

Useless superpower in solving "spot the difference" puzzles

Here's how I did it: with the example images on screen (~10cm wide), stare at it from around 25cm away. Cross your eyes until the images overlap. To cross your eyes you should keep the distance to the screen around the same but actively tries to move the focus. Do so until the image overlaps and merge. Now adjust the distance to the screen very slowly while keeping the focus so the merged image don't split, until the merged image become sharp. The merged image may never become as sharp as viewed directly, but that's enough for us. Now notice the spots where the image appears semi-transparent/flickering/bloty. You may not be able to tell in detail what the differences exactly are, but you should be able to tell the relative locations. Note that depending on the focusing, nearby spots may merge as one. Also I found the "hard mode" challenge easier than the "easy mode" in the sense that the difference stands out more clearly.

GitHub - s-macke/VoxelSpace: Terrain rendering algorithm in less than 20 lines of code

TIL VoxelSpace, a simple algorithm for rendering terrain map in high detail. The terrain is described by two identical sized textures: the height map and the color map. The color map is preshaded to contain shadows/other features. The rendering is performed from back to front at the viewer's perspective (painter's algorithm). For each depth, calculate a line corresponding to the given depth, use the line to sample textures on the height map and the color map. For each rasterized point of such line, render a vertical line into the view port from the given height to 0 with the given color. Repeat this process until the depth reaches the near z-plane. The algorithm can be optimized by drawing from front to back to avoid drawing unnecessary vertical line segments at the cost of an extra z-buffer.