Skip to content

Instantly share code, notes, and snippets.

View larsbratholm's full-sized avatar

Lars Andersen Bratholm larsbratholm

View GitHub Profile
@larsbratholm
larsbratholm / lol.py
Last active May 10, 2016 19:53
for else example
for i in range(5):
for j in range(3):
if i == 2 and j == 1:
break
else:
continue
break
@larsbratholm
larsbratholm / const.py
Last active June 12, 2016 17:35
const example
# const decorator
def const(f):
def fset(self, value):
raise TypeError
def fget(self):
return f(self)
return property(fget, fset)
# example with class
class Data(object):
@larsbratholm
larsbratholm / .i3status.conf
Created September 24, 2016 14:49
Charge monitoring for dual batteries in e.g. i3 status bar
# i3status configuration file.
order += "battery 2"
battery 2 {
integer_battery_capacity = true
last_full_capacity = true
path = "/home/lab/.uevent"
format = "%status %percentage %remaining"
}
@larsbratholm
larsbratholm / flightmode.sh
Created September 24, 2016 15:00
Enable/disable flightmode
#!/usr/bin/env bash
if [ "${1,,}" = "on" ] || [ "${1,,}" = "enable" ] || [ "${1,,}" = "1" ]; then
arg=0
elif [ "${1,,}" = "off" ] || [ "${1,,}" = "disable" ] || [ "${1,,}" = "0" ]; then
arg=1
else echo "Unknown argument: $1"; exit 1
fi
nmcli r all $arg
@larsbratholm
larsbratholm / config
Created September 24, 2016 15:04
Keyboard issue fix on T450s
# i3 config file (v4)
# Disable and re-enable keyboard
exec (~/bin/keyboard.sh disable;sleep 1;~/bin/keyboard.sh enable)
@larsbratholm
larsbratholm / nosleep
Created September 24, 2016 17:05
deactivate sleepmode on lid close
#!/usr/bin/env bash
# As far as I remember only disables sleep until the terminal where this is run is closed.
systemd-inhibit --what=handle-lid-switch sleep 1d
@larsbratholm
larsbratholm / wget_dir
Created January 9, 2017 14:28
wget a directory
#!/bin/bash
# remove http:// etc
SUBSTRING=$(cut -d. -f2- <<< "$1")
# remove last slash if present
if [ "${SUBSTRING: -1}" = "/" ];then
SUBSTRING="${SUBSTRING%?}"
fi
# count subdirectories
NCUT=$(grep -o "/" <<< "$SUBSTRING" | wc -l)
@larsbratholm
larsbratholm / properties.py
Created March 14, 2017 14:05
Bruteforce matrix function relationships
from sympy import *
import itertools
def M(a, f1, f2, f3, f4):
a1, a2, a3, a4 = a.values()
M1 = f1 * Matrix([[0,-a3, a2,0],[a3, 0, -a1,0],[-a2, a1, 0,0],[0,0,0,0]])
M2 = f2 * Matrix([[0,0, 0,0],[0, 0, 0,0],[0, 0, 0,0],[a1,a2,a3,0]])
M3 = f3 * Matrix([[0,0, 0,a1],[0, 0, 0,a2],[0, 0, 0,a3],[0,0,0,0]])
M4 = f4 * a4 * eye(4)
from sympy import *
import itertools
def do_replacement(expr):
queue = [expr]
permutations = []
while len(queue) > 0:
next_queue = []
import numpy as np
def make_exclusionlist(fragment, capped, max_length, ignore_capping_hydrogens = True):
# is this int? - else change
frag_serials = np.asarray(fragment.serials, dtype=int)
valid_capped_fragments = np.fromiter((frag for frag in capped if capfrag.ignore == False), int)
valid_capped_fragment_serials = [[serial for serial, name in zip(capfrag.serials, capfrag.names) if (ignore_capping_hydrogens and name != " H* ")] for capfrag in valid_capped_fragments]
# are serials unique? - else change
matches = (np.intersect1d(fragment.serials, cap_serials, assume_unique = True) for cap_serials in valid_capped_fragment_serials)