Skip to content

Instantly share code, notes, and snippets.

I may be slow to respond.

Michael Hirsch scivision

I may be slow to respond.
View GitHub Profile
scivision / CheckTLS.cmake
Last active May 12, 2021
Check if CMake TLS is working
View CheckTLS.cmake
cmake_minimum_required(VERSION 3.20)
# some CMake may not have SSL/TLS enabled, or may have missing/broken system certificates.
# this is a publicly-usable service (as per their TOS)
cmake_path(APPEND temp ${PROJECT_BINARY_DIR} check_tls.json)
if(NOT EXISTS ${temp})
scivision /
Last active Apr 26, 2021
Extract a .zst file in Python
from pathlib import Path
import tempfile
import tarfile
import zstandard
# pip install zstandard
def extract_zst(archive: Path, out_path: Path):
"""extract .zst file
scivision / TestAll.m
Created Apr 19, 2021
Matlab with GitHub Actions CI
View TestAll.m
import matlab.unittest.TestRunner
import matlab.unittest.Verbosity
import matlab.unittest.plugins.CodeCoveragePlugin
import matlab.unittest.plugins.XMLPlugin
import matlab.unittest.plugins.codecoverage.CoberturaFormat
name = "MyProject";
suite = testsuite(name);
runner = TestRunner.withTextOutput('OutputDetail', Verbosity.Detailed);
scivision / expanduser.cmake
Last active Mar 31, 2021
Expand ~ tilde to home directory in CMake script
View expanduser.cmake
function(expanduser in outvar)
# expands ~ to user home directory
# cmake_path and file do not expand ~
# get_filename_component expands ~ in C++ similar to above
# usage:
# expanduser("~/code" x)
string(SUBSTRING ${in} 0 1 first)
scivision / extract_zstd.m
Last active Apr 20, 2021
Matlab extract .zst Zstd compressed files
View extract_zstd.m
function extract_zstd(archive, out_dir)
% extract a zstd file "archive" to "out_dir"
if ~isfile(archive)
error("%s is not a file", archive)
[ret, ~] = system("zstd -h");
if ret ~= 0
if ismac
scivision / AddGitSubmodule.cmake
Last active Mar 7, 2021
CMake: init/update a Git submodule and add_subdirectory()
View AddGitSubmodule.cmake
function(add_git_submodule dir)
# add a Git submodule directory to CMake, assuming the
# Git submodule directory is a CMake project.
# Usage: in CMakeLists.txt
# include(AddGitSubmodule.cmake)
# add_git_submodule(mysubmod_dir)
find_package(Git REQUIRED)
View .cpack_ignore
scivision / CMakeLists.txt
Last active Feb 26, 2021
GCC static exe linking
View CMakeLists.txt
cmake_minimum_required(VERSION 3.14)
project(demo Fortran)
# --- static flags avoid users needing libgfortran etc. on their Windows system
# MacOS and Linux needs more caution as true static linking is an advanced topic.
# this does not guarantee a portable executable, careful testing is needed and possibly further options
set(static_link_flags -static -static-libgfortran)
# MinGW / MSYS2 special considerations:
scivision / configure.output.mpich
Last active Feb 22, 2021
Intel oneAPI MacOS 11.x: Trying to get MPI library working (MPICH, or OpenMPI)
View configure.output.mpich
$ git clone
$ git checkout v3.4.1
$ ./configure --prefix=$HOME/mpich-3.4.1 --disable-cxx
# NOTE: if CPPFLAGS not set, configure will fail in HWLOC. There is some bug in mpich/configure that just requires CPPFLAGS.
# configure complete, but make fails instantly:
$ make
scivision / image_stack_hdf5.m
Last active Feb 18, 2021
HDF5 image stack writing, suitable for HDFView video player
View image_stack_hdf5.m
Simg = load('clown');
imgs = Simg.X;
file = 'img.h5';
name = '/img';
h5create(file, name, size(imgs))
h5write(file, name, imgs)
h5writeatt(file, name, 'CLASS', 'IMAGE')