Skip to content

Instantly share code, notes, and snippets.

View scivision's full-sized avatar
💭
I will be slow to respond.

scivision

💭
I will be slow to respond.
View GitHub Profile
@scivision
scivision / setup_apt-get_requirements.py
Last active April 22, 2021 19:41
Python setup.py that installs requirements.txt using apt-get install (useful for ARM systems like Raspberry Pi and Beaglebone without Anaconda Python)
#!/usr/bin/env python
from setuptools import setup
import subprocess
import sys,os
with open('requirements.txt', 'r') as f:
req = f.read().split('\n')
req = [os.path.basename(sys.executable) + '-' + r for r in req if r]
try:
@scivision
scivision / hw.c
Created June 1, 2021 21:20
Detect Mac ARM64 CPUs
// build like:
// clang hw.c -framework Foundation -framework IOKit
// ./a.out then gives with an M1 Apple Silicon CPU:
//
// cpu0@0(E): apple,icestorm
// cpu1@0(E): apple,icestorm
// cpu2@0(E): apple,icestorm
// cpu3@0(E): apple,icestorm
// cpu4@1(P): apple,firestorm
// cpu5@1(P): apple,firestorm
@scivision
scivision / meson.build
Created September 10, 2021 00:10
Meson build download and extract file
run_command('python', 'meson_file_download.py', url, zipfn, '-hash', 'md5', md5hash, check: true)
run_command('python', 'meson_file_extract.py', zipfn, outpath, check: true)
@scivision
scivision / .gitattributes
Last active September 25, 2021 14:51
End CRLF line ending hell for Windows + Cygwin or WSL and any other OS https://www.scivision.dev/git-line-endings-windows-cygwin-wsl/
.gitattributes text eol=lf
.gitignore text eol=lf
*.build text eol=lf
*.c text eol=lf
*.cmake text eol=lf
*.cpp text eol=lf
*.csv text eol=lf
*.f text eol=lf
*.f90 text eol=lf
*.for text eol=lf
@scivision
scivision / mingw_octave_path.m
Created October 22, 2021 00:39
Windows Octave using MinGW executables needs MinGW on PATH
function prepend = mingw_octave_path()
% for Octave on Windows, it's necessary to prepend MinGW path
% when running MinGW-compiled executables
% Also, Matlab with Parallel Toolbox MPIEXEC conflicts with system MPIEXEC,
% so excise from Path
%
% a command is then run like
%
% system([prepend, ' ', 'foo.exe'])
@scivision
scivision / CMakeLists.txt
Created October 24, 2021 20:48
CMake CTest ENVIRONMENT_MODIFICATION test property
cmake_minimum_required(VERSION 3.22)
project(envPrint LANGUAGES NONE)
enable_testing()
add_test(NAME PrintEnv COMMAND ${CMAKE_COMMAND} -E environment)
set_tests_properties(PrintEnv PROPERTIES
ENVIRONMENT_MODIFICATION "NotExistingVar=path_list_prepend:WillSegfault")
@scivision
scivision / find_compiler.cmake
Created June 13, 2022 20:00
CMake compiler hinting--not normally needed
# this must be include() before CMakeLists.txt project()
# --- Help CMake find matching compilers
function(find_fortran)
if(NOT DEFINED FC AND DEFINED ENV{FC})
set(FC $ENV{FC})
endif()
@scivision
scivision / ctest_once_only.cmake
Last active August 2, 2022 19:42
Detect if CTest already running, to avoid unwanted concurrent CTest/CDash runs
function(ctest_once_only)
# check if CTest already running, error if so
if(WIN32)
find_program(tasklist NAMES tasklist REQUIRED)
execute_process(COMMAND ${tasklist} /fi "Imagename eq ctest.exe" /fo csv
TIMEOUT 10
RESULT_VARIABLE ret
OUTPUT_VARIABLE out
OUTPUT_STRIP_TRAILING_WHITESPACE
@scivision
scivision / find_fortran.cmake
Created August 7, 2022 14:33
CMake include before for Fortran compiler
# Find and hint Fortran compiler via ENV{FC}.
# ENV{FC} is picked up by project().
# This is needed for CI GitHub Actions,
# which purposely doesn't have an alias for "gfortran"
include_guard(GLOBAL)
if(DEFINED ENV{CI})
set(CI $ENV{CI})
endif()
@scivision
scivision / bison.cmake
Created September 29, 2022 15:38
CMake hint MacOS homebrew Bison
# CMake projects may not find Homebrew's newer Bison since MacOS has an old Bison on PATH.
# this CMake script emits the location of Homebrew's Bison if available.
#
# brew install bison
function(bison_homebrew)
find_program(brew NAMES brew)
if(NOT brew)
return()