Skip to content

Instantly share code, notes, and snippets.

View Roninkoi's full-sized avatar
🐲

Roninkoi Roninkoi

🐲
View GitHub Profile
@Roninkoi
Roninkoi / vtkToObj.py
Last active October 24, 2024 06:04
Convert vtkUnstructuredGrid VTK file to Wavefront OBJ file or STL file
#!/bin/env python3
# Convert vtkUnstructuredGrid VTK file to Wavefront OBJ file or STL file
import sys
import os
import vtk
if len(sys.argv) != 3:
print('Usage: ', sys.argv[0], 'in.vtk out.obj')
sys.exit()
@Roninkoi
Roninkoi / buildgcc.sh
Created April 3, 2024 08:33
Build GCC from Git
#!/bin/sh
# clone and build gcc for linux, link bin
gccpath="/home/ronialek/gcc-test"
mkdir $gccpath
cd $gccpath
git clone git://gcc.gnu.org/git/gcc.git .
git checkout releases/gcc-13
./contrib/download_prerequisites
mkdir build
cd build
@Roninkoi
Roninkoi / extract_last.py
Created May 9, 2023 08:44
Extract last frame of LAMMPS xyz file
#!/bin/env python3
# Extract last frame from LAMMPS xyz dump file
# inpath and write it to outpath
inpath = "AgNWSiO2.xyz"
outpath = "data.AgNWSiO2"
df = open(inpath, "r")
buf = []
i = 0
for l in df:
@Roninkoi
Roninkoi / filehex.sh
Last active February 28, 2023 21:33
Write hexadecimal byte contents to multiple files. The file files.txt has rows in the format <filename> <hexadecimal number ffff...>
#!/bin/sh
##xargs -a files.txt -n2 sh -c '(echo "16i $(echo $1 | tr '[:lower:]' '[:upper:]') P" | dc) > $0'
xargs -a files.txt -n2 sh -c 'echo $1 | xxd -r -p - $0'
@Roninkoi
Roninkoi / plot.py
Last active November 24, 2022 16:40
My Python plotting scripts
# Roni Koitermaa 2022
# Plotting code using Matplotlib
# Line/scatter plots, subplots, histogram plot, bar plot
import numpy as np
from matplotlib import rc
import matplotlib.pyplot as plt
import matplotlib.ticker as mtick
# line + scatter plot of multiple data sets a
@Roninkoi
Roninkoi / mkvsubs.sh
Last active October 31, 2022 15:43
Change default audio and subtitle track in mkv files
#!/bin/sh
# set audio and subtitle track 2 as default in mkv files (typically japanese with english subtitles)
for file in *.mkv ; do
mkvpropedit "$file" --edit track:a1 --set flag-default=0 --set flag-forced=0 \
--edit track:a2 --set flag-default=1 --set flag-forced=0 \
--edit track:s1 --set flag-default=0 --set flag-forced=0 \
--edit track:s2 --set flag-default=1 --set flag-forced=0
done
@Roninkoi
Roninkoi / tsdl.sh
Created August 5, 2022 00:21
Download series of .ts files from a web video stream and concatenate into mp4
#!/bin/sh
# Download series .ts files and concatenate into mp4 using ffmpeg
# Usage: tsdl <url> <file prefix i.e. prefix_0.ts>
if [ $# != 2 ]; then
echo "Usage: tsdl <url> <file prefix i.e. prefix_0.ts>"
exit
fi
echo "ffconcat version 1.0" > tsdl_list.txt
@Roninkoi
Roninkoi / pianohammers.py
Created September 28, 2021 05:32
Fourier analysis of piano hammer shapes and positions where they hit the string
# Fourier analysis of piano hammer shapes on string.
# Hammers of different shapes hit piano string at different points,
# what is the frequency spectrum?
import numpy as np
import matplotlib.pyplot as plt
# line + scatter plot of multiple data sets a
def linescatter(a, titles=["", "", ""], labels=[], styles=[], fpath="", cm=plt.cm.rainbow):
f = plt.figure(figsize=(10, 10))
@Roninkoi
Roninkoi / particleinbox.py
Last active May 28, 2021 02:33
Solve particle-in-a-box problem
import numpy as np
import matplotlib.pyplot as plt
# line + scatter plot of multiple data sets a
def linescatter(a, titles=["", "", ""], labels=[], styles=[], fpath=""):
f = plt.figure(figsize=(10, 10))
plt.rcParams.update({'font.size': 22})
colors = plt.cm.plasma(np.linspace(0, 1, len(a)))
plt.rcParams['axes.prop_cycle'] = plt.cycler(color=colors)
@Roninkoi
Roninkoi / mcplane.py
Created November 25, 2020 14:52
Plane boarding time Monte Carlo simulation
import numpy as np
class Passenger:
walkspd = 0.5 # walking speed
storespd = 30 # luggage storing speed
swapspd = 15 # seat swapping speed
def __init__(self, aislerow, seatrow, seatcol):
self.x = 0 # at gate
self.aislerow = int(aislerow)