Skip to content

Instantly share code, notes, and snippets.

@reox
reox / setdatetime.sh
Created August 8, 2016 16:45
Set the Time on a Canon Camera with gphoto2
# This is very simple but I always forget it...
gphoto2 --set-config datetime=$(date +%s)
@reox
reox / pfilter.py
Created May 3, 2022 09:49
Paraview: Programmable Filter to display the CellType of unstructured grids
# This programmable filter can be used on an unstructured grid to display the
# numerical value of the cell type (i.e., tet, hex, wedge, ...)
output.CellData.append(inputs[0].CellTypes, 'Cell_type')
@reox
reox / stiffness.py
Last active March 22, 2022 13:50
Fun with stiffness matrices: Voigt-Reuss-Hill averages and plotting Young's modulus
"""
Fun with stiffness matrices!
The plotting routine is inspired by https://github.com/coudertlab/elate
The Voigt-Reuss-Hill Averaging was directly copied from there.
Note the following relationships of stresses and strains:
sigma_ij ... stress tensor
epsilon_ij ... strain tensor
@reox
reox / savefig_tiff_lzw.py
Created March 17, 2022 10:40
Save a figure as tiff with lzw compression
import matplotlib.pyplot as plt
# do plotting:
#plt.dosomething(...)
# pil_kwargs can be used to pass things to PIL.
# the save function has **params which then passes the kwargs to the file format save function, for example:
# See https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#saving-tiff-images
# LZW compression is called tiff_lzw in pil...
plt.savefig('foobaz.tiff', pad_inches=0.05, bbox_inches='tight', pil_kwargs=dict(compression='tiff_lzw'))
[
{
"ColorSpace": "RGB",
"DefaultMap": true,
"Name": "Turbo",
"RGBPoints": [
0.0,
0.18823529411764706,
0.07058823529411765,
0.23137254901960785,
@reox
reox / bend_tube.scad
Last active June 2, 2021 18:52
Create a bend tube in OpenSCAD. Work ONLY with openscad >=2016, as the angle parameter in rotate_extrude was introduced there.
// fine mesh
fn = 1000;
// epsilon for clean intersection
eps = 0.1;
module tube(inner=5, outer=10, angle=45, length=250){
// we want the thing in z direction, thus we rotate on x axis
@reox
reox / faces_of_array.py
Created May 20, 2021 12:41
Query the faces of a cubical image in numpy
import numpy as np
# Numpy array is xyz
img = np.zeros((10,20,30))
a = slice(None) # all items, same as ':'
faces = {
'top': (-1, a, a),
'bottom': (0, a, a),
@reox
reox / eigen.py
Created August 5, 2020 08:34
Eigenvalues and -vectors of matrix and getting matrix back in numpy
import numpy as np
A = np.array([[2,1,2.5], [1,3,1], [2.5,1,4]])
# Eigenvalues and -vectors have the property such that: Ax = lx
# x ... Eigenvectors
# l ... Eigenvalues
l, x = np.linalg.eig(A)
# it follows:
@reox
reox / freecad_daily_build.sh
Last active March 19, 2019 01:41
Build a debian package from FreeCAD yourself.
#!/bin/bash
set -e
#################################
# NOTE:
# This assumes you have a user `builder` and a folder `/home/builder/packages`.
# it will clone FreeCAD there and start pbuilder using pdebuild.
# For me this works using debian sid. (stretch/buster will probably not work!)
#
# After the build has finished, it will import the packes into a reprepro
# which is setup at /srv/repo
@reox
reox / new_debian_kvm.sh
Last active March 31, 2018 20:17
Create a new Debian container for KVM and import it using virt-install
#!/bin/bash
set -e
# Name of the VM
IMAGE=some-fancy-name
# IP address for VM
IP="192.168.122.30"
MIRROR=http://mirror.hetzner.de/debian/packages
PACKAGES="openssh-server htop vim"