Skip to content

Instantly share code, notes, and snippets.

@eliemichel
eliemichel / TinyTimer.h
Last active April 17, 2025 15:32
A simple C++ timer library
/**
* A simple timer library, with a thread-safe sample accumulator.
*
* Basic usage:
* using TinyTimer::Timer;
* Timer timer;
* // .. do something
* cout << "Something took " << timer.elapsed() << " seconds" << endl;
*
* One can also consolidate several timings to measure standard deviation:
import bpy
class IconPanel(bpy.types.Panel):
"""Creates a Panel width all possible icons"""
bl_label = "Icons"
bl_idname = "icons_panel"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "object"
@eliemichel
eliemichel / StructuredAccessorFactory.js
Last active November 14, 2024 01:34
Javascript view builder to interpret raw ArrayBuffer data as structured data
// Javascript view builder to interpret raw ArrayBuffer data as structured data.
// Copyright 2024 (c) Élie Michel - MIT Licensed
// NB: This is loosly inspired by https://github.com/kainino0x/structured-accessor
const kTypedArrayConstructors = {
i8: Int8Array,
u8: Uint8Array,
i16: Int16Array,
u16: Uint16Array,
i32: Int32Array,
@eliemichel
eliemichel / extract_marmoset_archive.py
Last active October 21, 2024 14:32
Extract the items contained in a Marmoset Viewer's .mview archive file
import struct
import os
# Parameter
archive = "vivfox.mview"
def readCString(f):
"""This is the most naive implementation possible, don't use in prod"""
str = ""
c = f.read(1)
@eliemichel
eliemichel / git_resolve.py
Last active September 9, 2024 14:20
Resolve conflicted areas of a file in favor of theirs or ours and leave correctly merged areas as is
# This is an automation of https://stackoverflow.com/questions/71783590/git-merge-strategy-option-theirs-for-individual-files
# Example:
# git_resolve.py --theirs path/to/some/file
import os
import argparse
from shutil import copyfile
import subprocess
parser = argparse.ArgumentParser(description='Resolve conflicted areas of a file during a git merge')
@eliemichel
eliemichel / marmoset.js
Created March 1, 2019 22:46
Marmoset viewer embedded code, as is
/*
(Built: Mon, Sep 24, 2018 4:38:25 PM)
Marmoset Viewer Code and Tools
Copyright (c) 2018 Marmoset LLC.
All rights reserved.
Redistribution and use of this software are permitted provided
that the software remains whole and unmodified and this copyright
notice remains attached. Use or inclusion of any portion of this
@eliemichel
eliemichel / packHalf2x16.py
Created December 29, 2023 01:20
An efficient numpy implementation of GLSL packHalf2x16 and unpackHalf2x16
"""
An efficient numpy implementation of GLSL packHalf2x16 and unpackHalf2x16.
Author: Elie Michel <elie.michel@exppad.com>
License: MIT - 2023
"""
def packHalf2x16(x, y):
"""
Pack two floats into a single uint32, like GLSL's packHalf2x16 function
(but vectorized for numpy arrays).
@eliemichel
eliemichel / list_marmoset_archive.py
Last active December 14, 2023 08:05
List the items contained in a Marmoset Viewer's .mview archive file
import struct
def readCString(f):
"""This is the most naive implementation possible, don't use in prod"""
str = ""
c = f.read(1)
while c != '\0':
str += c
c = f.read(1)
return str
@eliemichel
eliemichel / save_texture.h
Last active July 2, 2023 13:46
A single-header utility file to save a given WebGPU Texture MIP level into an image
#include "stb_image_write.h"
#include <webgpu/webgpu.hpp>
#include <filesystem>
#include <string>
bool saveTexture(const std::filesystem::path path, wgpu::Device device, wgpu::Texture texture, int mipLevel) {
using namespace wgpu;
@eliemichel
eliemichel / webgpu-raii.h
Created May 14, 2023 10:58
An example of RAII wrapper for WebGPU's wgpu::Buffer
// Using https://github.com/eliemichel/WebGPU-Cpp
#include <webgpu/webgpu.hpp>
namespace raii {
class Buffer {
public:
// Whenever a RAII instance is created, we create an underlying resource
Buffer(wgpu::Device device, const wgpu::BufferDescriptor& bufferDesc)
: m_raw(device.createBuffer(bufferDesc))
{}