Skip to content

Instantly share code, notes, and snippets.

@jonwis
jonwis / user_defined_things.h
Created April 7, 2026 06:49
SIDs as user defined literals
#include <cstdint>
#include <string_view>
#include <algorithm>
#include <ranges>
#include <array>
template<size_t N>
struct string_literal
{
std::array<wchar_t, N> arr_{};
@jonwis
jonwis / thing_caller.cpp
Created December 3, 2025 17:20
Sample Try... pattern like HttpClient
// C++ caller
void DownloadTheThing(Thing const& thing) {
auto op { thing.DownloadAsync(L"arg1", L"arg2") };
op.Progress([](auto const &pending, uint32_t progress) {
// Handle progress update
wprintf(L"Download progress: %u%%\n", progress);
});
var result = op.get(); // Await completion
if (result.StatusIsSuccess) {
// use result.Result
@jonwis
jonwis / Copilot Prompts.md
Last active October 16, 2025 22:09
Getting NV12 plane data out of a WinRT IDirect3DSurface

Get data

I have a Windows.Graphics.DirectX.Direct3D11.IDirect3DSurface - how do I get a pointer to the graphics data to operate on? Write a C++/winrt sample if you can.

Get NV12

OK, next up, split the locked bytes into a std::vector<> of NV12 plane definitions.

@jonwis
jonwis / wil_thread_buckets.hxx
Created August 24, 2025 18:32
Per-thread bucket storage
#include <wil/wistd_type_traits.h>
#include <wil/resource.h>
template<typename Q> struct bucketed_hash
{
struct entry
{
uint32_t thread_id;
wil::unique_process_heap_ptr<entry> next;
Q value;
@jonwis
jonwis / find_bad_use_of_ref_params.md
Created June 14, 2025 20:44
Copilot-generated CodeQL query

Question

Write a CodeQL query that finds coroutine methods that take parameters by reference, where those parameters are used after any co_await suspension point.

Response

import cpp
@jonwis
jonwis / deploy_wasdk.py
Created March 17, 2025 06:13
Deploy WASDK with python
import os
import sys
import subprocess
import urllib.request
import argparse
from pathlib import Path
wasdk = {
"name": "Microsoft.WindowsAppSDK",
"version": "1.7.250127003-experimental3",
@jonwis
jonwis / sample_header.hxx
Created December 9, 2024 20:02
A model for free-threaded properties in a C++/WinRT Object
#include <winrt/base.h>
/* Assume this type:
runtimeclass Foo {
String Name;
UInt32 Id { get; };
Foo[] GetMoreFoos();
}
@jonwis
jonwis / test_lookups.cpp
Created December 9, 2024 07:29
Vector map unordered set test
// ConsoleApplication1.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <map>
#include <chrono>
#include <unordered_map>
#include <array>
#include <string>
#include <functional>
@jonwis
jonwis / std_lazy.h
Created November 23, 2024 07:52
Lazy C++ type suggestion
// https://godbolt.org/z/xnd359j99
#include <optional>
#include <mutex>
#include <functional>
template<typename T> struct default_lazy_init {
T operator()() const {
return T{};
}
#include <vector>
#include <span>
#include <variant>
#include <memory>
template<typename T, int internal = 25> struct small_vector_optimization : std::span<T const>
{
small_vector_optimization(std::span<T const> src)
{
if (src.size() <= internal)