- Use TypeScript
- Expect the unexpected: yes, we use TypeScript, but you never know when things could go wrong
- Murphy's rule: whatever that can go wrong will go wrong
- Be liberal in what you accept, and conservative in what you give out
- This is related to handling remote data
- Some axioms
- Never trust user data
- Validate it
- Allow them to give you just about anything
- Never trust user data
- Some axioms
- This is related to handling remote data
- In HTTP, clients can decide what they want to give to you; do your best to parse as best as possible
import { z } from "zod"; | |
export type BaseNode<T extends string = "children"> = { | |
[K in T]?: BaseNode<T>[]; | |
}; | |
/** | |
* Creates a schema for a node that forms a directed tree. | |
* | |
* Usage: |
In the United States, protein isn't just a macronutrient---it's a cultural symbol. Whether it's emblazoned on snack bars at the checkout line or fueling Instagram influencers' morning routines, protein has become the star of the nutritional show. But what's behind this fixation, and how should health-conscious individuals navigate it?
Protein has long been associated with strength and vitality, but in recent decades, that connection has evolved into a full-blown obsession. Starting with the bodybuilding boom of the 1970s and later amplified by the low-carb craze of the 1990s and 2000s, protein earned a reputation as the "clean" nutrient---unlike fats, which were demonized, or carbs, which still struggle under the shadow of dietary suspicion.
Today, the narrative goes beyond physical health. A high-protein, mea
import * as bigintConversion from "bigint-conversion"; | |
const extendedGcd = ( | |
a: bigint, | |
b: bigint | |
): { result: bigint; x: bigint; y: bigint } => { | |
if (a === 0n) return { result: b, x: 0n, y: 1n }; | |
const { result, x: x1, y: y1 } = extendedGcd(b % a, a); | |
return { result, x: y1 - (b / a) * x1, y: x1 }; | |
}; |
I wrote this to teach myself on how React and other JSX library work behind the scenes.
First, you will need a bundler that doesn't exclusively work with React. Unfortunately, how to configure it is beyond the scope of this README file, since every bundler has their own way of converting JSX to JavaSript.
That said, there are some tutorials on how to do that.
Think of a bounded variable no different than a bounded queue to solve the consumer—producer problem.
A very common use case is for me is to push to a single variable from one producer, and pull from that single variable from one consumer.
Go has a very simple solution: channels.
But I was curious: can we improve the performance?
/** | |
Copyright 2023 Sal Rahman | |
Permission is hereby granted, free of charge, to any person obtaining a copy of | |
this software and associated documentation files (the “Software”), to deal in | |
the Software without restriction, including without limitation the rights to | |
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | |
the Software, and to permit persons to whom the Software is furnished to do so, | |
subject to the following conditions: |