Skip to content

Instantly share code, notes, and snippets.

@mrange
mrange / main.c
Last active February 24, 2026 12:50
Obfuscated C experiment: Nothing special
#define _GNU_SOURCE
#include<math.h>
#include<sys/ioctl.h>
#define V for(n=0;n<3;++n)
#define F c+=sprintf(b+c,
//////////////////////////////////////
// "Nothing Special"-Posix version ///
// by mrange 2026-02-22 ////
// // //
// Compile and run with: // //
@mrange
mrange / Program.cs
Created February 21, 2026 11:51
Spectre Playground Effect
// "Nothing Special" shader by Mårten Rånge
var terminal = new BrowserTerminal(
AnsiConsole.Console,
AnsiConsole.Profile.Width,
AnsiConsole.Profile.Height);
var renderer = new Renderer(terminal);
var writer = AnsiConsole.Profile.Out.Writer;
writer.Write("\x1b[?25l"); // Hide cursor
@mrange
mrange / main.cpp
Created January 27, 2026 11:16
pimpl
#include "pimpl.h"
int main() {
auto x = new pimpl();
x->the_method();
delete x;
return 0;
}
@mrange
mrange / units.fs
Last active October 7, 2025 19:56
F# measures
open LanguagePrimitives
// Units of measure are *compile-time* type tags on numeric types
// They prevent mixing incompatible dimensions (meters vs seconds) and have *no runtime cost*.
type [<Measure>] m // meter (length)
type [<Measure>] kg // kilogram (mass)
type [<Measure>] s // second (time)
type [<Measure>] A // ampere (electric current)
type [<Measure>] K // kelvin (thermodynamic temperature)
type [<Measure>] mol // mole (amount of substance)
type [<Measure>] cd // candela (luminous intensity)
@mrange
mrange / 0_main.glsl
Last active October 6, 2025 17:15
Bonzomatic Prelude
// -----------------------------------------------------------------------------
#version 430 core
// -----------------------------------------------------------------------------
uniform float fGlobalTime; // in seconds
uniform vec2 v2Resolution; // viewport resolution (in pixels)
uniform float fFrameTime; // duration of the last frame, in seconds
uniform sampler1D texFFT; // towards 0.0 is bass / lower freq, towards 1.0 is higher / treble freq
uniform sampler1D texFFTSmoothed; // this one has longer falloff and less harsh transients
@mrange
mrange / shadertoy.glsl
Last active September 3, 2025 18:27
Grid glow tracer
// CC0: Grid glow tracer
// Shadertoy compatible
float fbm_noise(vec3 P) {
float
a=.6
, d=0.
, k=0.
;
for(P*=.2;++k<4.;P=P.yzx) {
// Used Dot noise by XorDev as an example.
@mrange
mrange / FuleSnabel.glsl
Created August 18, 2025 20:04
FieldFX 2025-08-18
// -----------------------------------------------------------------------------
#version 430 core
// -----------------------------------------------------------------------------
uniform float fGlobalTime; // in seconds
uniform vec2 v2Resolution; // viewport resolution (in pixels)
uniform float fFrameTime; // duration of the last frame, in seconds
uniform sampler1D texFFT; // towards 0.0 is bass / lower freq, towards 1.0 is higher / treble freq
uniform sampler1D texFFTSmoothed; // this one has longer falloff and less harsh transients
@mrange
mrange / FuleSnabel.glsl
Created August 4, 2025 20:13
Field-FX 2025-08-04
// -----------------------------------------------------------------------------
#version 430 core
// -----------------------------------------------------------------------------
uniform float fGlobalTime; // in seconds
uniform vec2 v2Resolution; // viewport resolution (in pixels)
uniform float fFrameTime; // duration of the last frame, in seconds
uniform sampler1D texFFT; // towards 0.0 is bass / lower freq, towards 1.0 is higher / treble freq
uniform sampler1D texFFTSmoothed; // this one has longer falloff and less harsh transients
@mrange
mrange / FuleSnabel.glsl
Last active July 29, 2025 05:33
Field-FX 2025-07-28
// 2025-07-28 - DJ alkama - 126 BPM
// https://scenesat.com/videoarchive/FYBKI5?bs5#show-FYBKI5
// -----------------------------------------------------------------------------
#version 430 core
// -----------------------------------------------------------------------------
uniform float fGlobalTime; // in seconds
uniform vec2 v2Resolution; // viewport resolution (in pixels)
uniform float fFrameTime; // duration of the last frame, in seconds
@mrange
mrange / README.md
Last active April 21, 2025 06:50
[F#] Implementing Coroutines (async/await) using continuations

[F#] Implementing Coroutines (async/await) using continuations

Coroutines or async/await is not a new concept as it was named in 1958 by Melvin Conway. Coroutines had support in languages such as Simula(1962), Smalltalk(1972) and Modula-2(1978) but I think one can argue that coroutines came into mainstream with C# 5(2012) when Microsoft added async/await to C#.

The problem with subroutines

A thread can only execute a single subroutine at a time as a subroutine starts and then runs to completion. In a server environment subroutines can be problematic as in order to service connections concurrently we would usually would start a thread per connection, this was the idiom a few years ago. A thread depending on the operating system and settings needs about 1 MiB of user stack space meaning 1,024 threads needs 1 GiB of for just user stack space. In addition there's the cost of kernel stack space, book-keeping and scheduling of threads. This drives cost of VM/hardwa