Skip to content

Instantly share code, notes, and snippets.

View pastewka's full-sized avatar

Lars Pastewka pastewka

View GitHub Profile
@pastewka
pastewka / install_packages.sh
Last active January 4, 2024 09:30
Fedora packages
sudo wget -qO /etc/yum.repos.d/enpass-yum.repo https://yum.enpass.io/enpass-yum.repo
sudo wget -qO /etc/yum.repos.d/softmaker.repo https://shop.softmaker.com/repo/softmaker.repo
sudo rpm -v --import https://packages.microsoft.com/keys/microsoft.asc
sudo rpm -v --import https://download.sublimetext.com/sublimehq-rpm-pub.gpg
sudo sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo'
sudo dnf install -y dnf-plugin-config-manager fedora-workstation-repositories
sudo dnf config-manager --set-enabled google-chrome
sudo dnf config-manager --add-repo https://download.sublimetext.com/rpm/stable/x86_64/sublime-text.repo
@pastewka
pastewka / make_rough.py
Last active April 14, 2023 07:54
Generate a random, self-affine surface topography map
# Copyright (c) 2015 Lars Pastewka
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
# (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do
# so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
@pastewka
pastewka / extract_thermo.sh
Created July 16, 2017 11:38
Extract "thermo" output section from a LAMMPS log file
#! /bin/sh
cat log.lammps | sed -n "/Step/,/Loop time/p" | head -n-1 > thermo.out
@pastewka
pastewka / bluetooth.sh
Last active September 20, 2021 15:56
Automatically import bluetooth keys from Windows to Linux
#! /bin/bash
WINDOWS_ROOT=$1
cd $WINDOWS_ROOT/Windows/System32/config
# Get MAC address of Bluetooth module
for mac in /var/lib/bluetooth/??:??:??:??:??:??; do
btmacwin=$(basename ${mac} | sed 's/://g' | awk '{print tolower($0)}')
btdir=${mac}
@pastewka
pastewka / gpc.py
Last active September 14, 2021 13:16
Simple Gaussian process classification example
"""Simple Gaussian process classification example (Laplacian approximation)"""
import numpy as np
import scipy.special
import matplotlib.pyplot as plt
class ProbitLikelihood:
"""
@pastewka
pastewka / gpr.py
Last active September 14, 2021 10:02
Simple Gaussian process regression example
"""Simple Gaussian process regression example"""
import numpy as np
import matplotlib.pyplot as plt
def kernel(x1, x2, length_scale=1, signal_variance=1):
return signal_variance*np.exp(-(x1-x2)**2 / (2*length_scale**2))
@pastewka
pastewka / label_line.py
Last active May 14, 2020 21:02
Put labels on lines in matplotlib
#Label line with line2D label data
def label_line(line,x,label=None,rotation=None,**kwargs):
ax = line.axes
xdata = line.get_xdata()
ydata = line.get_ydata()
if (x < xdata[0]) or (x > xdata[-1]):
print('x label location is outside data range!')
return
@pastewka
pastewka / read_xdmf.py
Last active September 3, 2019 08:20
Simple XDMF reader
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
# (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do
# so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
@pastewka
pastewka / lammps_to_data.py
Last active April 10, 2019 14:06
Convert LAMMPS data files into NetCDF trajectory
import glob
import os
from ase.io import NetCDFTrajectory, read
fns = glob.glob('/work/ws/nemo/fr_rj1011-18.07.03-GAP_low_density-0/18.10.15-aC_GAP-quasistatic-bond_breaking_B/quasistatic-2.7_B_*.lammps')
nc = NetCDFTrajectory('quasistatic_2.7.nc', 'w')
fns = sorted(fns, key=lambda x: int(os.path.basename(x).replace('quasistatic-2.7_B_', '').replace('.lammps', '')))
for fn in fns:
Place fonts in $HOME/.fonts or other directory of choice.
Create file $HOME/.config/fontconfig/fonts.conf with following content:
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<!-- ~/.fonts.conf for per-user font configuration -->
<fontconfig>
<dir>~/.fonts</dir>
</fontconfig>