Skip to content

Instantly share code, notes, and snippets.

@tkrotoff
tkrotoff / MinimalSVG.md
Last active March 11, 2025 23:28
Minimal SVG structure
<svg xmlns="http://www.w3.org/2000/svg" />
@tkrotoff
tkrotoff / #parseCookie.ts
Created January 23, 2025 10:42
Parses a `Cookie` HTTP header value or `document.cookie` into an object
function decode(str: string) {
try {
return decodeURIComponent(str);
} catch {
return str;
}
}
/**
* Parses a `Cookie` HTTP header value or `document.cookie` into an object.
@tkrotoff
tkrotoff / ImageFormat.md
Last active March 12, 2025 00:18
What image format to use?
flowchart TD
  format["What image format to use?"] --> source{"Analog or digital source?"}

  source -- "analog<br>(photo from a camera)" --> jpeg["JPEG lossy<br><br>(also AVIF, WebP, HEIF/HEIC, JPEG XL...)<br><br>Like MP3 format</span>"]
  source -- "digital<br>(using a software to draw the picture)" --> staticOrAnimated["Static or animated?"]

  staticOrAnimated -- "static" --> vectorOrRaster{"Can you make it scalable (vector based)?"}
  staticOrAnimated -- "animated" --> gif["GIF<br><br>(also APNG, AVIF, WebP, MNG, HEIF, video formats like MP4...)"]
@tkrotoff
tkrotoff / font.md
Last active April 5, 2025 17:41
What font to use? Web or system font?

What font to use? Web or system font?

Context and Problem Statement

@tkrotoff
tkrotoff / #parseEnv.ts
Last active April 8, 2025 14:55
Parse an env string (printenv output)
import assert from 'node:assert/strict';
/**
* Parses a string containing environment variables and returns a map of key => value pairs.
*
* The string format is `KEY=VALUE` pairs separated by new lines;
* it typically comes from UNIX command `printenv` or `env`.
*/
export function parseEnv(env: string) {
const lines = env