Lessons from UNO

The vanilla UNO itself is a simple game to implement. Initially I thought of doing a completely command-line based interface, but that gets very unwieldy. So I quickly switched to termui. Being built for dashboards, the UI library itself isn’t the most glamorous and I am contemplating moving to bubbletea. But that has to wait. session with 4 players In this post, I will note down a few of the stuff I have learned while implementing this prototype....

<span title='2023-04-18 19:41:54 +0530 IST'>April 18, 2023</span>

Action, Reflection

Action, then reflection. Act, then reflect, then revise. Never do the two together. This is one of the key takeaways from Steven Pressfield’s “Do the Work”. I encounter mental states where it’s easy to fall into analysis paralysis. These are the times when it’s crucial to fall back into the act then reflect mode. Over time, I can only hope that the “correct” approach comes to me easier. The fuck around vs find out curve is a very real thing....

<span title='2023-02-22 11:08:42 +0530 IST'>February 22, 2023</span>

Parsing JSON requests with zod

In the spirit of parse, don’t validate, I’ve started using zod as my go-to JSON parsing library in Typescript. JSON.parse, or something like response.json() gives you an valid JS object but in your application you’re usually working with a richer set of types that will almost always require validation. The idea is to parse the JS object into a Typescript object. While there are powerful parser combinator libaries for JavaScript, zod takes a simpler approach by only allowing you to JSON objects1 and only exposing a few (and very sane) set of parsers for each field....

<span title='2023-02-19 16:06:56 +0530 IST'>February 19, 2023</span>

CORS and Cookies

Articles and Libraries Explains CORS including some of its origin story Go CORS middleware General notes Cross-origin requests, are resource-scoped. In REST terms, the server can decide whether to allow cross-origin requests to a particular API or not. That capability is naturally exposed by the Go middleware above - and you can wrap any handlers (which correspond to paths) you have for which you want to enable CORS. In python frameworks, a @cors(....

<span title='2023-02-08 22:37:45 +0530 IST'>February 8, 2023</span>

font-variation-settings

Recently I came to know about the CSS font-variation-settings property by way of the amazing Recursive font family. So I have been thinking of different ways of utilizing it. Of course, you would need a font that has a lot of “axes” on which you can vary it. Commonly used fonts usually have just a single axis that you can interpolate on: the weight axis. But recursive supports 5 axes that you can vary and get amazing looking types....

<span title='2023-01-12 04:02:30 +0530 IST'>January 12, 2023</span>

Caddy

This blog (and my personal git server) are running on Caddy. No more elaborate certbot-based setup thanks to Caddy’s Automatic HTTPS feature. Couldn’t find a detailed example that sort of shows a good Caddyfile for a single website so here’s mine. nrawrx3.xyz log { output file /var/log/caddy.log { roll_size 1gb roll_keep 5 roll_keep_for 720h } } root * /blog-root rewrite /blog /blog/ handle /blog/* { file_server } handle /css/*.css { root * /blog-root/blog/ file_server } handle_errors { @404 { expression {http....

<span title='2022-11-15 18:59:43 +0530 IST'>November 15, 2022</span>

Date interval operations

Trivia - Off-by-one errors and Interval notations Dumping some info about working with intervals with a focus in implementation in Go. Date intervals in particular, and one dimensional integer intervals in general (if you want to be really formal). We will denote an interval as [a .. b] that represents all the numbers i such that a ≤ i ≤ b. In some cases it is actually neater to work with “half-open” intervals, which are denoted as [a ....

<span title='2022-11-02 07:02:30 +0530 IST'>November 2, 2022</span>

Representation

Fred Brooks, in his all-time best-selling computer science text, The Mythical Man-Month says: Representation is the essence of computer programming. … Show me your flowcharts and conceal your tables, and I shall continue to be mystified. Show me your tables, and I won’t usually need your flowcharts; they’ll be obvious. Tools like LSP have made it possible to navigate code using static-types so much easier than they were even a just a decade or so ago....

<span title='2022-10-26 21:25:12 +0530 IST'>October 26, 2022</span>

Keyboard

I am doing most of my typing nowadays on a Tofu65 keyboard. The keyboard is a so-called custom keyboard. The basic package includes components that you have to assemble together to build your keyboard. Some custom keyboard packages come with most of the components required to build a basic working keyboard and as such the user needs to do very little extra purchase. But Tofu65, like most packages, comes with only the case, a case foam, the pcb and the plate....

<span title='2022-09-12 17:04:06 +0530 IST'>September 12, 2022</span>

Writing small stuff

I’ve been working on a terminal-based uno game, on and off, for a couple of months now. While the core logic of uno is simple, there’s a lot of things implementing a multiplayer command line game can teach a programmer. How do you sync between game events and UI is one pillar of your codebase. How do you transition between the different states of the admin and the player clients? What happens when a player disconnects?...

<span title='2022-05-17 12:43:59 +0530 IST'>May 17, 2022</span>