Skip to content

Instantly share code, notes, and snippets.

@rmitton
rmitton / sort_analysis.cpp
Created September 18, 2023 14:30
A small test harness for timing different sorting algorithms.
// A small test harness for timing different sorting algorithms.
// Prints a graph as a .svg file to stdout.
//
// sort_analysis.exe > output.svg
//
#include <stdio.h>
#include <windows.h>
#include <assert.h>
#include <math.h>
@rmitton
rmitton / hipparchus.c
Created August 30, 2020 02:27
Mandelbrot set rendered from a first-person viewpoint
// I don't know what I'm looking at here.
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <math.h>
#define OUTPUT "hipparchus.pgm"
#define WIDTH 1024
@rmitton
rmitton / function.cpp
Last active February 29, 2020 19:22
Tiny std::function implementation
/* EDIT:
* For future reference, this code doesn't work right so don't use it.
* (but probably could be fixed with some care and attention)
*/
// Tiny std::function workalike, to allow storing lambdas with captures. (public domain)
template <typename> struct fnptr;
template <typename Ret, typename... Args> struct fnptr<Ret(Args...)> {
void *obj = nullptr;
Ret (*wrap)(void*, Args...) = nullptr;
@rmitton
rmitton / toolbar.cpp
Created March 13, 2019 06:20
How to do a toolbar in Dear ImGui.
// How to do a toolbar in Dear ImGui.
const float toolbarSize = 50;
void DockSpaceUI()
{
ImGuiViewport* viewport = ImGui::GetMainViewport();
ImGui::SetNextWindowPos(viewport->Pos + ImVec2(0, toolbarSize));
ImGui::SetNextWindowSize(viewport->Size - ImVec2(0, toolbarSize));
ImGui::SetNextWindowViewport(viewport->ID);