Skip to content

Instantly share code, notes, and snippets.

let w and h be the width and the height of the screen, respectively.

let a be the ratio of the width to the height.

a = w / h

Note that this is equivalent to the aspect ratio of the screen for the case where the screen is wider than it is tall, and the inverse of the aspect ratio otherwise.

Let q be the area of the screen.

#include "ki25.h"
// convert an index into a coordinate,
// given a width `w` and height `h`
si u16 xcoord(u32 i, u16 w, u16 h) { return i % w; }
si u16 ycoord(u32 i, u16 w, u16 h) { return i / w; }
// normalize value on a scale from `0` to `s`
si f32 fnorm(u16 x, u16 s) { return (f32)x / s; }
// KI25 -- Keep It 2hort 5tupid
// TABA -- These Are Bad Acronyms
// - (probably) bad variable names
// - horrible function names
// - reserve for extremely common stuff
#define si static inline
#include <stdint.h>
@acdimalev
acdimalev / cfg.sh
Last active November 4, 2023 21:59
building a miniaturized control flow graph
#!/bin/sh
r2 -qc "e anal.bb.maxsize=2048;s sym.$2;af;agfj" "$1" | python3 control-flow-graph.py
@rygorous
rygorous / cheb.py
Created November 30, 2021 23:34
Chebyshev evaluation pseudocode
# Chebyshev evaluation with interval rescaled to [0,1]
xp = 2*x - 1 # remap to [-1,1] that Cheb basis is easier in
# Constant and linear terms
result = coeffs[0] + xp*coeffs[1]
# Recurrence for remaining terms
cur, prev = xp, 1
t = xp * 2