Skip to content

Instantly share code, notes, and snippets.

@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
@nickav
nickav / ReadDirectoryChangesW_craziness.cpp
Last active December 17, 2024 08:39
Example of how to poll ReadDirectoryChangesW on Windows
int main() {
char *path = "/path/to/my/directory";
print("watching %s for changes...\n", path);
HANDLE file = CreateFile(path,
FILE_LIST_DIRECTORY,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
NULL,
OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED,

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 / 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
@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 / defer.cpp
Created July 14, 2023 15:18
defer macro thing
#ifndef defer
// Defer macro/thing.
template<typename T>
struct ExitScope {
T lambda;
ExitScope(T lambda) : lambda(lambda) {}
~ExitScope() { lambda(); }
ExitScope(const ExitScope&);
private:
ExitScope& operator =(const ExitScope&);
@nickav
nickav / LightningLinks.js
Last active May 24, 2023 23:25
Definitely not a cheap knock-off of Turbolinks
@nickav
nickav / better-fetch.js
Created February 17, 2023 23:11
A nice wrapper around the browser's kind of broken fetch API
const handleFetchResponse = (resp) => {
return resp.text().then((text) => {
let data = text;
const contentType = resp.headers.get("content-type");
const isJSON = contentType && contentType.indexOf("application/json") >= 0;
if (isJSON)
{
try {
data = JSON.parse(text);
<!doctype html>
<html>
<head>
<meta charset=utf-8>
<meta name="viewport" content="minimal-ui, width=device-width, height=device-height, initial-scale=1, maximum-scale=1, user-scalable=no, viewport-fit=cover">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<title></title>
<meta name="description" content="">