Skip to content

Instantly share code, notes, and snippets.

@mhalle
mhalle / torchfree_pth.py
Created May 27, 2026 12:19
Torch-free loader for PyTorch .pth checkpoints (numpy only, restricted unpickler). Drop-in for torch.load(weights_only=False) on legacy nnUNet/TotalSegmentator checkpoints.
"""Torch-free loader for PyTorch ``.pth`` checkpoints.
Single-file module, ``numpy`` as the only dependency.
Reads the modern zip-format ``.pth`` (PyTorch >= 1.6) into nested
dict/list/OrderedDict with ``numpy.ndarray`` leaves, using a restricted
unpickler whose ``find_class`` only permits the symbols a weights checkpoint
actually uses.
Why this exists

Python Dependency Management for 3D Slicer Using UV


Executive Summary

The Problem

3D Slicer extensions currently install Python dependencies at runtime using ad-hoc pip_install() calls. This causes:

  • Environment corruption: Extensions can break each other or Slicer itself by installing incompatible packages
# /// script
# requires-python = ">=3.9"
# dependencies = [
# "requests>=2.31.0", # For fetching the sitemap and content
# "sqlite-utils>=3.35.2", # For database operations
# "urllib3>=2.0.7", # Required by requests
# "beautifulsoup4>=4.12.0", # For parsing HTML content
# ]
# ///

vtkSurfaceNets3D

Overview

vtkSurfaceNets3D is a VTK filter that generates smooth boundary surfaces from segmented 3D image data (label maps) using the Surface Nets algorithm. It is particularly well-suited for extracting boundaries between multiple labeled regions in volumetric data while maintaining shared boundaries and producing high-quality surface meshes.

Key Features

  • Extracts smooth boundary surfaces from label maps (segmented volumes)
  • Handles multiple labels/regions simultaneously in a single pass
name: Test BigQuery Query
publicationDate: 2023-07-01
version: 1.0
creator:
- name: Michael Halle
affiliation: Brigham and Women's Hospital
email: m@halle.us
identifier: https://orcid.org/0000-0002-1825-0097
@mhalle
mhalle / 0_reuse_code.js
Last active August 29, 2015 14:27
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@mhalle
mhalle / .gitignore
Created November 27, 2012 07:00
Event test
*~
@mhalle
mhalle / ffi-string-null
Created September 16, 2011 04:45
demonstration of node-ffi null termination bug
var FFI = require('node-ffi');
var basePtr = new FFI.Pointer(128);
var ptr = basePtr.seek(0);
ptr.putCString('one', true);
console.log('Writing string "one" to buffer and advancing pointer.');
console.log('The trailing null is written so that the string is valid.');
console.log(ptr.address - basePtr.address + ' (new pointer position is 3, not 4 bytes offset)');