Skip to content

Instantly share code, notes, and snippets.

View jonwis's full-sized avatar

Jon Wiswall jonwis

View GitHub Profile
@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)
// This is replacement for std::format on systems that don't have std::locale support,
// but do have std::to_chars locale invariant.
template <typename... Args>
std::string myformat(std::format_string<Args...> fmt, Args&&... args)
{
std::string output;
auto formatArgStore = std::make_format_args(args...);
auto formatArgs = std::format_args(formatArgStore);
std::string_view fmtString = fmt.get();
int nextIndex = 0;
@jonwis
jonwis / bijection.h
Created January 12, 2024 21:37
Bijection support-ish?
#include <tuple>
#include <iostream>
#include <algorithm>
#include <string_view>
#include <array>
#include <stdexcept>
#include <optional>
// This is a bijection lookup helper that given an array of pairs finds the key or
// the value. The keys should be sorted.
@jonwis
jonwis / winrt_obfuscate.cpp
Last active December 20, 2023 04:25
Obfuscation from a seed number
#include <random>
#include <string>
#include <vector>
#include <span>
#include <winrt/windows.storage.streams.h>
#include <winrt/windows.security.cryptography.h>
#include <winrt/windows.security.cryptography.core.h>
#include <winrt/windows.security.cryptography.certificates.h>
namespace winrt {
@jonwis
jonwis / transmute.hxx
Created November 21, 2023 05:01
A function that transmutes any container into a vector of another type
#include <vector>
#include <algorithm>
#include <iterator>
#include <functional>
// Given a container that supports "begin(c)" / "end(c)", uses std::transform plus a
// provided transmutor function to produce an output vector of the results. The
// type of the vector returned is derived from the return type of the transmutor
// operation.
template<typename Z, typename Q>
@jonwis
jonwis / enum_iter.hxx
Created November 19, 2023 07:15
Yet another enum iterator attempt
#include <wil/com.h>
// Wraps a type like IEnumIUknown and exposes it as a forward iterator,
// or like IEnumIDList and exposes it as a forward iterator of type TStoredType.
// The IEnumType must have the following methods:
// HRESULT Next(ULONG celt, T* rgelt, ULONG* pceltFetched)
template <typename IEnumType, typename TStoredType>
struct iterator
{
wil::com_ptr<IEnumType> m_enum{};