Reading tip: If you’re already familiar with boring math like Vectors and dot products, feel free to skip ahead. Then if you understand nothing, get back here, sit down, take a deep breath and read…
This is my attempt to benchmark and compare the quality of some of the well known Qwen3.6 27B quantizations on HuggingFace (unsloth, mradermacher, IQ4_XS from cHunter789 and Ununnilium), from Q8 all…
When Claude Code needs your attention — whether it’s waiting on a permission request, finished a long task, or just has something to tell you — it’s easy to miss if you’ve switched to another window…
Text-to-diagram seems to be an area that has been solved perfectly by LLMs, but only with popular languages like Mermaid or PlantUML. There are many other less popular diagramming languages like D2…
This year, I decided to use Zig to solve Advent of Code. I started learning Zig sometime ago but took a break. It was not something easy from the beginning, so in the first few days, I had to use…
OK, this one is super useful, I promise! As you may already know, we can use toHaveBeenCalledWith on a spied function to check if that function has been called with a set of arguments. For example…
For the uninformed, optional chaining is a new JavaScript feature that allows you to access property values deep inside an object without checking that each reference in the chain is valid. For…
Sometimes we need to mock a FileList, for example, when we need to test file upload features. First, create a mock File object: The above function creates a file with a custom extension and size…
One approach to testing the localStorage function in Jest is to mock the setItem/getItem methods. To mock something with localStorage, we can do it via the Storage.prototype, for example: Now, you’ll…
Previously, I hosted Plausible on my Linux server. It’s a Google Analytics alternative, that runs as a set of 4 Docker containers, managed with docker-compose. Which is cool. The uncool part is, that…
A parser is a program that usually takes a stream of lexical tokens and transforms them into another data structure, usually in the form of a parse tree that satisfies the language’s grammar rules…
In the previous article, we get an overview of how bytecode is executed in a stack machine. In this article, we continue to dive into the details of a different scenario: Variable declaration. In the…
Different programming languages have different approaches to executing their code. Some languages execute the code as they travel the AST (Tree Walk approach), and some languages compile the code into…
An event system is a mechanism for globally receiving and broadcasting messages, which can be used in a Web Application to allow different components that do not have any parent-child relation to…
Let’s say, we have a problem that requires us to print all the digits of a number from the left to right. A simple approach would be extracting the digits from the right to the left, storing them in…
In the previous article, we learned about Bitboard and how to use it in a simple board game. In this article, let’s see how Bitboard can be actually used to implement a chessboard. For those who are…
Bitboard is a widely-used technique in many computer chess programs for efficiently representing and extracting information on the chessboard. It seems to be simultaneously invented by the computer…
Let P be the intersection point, A is the anchor point of the ray, B is the endpoint of the ray (assuming the ray is length-limited) and C is the circle’s center point, with radius r. Now we have 3…
In mathematics, the fundamental theorem of arithmetic states that: “Any integer number larger than 1 can be written as a product of prime numbers in one and only one way”. No matter how you come up…
In the “Use String as Enum Key” article, we use the keyof typeof keywords to create a union of an enum’s keys. It might not be immediately clear why and how this keywords combination works. In this…
go-staticcheck is a static code analysis tool for Go. It has an interesting ability to detect infinite recursive calls. For example, infinite calls like this would be detected early before the program…
In a computer system, there are 2 types of clocks: Wall Clock (or Real-Time Clock): is the clock that is synchronized with NTP (Network Time Protocol), which is subjected to jump (moving forward or…
In TypeScript, you can define an enum and access its value with a string-like value, like this: In this example, the type of the key variable is not actually a string, but a literal type called…
Sometimes, you will need to count the frequency of letters in a string and do something with that count. For example, with a simple algorithm to check if a string is a permutation of another one, we…
Delve is a GDB-alike debugger for Golang, with better support for Go’s data structures and Goroutine. To install Delve on M1 Mac devices, you first need to install the Go ARM64 version, then install…
Cyclic Sort is an easy to implement and efficient algorithm. The only caveat is that it requires an input array to be a continuous range of values. It can be applied to the problems of finding…
In a Linked List, traversal is restricted to forward only, you can’t really go back to previous nodes once you go past them. When working on a problem that requires us to do some lookup in a Linked…
Nx is a tool to create and manage multiple-project workspaces. One of its most important features is the ability to track the changes in your projects in your workspace and only rebuild what is…
Some notes about some not-so-well-known things about TypeScript Classes. In TypeScript, you can define a class’s properties in two ways: Define it as a class property in the normal way, or define it…
OK, this one is embarrassing, I still remember the first time I was taught to dry run the code. It was many years ago when I started learning how to program. But I’ve never actually tried it properly…
For the problems that require us to do something a stream of values, or a subsequence of an array, the typical approach is to use a sliding window. A naive way to implement a sliding window is to have…
The problem Given two non-decreasing arrays a of length m, and b of length n. Merge the two arrays into array a. Since it’s an in-place merge, a has some extra spaces to fit the result. The solution…
This article is inspired by the talk How the TypeScript compiler compiles, you should really check it out for a more in-depth understanding about the TypeScript’s compiling process. At a high level…
In the previous post, we learned how some utility types are implemented. The fact that they’re all done at the type level is very interesting. But not all utility types can be done like that. In…
TypeScript provides several utility types to help us manipulate types easier, like: Partial<T>, Required<T>, Pick<T, Keys>,… Internally, these types are implemented in the src/lib/es5.d.ts, at the…
In TypeScript, all the type definitions for the Web API are implemented in the lib.dom.d.ts file. One interesting thing is, this file is automatically generated from the Web Standards and does not…
Memoization is the technique to let an expensive function return the cached value if all of its arguments remain unchanged. When a React component is wrapped inside a React.memo, the render result of…
When working with text and CSS, we usually assume that the default font size of the browser is always a fixed number (for example, 16px), therefore, we don’t think much when setting the base font size…
Hanging punctuation is the practice of pulling the punctuation marks into the margin of a text so that it does not disturb the vertical reading flow. It was first introduced by Gutenberg in the…
In CSS, we can create a custom list numbering with counter-reset, counter-increment and counter() functions. For example: This approach works fine for most of the continuous list, for example: But…
So, I want to look into the TypeScript source code to understand how things work and maybe contribute to the project as well. This is a quite big project but I think the code organization is pretty…
Active Listening is a process to engage and empathize with the speaker when talking about something. The most important part of active listening is to: Try to understand the topic you’re listening to…
In Angular, component styles are isolated (a.k.a View Encapsulation). That means CSS styles of a component are only affect the component itself, not its parent or child components. It is helpful…
Using serde, we can serialize a data structure into different formats, for example, JSON: Output: Sometimes, we need to exclude some fields from the original data structure when serializing. To do so…
Collector’s Fallacy is the urge to collect something that you never use or need, but the act of collecting gives you a good feeling (cognitive reward). For example: Save every article on the internet…
Angular is: A component-based framework to build web apps A collection of libraries that support multiple features such as routing, form management, client-server communication,… A suite of tools to…
As a developer, our main job is contributing to code projects, it can be a work project or an open-source project. With work projects, we might have access to more resources (other developers to learn…
Let’s say, you have the object store called characters as the following table: To update a record, we can use IDBObjectStore.put() method, but this will update the value object as a whole. In case you…
LocalStorage is a popular solution to persists data (locally) across sessions for web applications, but there are some limitations, for example: It is limited to 10MB on most browsers. On Safari, it’s…
Article: https://www.nytimes.com/2020/04/07/smarter-living/how-to-edit-your-own-writing.html Writing is like thinking. You will not know precisely what you are going to say before you say it. And many…
Coming from React or other UI frameworks, when it comes to building large applications, you might have the habit of breaking it into smaller components. This mental model does not fit in Elm, in fact…
The Learning How to Learn course proposed an idea that there are two modes of thinking: Focused and Diffuse. You are either in one of the two modes but never be in two modes at the same time. Focused…
In RxJS, a Subscription is an object that represents an execution of an Observable. It has the most important method, the unsubscribe(), mainly used to cancel the execution. For example, we usually…
Structured data is a special data snippet you can insert into your page to help Google Search identify your content in a richer way (called Rich Result). It usually comes in the JSON-LD format. For…
The curse of knowledge is a cognitive bias of assuming that others have the same background knowledge to understand what you are talking. It is also known as the False-Consensus Effect. This bias…
Painting and Compositing are the last two steps to generate a frame in the browser’s pixel pipeline. Painting is the process of creating a single or multiple layers (a.k.a compositor layers) for each…
When a DOM node is written (change of style, attribute, or inner content), and the action triggers a layout change, the browser must do a layout recalculation (reflow). The browser usually waits for…
Article: https://fs.blog/feynman-learning-technique/ There are 2 types of knowledge: Knowing the name of something Understand something With a full understanding of something, you will be able to use…
Most devices refresh their screen 60 times a second. On each refresh, the graphics driver generates the pixel data from the frame provided by the application and sends it to the monitor to display. To…
If you are busy, here is the TL; DR: React Reconciliation is the tree diffing algorithm that React used to update your application’s DOM tree between renders. The existing algorithms do this in O(n^3)…
The Zeigarnik Effect means: If you are working on a task and being interrupted, the task remains longer in your mind, making it easier to remember the task’s details. A more detailed explanation for…
On Github, you can create a CODEOWNERS file in the .github/ or docs/ folder to specify which person or team is responsible for the code in a repository. If a file or a folder has a code owner, their…
One of the most confusing things in JavaScript is the context object this inside a function. The value of this depends on how the function is called, not how the function is defined. Let’s take a look…
Article: https://en.m.wikipedia.org/wiki/Tetris_effect Tetris Effect is an effect that happens when you devote a large amount of time and mental effort to do something, it will shape the way you…
By default, the TypeScript compiler tries its best to analyze the code and infer the type of your variables. Type Assertion is when you tell the compiler that you know a variable has a specific type…
The Elm Architecture is not something necessary exclusive to the Elm language but should be viewed as a generic design pattern for architecting GUI applications. In fact, this architecture is adopted…
Article: http://nathanmarz.com/blog/suffering-oriented-programming.html OK, so I came across this very interesting article about product building. The author talks about a style of programming that he…
Let’s say you are tasked to build the next Amazon, and you gotta start small. So, you build a website that only sells books and audiobooks for now. The system would have the BaseItem type, defining…
In TypeScript, an enum can be defined in various ways: a numeric enum, a string-based enum, or heterogeneous enum. By default, any enum member will have a numeric value: A string-based enum is an enum…
When you specify a percentage value for the CSS padding or margin of an element, this percentage is based on the width of the containing block, not the width of the element itself. For example, in the…
This note only covers the mechanism of Bitwarden’s end-to-end encryption for a single user, between one or more clients. For more information about how they handle user authentication and password…
PBKDF2 is a key derivation function, used in the process of deriving encryption keys. The main idea of PBKDF2 is repeatedly applying the input and the salt to a hash function like HMAC to produce a…
Article: https://blogs.scientificamerican.com/symbiartic/rediscovering-the-forgotten-benefits-of-drawing/ In the old times, scientist are required to have drawing skill, because they have to recreate…
Reference Link: https://eric.ed.gov/?id=EJ718563 Full text: https://files.eric.ed.gov/fulltext/EJ718563.pdf In this article, the author make the point about what is the worst way to read (passively…
Unlike C/C++, the delete operator in JavaScript has nothing to do with memory deallocation. What it actually does is remove a property from its parent object. If there is no more reference to that…
There are two ways to represent a graph data structure, each come with its own pros and cons. An adjacency matrix is a square matrix, each element in the matrix indicate whether pairs of vertices are…
You can think of unknown as a type-safe version of any. They are both used to represent the type of value that is unknown beforehand (like a result of JSON.parse,…), but unknown required us to do more…
Macro is a complex type of repeation, it allow you to record and replay a sequence of actions. A macro can be created by: Press q<register-name> to start record mode and store the macro to the…
In Rust, there is a Result<T, E> type that could return either an Ok(T) value if the operation is succeeded, or an Err(E) value if the operation is failed. To mimic this type in TypeScript, first…
Railroad Diagrams (or Syntax Diagrams) are the graphical way to represent context-free grammars. Each diagram defines a nonterminal. And they must have an entry point and an endpoint. There is no…
Backus-Naur Form (BNF) is a metasyntax for context-free grammars, is used to describe the syntax of languages used in computing such as programming languages, instruction sets,… The specification of…
A derivation of a string for a grammar is a sequence of production rule applications. The process of getting the string through the derivation is the parsing process. For example, with the following…
Context-Free Grammar (CFG) is a grammar where production (or rewrite) rules are in the form of: A is a single nonterminal symbol, and \alpha is the string of terminals or nonterminals, it can also be…
One thing about JavaScript that is sometimes confusing: The named imports. When there is a big module that exports a lot of things, we usually think that we can use named import to get just what we…
Like Ngrok, Cloudflare Tunnel is a lightweight daemon that run on your server (or local machine) and create a tunnel between your machine and the Cloudflare edge, allowing you to expose your local…
Timing attack is the type of attack when an attacker tries to analyze the time it takes your application to do something, in order to guess the data it’s operating on. For example, you build an API…
To use Jest for testing a TypeScript library, we need to install a couple of things: And set up the jest.config.ts file to use the ts-jest transformer when processing *.test.ts files: From now on, you…
With Parcel 2.0, it’s very easy to build a TypeScript library and publish them to NPM later on, with automatically generated types and built-in support for both CommonJS and ESModule. Let’s say you…
In JavaScript, you can use any ASCII characters as variable or function names, even non-English words or some special symbols: But sadly you cannot use emojis: Apparently, this is not only possible in…
When you load custom web fonts with just the regular font-weight, no bold or italic styles, the browser tries its best to render them in bold and italic style by faking it. These styles are called…
Interpolation is a type of estimation method for finding new data points based on the range of a discrete set of known data points. The most basic kind of interpolation is Linear Interpolation (Lerp)…
Safari on iOS and macOS devices have the ability to automatically retrieve and autofill the OTP code sent via SMS if your input has the autocomplete="one-time-code" attribute: To make the SMS OTP more…
Sometimes, we want to call an FFI function that is CPU-bound. This would block the main thread. For example, in this sleep_and_scream method from Rust, we use std::thread::sleep to hang the function…
From version 1.13, Deno introduced the FFI API (foreign function interface API) that allows us to load libraries built in any language that supports the C ABI (like C/C++, Rust, Zig, Kotlin,…). To…
In Postgres, tables can have Row Level Security that restrict the user’s action on each row. With Supabase, we can create a policy that matched the current logged in user, this user is from the…
wasm-bindgen is an awesome tool made by rustwasm team, make it very easy to expose Rust’s data/functions to JavaScript and vice versa. To use, you can add a #[wasm_bindgen] as an annotation the code…
WebAssembly is executed using a stack-based virtual machine. There are two types of execution of a WASM module: Instance Execution: If the module contains a start section, the referenced function here…
Table is another shared instance in WebAssembly just like Linear Memory, but it can only store function references. It can be shared between modules, and all you can do with tables is to make indirect…
Linear Memory in WebAssembly is a contiguous and mutable array of uninterpreted bytes. It is shared between the WASM module and the host runtime. It can be expanded by calling WebAssembly.Memory.grow…
Just like a good-old-Assembly program, a WebAssembly module is made up of different sections: (Source: rsms/Introduction to WebAssembly) The type section contains a list of each unique function…
WebAssembly is a new type of code that can be loaded and run by the JavaScript VM on web browsers. It can also be run natively on the computer by other WASM runtimes like Wasmer. WebAssembly is fast…
A Vector in Rust is fundamentally a (pointer, capacity, length) triplet. For example, a Vec<Char> containing two elements 'a' and 'b', with the capacity of 4, can be visualized as the following…
Suppose that a number n has d digits, then: Because 10^d is the smallest integer with d + 1 digits. Now, take logs base 10 of this relation: This becomes: If you now take the integer part of…
By using generic parameters, you can impl a trait for any type that satisfies some trait bounds, for example, implement trait ToString for every type T that implemented the Display trait: This…
Rust has a special type ! to imply that there is no return value. Usually called never type. It allows us to write code like this: We expect the num variable to have the type f32 if the input is…
Before Rust 1.0, writing code that returns a reference without any lifetime annotation wouldn’t compile. Because Rust does not know what’s the lifetime of the returned reference: In later versions…
The built-in console comes with the console.assert method, which is pretty useful to write some tests in your code. This method has the syntax of: When the assertion expression returns false, the…
Overflow can happen when doing integer arithmetics in Rust, for example: Rust handle overflow differently between Debug and Release mode: In debug mode, Rust includes checks for integer overflow that…
The traits std::ops::Deref and std::ops::DerefMut are used for explicit dereference operations (immutable or mutable), like: If a type T implements Deref<Target=U> or DerefMut<Target=U> like this: Any…
One of the rules for working with traits in Rust is: You are not allowed to implement a trait on a type if either the trait or the type is not local to your crate. For example, within your program…
Due to rounding errors, most floating-point numbers cannot be represented precisely in the computer. This led to some weird situations like: Different languages handle this calculation differently…
ArenaAllocator is one of Zig’s built-in allocators. It takes another allocator and wraps some code around to allow you to allocate memory without the need to free them individually. Every allocated…
There are 4 build modes in Zig, each can be enabled via the arguments -O ReleaseSafe, -O ReleaseSmall, and -O ReleaseFast when running zig run or zig test. Depending on which mode is enabled, runtime…
A function in Zig can return either an error or an actual value, most of the time you will see something like this: The return type of these functions is the combination of an error set type and an…
Zig has built-in support for JSON via the std.json module. To convert any object into a JSON string, we use std.json.stringify(<input>, <options>, <output stream>): See StringifyOptions struct for…
Implementing a stack is one of my favorite tests when working with a new language because it will show us a lot about the language’s ergonomics. We are going to make this stack a generic data…
Zig came with a built-in C/C++ compiler zig cc and zig c++. So you can compile and run your C/C++ code with Zig! For example, let’s compile this simple C program: What’s more interesting is…
One of the unique features of Zig is the ability to let us control what happens in our code, during both runtime and compile time. For optimization, Zig implicitly performs some evaluations at…
Zig has no runtime, hence, no automatic memory management. It’s the developer’s responsibility to manage the allocation/deallocation of memories. It’s important to know how memory allocation works…
Just like C/C++, you can define a string in Zig with an array of bytes or as a null-terminated string literal. You can reference to any byte in the string just like an array: Or reference to a…
In React, you can mount a component into any DOM node instead of just the current parent component, with the help of ReactDOM.createPortal([content], [node] ). It’s very helpful when working with…
Let’s say, we are building a component to display some images (with lazy loading): And this component takes some properties (ImageProps) that came from the two imaginary types: The most inefficient…
Sometimes, you’ll run into a case where TS keeps complaining about a possibly undefined value. For example: The proper way to handle this error is actually to check if a is valid before returning any…
In Next.js, you can define a dynamic route by creating a file at /pages/post/[id].tsx. And this will catch all URLs like /post/foo, /post/bar,… But if you want to catch URLs like /post, you will have…
Algorithm to delete a node from a BST: Find the node to delete Find the deepest right most (DRM) node of the tree Replace the node to delete with the DRM Continue find and delete the DRM in the tree…
To create a custom widget in Druid, we create a new struct and implement Widget trait. Or create a function that returns an impl Widget. Widget trait defined a few lifecycle methods for a Druid’s…
This one is a bit more compex than the pre-order (in term of using stack). Algorithm: Create an empty stack Create a temporary reference called curr, set it as root Repeat while curr still not null…
When solving palindrome problems, we need to avoid sliding window solution (a.k.a brute force), where we try to generate every substring and check to find the palindrome. The good approach to go for…
The array x is to keep track of all possible integers we can find, the array t is to keep the sum t[i] of every x number from x[1] to x[i]. Now, let’s write a Generator algorithm with Backtracking…
The algorithm is simple: Find the right most element less than n Increase it Set the other right the same It can be implemented as following: And here’s how we would use it:
Like currying, if a function takes some arguments and we invoke that function without all of the arguments, a new function will be created so we can call it with the remaining functions later on. In…