Skip to content

Instantly share code, notes, and snippets.

View halvarsu's full-sized avatar
🚅

Halvard Sutterud halvarsu

🚅
View GitHub Profile
@halvarsu
halvarsu / Fooling_with_with.ipynb
Last active December 14, 2020 17:53
Testing with statements in python
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@halvarsu
halvarsu / random_color.py
Created October 13, 2020 15:56
sets random base16-colorschemes until user is happy
import os
import subprocess
import random
def new_color():
base16_shell = os.environ['BASE16_SHELL']
proc = subprocess.run(['ls', '{}/scripts'.format(base16_shell)], capture_output=True)
out = proc.stdout.split()
cmd = random.choice(out).decode('utf-8').split('.sh')[0].replace('-','_',1)
@halvarsu
halvarsu / Rotate touchpad
Created May 19, 2020 09:29
Use rotation matrix to rotate the touchpad input, to allow for sensible hand positions
#!/bin/zsh
zmodload zsh/mathfunc
theta=${1:-0}
# Check if input is a number, from [1]
re='^[+-]?[0-9]+([.][0-9]+)?$'
if ! [[ $theta =~ $re ]] ; then
echo "error: Usage: $ rotate_touchpad.sh [number]" >&2; exit 1
@halvarsu
halvarsu / zathura_backward_search.sh
Created May 4, 2020 18:51
Move mouse cursor to (the right of) center of screen and ctrl click.
#!/bin/bash
ACTIVEWINDOW=$(xdotool getactivewindow)
eval $(xdotool getwindowgeometry --shell $ACTIVEWINDOW)
HALF_WIDTH="$(($WIDTH / 2 + 10))"
HALF_HEIGHT="$(($HEIGHT / 2))"
xdotool mousemove --window $ACTIVEWINDOW $HALF_WIDTH $HALF_HEIGHT keydown ctrl click 1 keyup ctrl
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import numpy as np
import matplotlib.pyplot as plt
from scipy.constants import physical_constants
from uncertainties import ufloat as uncfloat
uMeV = physical_constants['atomic mass constant energy equivalent in MeV'][0]
un = uncfloat(1008664.91582, 0.00049) * 1e-6 # in atomic mass units
u1H = uncfloat(1007825.03224, 0.00009) * 1e-6
u2H = uncfloat(2014101.77811, 0.00012) * 1e-6
u3He = uncfloat(3016029.32265, 0.00022) * 1e-6
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.