Skip to content

Instantly share code, notes, and snippets.

View AshishBhattarai's full-sized avatar

Ashish Bhattarai AshishBhattarai

View GitHub Profile
@AshishBhattarai
AshishBhattarai / 2d_physics.js
Last active October 13, 2024 06:28
Simple 2D Rigid Body Solver in JS
// https://ricefields.me/2024/10/11/intro-to-physics-simulation.html
const canvas = document.getElementById('render_canvas');
const ctx = canvas.getContext('2d');
function resizeCanvas() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
resizeCanvas();
window.addEventListener('resize', resizeCanvas);
@AshishBhattarai
AshishBhattarai / tlsf.zig
Last active November 22, 2024 18:21
Two-Level Segregated Fit memory allocator
const std = @import("std");
const Allocator = std.mem.Allocator;
const MemoryPool = std.heap.MemoryPool;
pub fn bit_scan_msb(mask: usize) u8 {
return 63 - @clz(mask);
}
pub fn bit_scan_lsb(mask: usize) u8 {
return @ctz(mask);
}