Skip to content

Instantly share code, notes, and snippets.

@reverofevil
reverofevil / video_noob_guide.md
Created January 2, 2026 23:16 — forked from arch1t3cht/video_noob_guide.md
What you NEED to know before touching a video file

What you NEED to Know Before Touching a Video File

Hanging out in subtitling and video re-editing communities, I see my fair share of novice video editors and video encoders, and see plenty of them make the classic beginner mistakes when it comes to working with videos. A man can only read "Use Handbrake to convert your mkv to an mp4 :)" so many times before losing it, so I am writing this article to channel the resulting psychic damage into something productive.

If you are new to working with videos (or, let's face it, even if you aren't), please read through this guide to avoid making mistakes that can cost you lots of computing power, storage space, or video quality.

namespace Example1 {
type Sig<I, O> = (input: I) => O;
declare const imm: (int: number) => Sig<[], [number]>;
declare const add: () => Sig<[number, number], [number]>;
interface Builder<Stack> {
$: <I extends any[], O extends any[]>(
instr: Stack extends [...I, ...any[]] ? Sig<I, O> : never
) => Builder<Stack extends [...I, ...infer R] ? [...O, ...R] : never>
}
@reverofevil
reverofevil / remy.ts
Created February 5, 2024 21:36
Remy's algorithm in TypeScript
type VarName = string;
type Expr = Var | App | Lam | Let;
type Var = { $: 'var', readonly name: VarName }
const Var = (name: VarName): Var => ({ $: 'var', name });
type App = { $: 'app', readonly left: Expr, readonly right: Expr }
const App = (left: Expr, right: Expr): App => ({ $: 'app', left, right });
type Lam = { $: 'lam', readonly name: VarName, readonly expr: Expr }
const Lam = (name: VarName, expr: Expr): Lam => ({ $: 'lam', name, expr });
type Let = { $: 'let', readonly name: VarName, readonly def: Expr, readonly body: Expr }
@reverofevil
reverofevil / totp.ts
Created January 27, 2024 23:35
Github TOTP in Node.js
import { createHmac } from 'crypto';
// token here
const priv = "...";
const base32chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
const base32tohex = (base32: string) => base32
.toUpperCase()
.replace(/=+$/, "")
.split('')
@reverofevil
reverofevil / use-fetch.ts
Last active May 16, 2023 23:50
Hook for fetch
import React, { useState, useEffect, useReducer, FC } from 'react';
type FetchState =
| { readonly type: 'initial' }
| { readonly type: 'loading', readonly onAbort: () => void }
| { readonly type: 'error', readonly error: unknown, readonly onRetry: () => void }
| { readonly type: 'ok', readonly value: unknown }
| { readonly type: 'aborted', readonly onRetry: () => void }
const initial: FetchState = { type: 'initial' };
@reverofevil
reverofevil / rb.hs
Created May 10, 2023 13:34
Red-black trees with deletion in Haskell
import System.Random
import Data.Array.IO
import Control.Monad
data Color = R | B deriving (Eq, Show)
data Tree a = E | N Color (Tree a) a (Tree a) deriving (Eq, Show)
data Result a b = D a | T b deriving (Eq, Show)
sseq (D x) f = D x
sseq (T x) f = f x
@reverofevil
reverofevil / yard.hs
Last active May 10, 2023 05:34
Shunting yard algorithm in Haskell
import qualified Data.Map.Lazy as M
import Data.Maybe
data Assoc = L | R deriving (Eq, Show)
-- operator table
table = [
(["||"], 20, L),
(["&&"], 30, L),
(["|"], 40, L),
@reverofevil
reverofevil / brzozowski.ts
Created June 20, 2022 00:21
Brzozowski's DFA minification in JavaScript
type Dfa<Tag> = {
trans: Map<string, [Tag, string][]>;
initial: string[];
final: string[];
}
const invertEdges = <Tag,>(auto: Dfa<Tag>): Dfa<Tag> => {
const trans = new Map<string, [Tag, string][]>();
for (const [from] of auto.trans) {
trans.set(from, []);
import "./styles.css";
import React, { useRef, useState, useEffect, useCallback } from "react";
import { unstable_batchedUpdates as batch } from "react-dom";
// call `f` no more frequently than once a frame
export const throttle = (f) => {
let token = null,
lastArgs = null;
const invoke = () => {
f(...lastArgs);
type IfEquals<X, Y, A, B> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? A : B;
type ReadonlyKeys<U, T = { [K in keyof U]-?: U[K] }> = {
[P in keyof T]: IfEquals<{ [Q in P]: T[P] }, { -readonly [Q in P]: T[P] }, never, P>
}[keyof T];
type Full<T, R = ReadonlyKeys<T>> = {
-readonly [K in keyof T]-?: {
type: T[K],
optional: T extends Record<K, any> ? false : true,
readonly: K extends R ? true : false,
}