Skip to content

Instantly share code, notes, and snippets.

View shovon's full-sized avatar
💻
Working on my own projects

Sal Rahman shovon

💻
Working on my own projects
View GitHub Profile
@shovon
shovon / base-node.ts
Last active May 13, 2025 07:14
Some zod schema utilities for creating a Zod schema for a recursive structure
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:
@shovon
shovon / gist:93960e4240fabd184150f441a4d3533e
Last active May 10, 2025 04:43
Frontend coding guidelines at my company
  • 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
  • In HTTP, clients can decide what they want to give to you; do your best to parse as best as possible

America's Protein Obsession: What's Driving It---and How to Navigate It Safely

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?

How Protein Became a Cultural Icon

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 };
};
@shovon
shovon / README.md
Last active July 10, 2024 22:52
A terminal emulator in Go

A terminal-based terminal emulator

Run a terminal from inside your terminal.

The purpose of this code is to demonstrate how to have applications running in a PTY (psedoterminal) environment.

Usage

Be sure to have Go installed.

@shovon
shovon / README.md
Created May 24, 2024 05:45
A dummy React clone

Kawaii: a dumb little JSX front-end library, purely created for educational purposes

I wrote this to teach myself on how React and other JSX library work behind the scenes.

Usage

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.

@shovon
shovon / README.md
Last active September 4, 2023 20:09

Bounded Variable

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?

@shovon
shovon / README.md
Created August 5, 2023 22:34
A sortable link list

Sortable Linked List

Usage

class ComparableNumber implements Comparable<number> {
	constructor(private _value: number) {}

	get value() {
 return this._value;
@shovon
shovon / base64.ts
Created April 10, 2023 05:23
Base64 encoder decoder in TypeScript
/**
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:
@shovon
shovon / e.md
Last active January 26, 2023 23:44

We want to prove that

$$ \left(1+\dfrac{1}{n}\right)^n < e < \left(1+\dfrac{1}{n}\right)^{n+1} $$

We will assume that $n \in \mathbb{N}$, $n &gt; 0$.

Left Side $(1+\dfrac{1}{n})^n &lt; e$