Skip to content

Instantly share code, notes, and snippets.

@nickav
nickav / triangle.m
Created August 11, 2025 22:23
Minimal Example of a Metal Triangle using Metal and QuartzCore (no MetalKit)
//
// Build with:
// > clang -fobjc-arc triangle.m -o triangle -framework Metal -framework AppKit -framework QuartzCore
//
#import <Cocoa/Cocoa.h>
#import <Metal/Metal.h>
#import <QuartzCore/QuartzCore.h>
typedef struct {
float position[2];
@nickav
nickav / coreaudio_backend.m
Last active July 28, 2025 20:17
Audio Playback on MacOS with AudioUnit Backend
//
// Build with:
// > clang coreaudio_backend.m -o main -framework AudioUnit
//
//
// Base Types
//
#include <stdint.h>
@nickav
nickav / d3d12_textured_quad.c
Created July 27, 2025 14:28
DirectX12 Textured Quad, Vertex, Index and Constants Buffer
//
// Compile with:
// > cl /I . /D"BUILD_DEBUG=1" /D"BUILD_ARCH64=1" /D"BUILD_WIN=1" /Z7 /W4 /sdl /MT /GR- /EHa /WX /nologo /Oi /Gm- /MP d3d12_textured_quad.c /link /opt:ref /DEBUG "kernel32.lib" "user32.lib" "gdi32.lib" "d3d12.lib" "dxguid.lib" "dxgi.lib" "d3dcompiler.lib" /OUT:d3d12_textured_quad.exe
//
#pragma warning(disable:4221)
#pragma warning(disable:4204)
#pragma warning(disable:4201)
#define NOMINMAX
@nickav
nickav / keep2obsidian.js
Created June 27, 2025 20:55
Converts Google Keep exported JSON notes to Obsidian markdown files
//
// Converts Google Keep exported JSON notes to Obsidian markdown files
// Usage: node keep2obsidian.js
// Place files in a sibling directory called: `notes`
//
const fs = require('fs');
const path = require('path');
const readJSON = (filePath) => {
@nickav
nickav / spall.h
Last active April 2, 2025 22:04
Single-file spall.h to capture profiling info for a C program in clang
//
// NOTE(nick): modified version of spall.h to make it a single-file header library
//
// Usage:
#if 0
// 1) Include this in your C source:
#include "spall.h"
// 2) Call the setup functions:
int main() {
@nickav
nickav / glfw_webgpu.c
Last active February 6, 2025 15:39 — forked from mmozeiko/win32_webgpu.c
setting up and using WebGPU in C using Dawn and GLFW
//
// NOTE(nick):
//
// 1. Get Dawn:
//
// on Windows get a prebuilt copy of dawn from: https://github.com/mmozeiko/build-dawn
//
// on MacOS build from source with:
// git clone https://github.com/google/dawn
// cd dawn

Instant MSVC Command Prompt Sessions

If you do C programming on Windows you need cl.exe in your PATH.

Unfortunately, running the batch file to locate the cl.exe compiler (vcvarsall.bat) takes about ~5 seconds!

That's only a problem on new Command Prompt sessions, but if you use a program that kicks off a build step it's really annoying to have to run this before any of your build commands. But, thankfully, there's a way around this. We can create a script to inflate the same environment variables that vcvarsall.bat ultimately sets up.

As a side-effect, this is also how to have a single file to manage all of your Command Prompt environment variables in Windows.

@nickav
nickav / msdfgen.h
Created November 29, 2023 05:47
Single-file header library for MSDFgen
/*
* MULTI-CHANNEL SIGNED DISTANCE FIELD GENERATOR
* ---------------------------------------------
* A utility by Viktor Chlumsky, (c) 2014 - 2023
*
* The technique used to generate multi-channel distance fields in this code
* has been developed by Viktor Chlumsky in 2014 for his master's thesis,
* "Shape Decomposition for Multi-Channel Distance Fields". It provides improved
* quality of sharp corners in glyphs and other 2D shapes compared to monochrome
* distance fields. To reconstruct an image of the shape, apply the median of three
@nickav
nickav / hello_win32_emojis.md
Last active November 10, 2023 21:19
Win32 Colored Emoji Rendering

Win32 Colored Emoji Rendering

Uses DirectWrite and D2D to render Segoe UI Emojis

demo

@nickav
nickav / hello.c
Last active May 24, 2024 09:37
WASM from Scratch
// Types
#define NULL 0
typedef unsigned char u8;
typedef unsigned int u32;
typedef signed int i32;
typedef signed long long i64;
typedef double f64;
// Imports