Skip to content

Instantly share code, notes, and snippets.

View mgbckr's full-sized avatar

Martin Becker mgbckr

View GitHub Profile
@mgbckr
mgbckr / IntegerValueOf
Created August 2, 2012 21:04
Always be careful to compare Objects using Object.equals(Object): Integer.valueOf(int) caches common values.
import junit.framework.Assert;
import org.junit.Test;
public class IntegerValueOf {
@Test
public void test() {
@mgbckr
mgbckr / AccessFileOnClasspath
Last active July 14, 2018 12:55
Resource access in Maven projects.
/**
* <p>Shows how files in the class path can be accessed when using the standard
* Maven directory layout.</p>
*
* <p>The test file is "src/test/resources/accessFileOnClasspath/test.txt".
* It is accessed using either {@link ClassLoader#getResource(String)} or
* {@link ClassLoader#getResourceAsStream(String)}. Note that the file's
* path is always relative to the class path's root. Thus the test file is
* accessed using "accessFileOnClasspath/test.txt".</p>
*
#!/bin/bash
# A small script for labelling music files (mp3) with their BPMs via filename.
#
# requires
# * bpm-tools
# * libsox-fmt-mp3
#
# usage:
#
# # get BPM of a file labels
@mgbckr
mgbckr / rpi3led.py
Last active June 1, 2017 08:14
Python 2 class for blinking the onboard ACT LED on the Raspberry PI 3
#/usr/bin/python -p
import time
import subprocess
import threading
"""
This is a class for blinking the onboard ACT LED on the Raspberry PI 3 based on
shell commands. There should be a way to do this via GPIO, but for me it did not
work so far. Here are some relevant links for blinking via GPIO:
* https://kofler.info/on-board-leds-des-raspberry-pi-steuern/
#!/bin/bash
#
# colorpages_printstring.bash
#
# Tool to print only color pages from a PDF (duplex).
# Generates a string to be used for common printing dialogs which only contains pages (back and front) with color.
#
# usage: colorpages_printstring <your>.pdf
#
# requirements: ghostscript (gs)
@mgbckr
mgbckr / extract_hr_from_polar_csv.py
Created March 2, 2018 11:29
A little function to extract heart rates with absolute timestamps from Polar CSV files
def extract_hr_from_polar_csv(filename):
# read header and data
h = pd.read_csv(filename, nrows=2)
d = pd.read_csv(filename, skiprows=2)
# parse start time
datetime_string = h["Date"].values[0] + " " + h["Start time"].values[0]
starttime = datetime.strptime(datetime_string, '%d-%m-%Y %H:%M:%S')
@mgbckr
mgbckr / pull_database_from_android.bash
Last active March 2, 2018 13:48
Small set of commands to download a database file (or any file) from an android device using `adb`
./adb shell
run-as the.package.of.the.application
cd /data/data/dthe.package.of.the.application/databases
chmod 777 TheDatabase.db
cp TheDatabase.db /mnt/sdcard/
./adb pull /mnt/sdcard/TheDatabase.db
@mgbckr
mgbckr / plot_multiple_axes.py
Created May 2, 2018 09:21
A helper function to plot data with multiple axes using Python's matplotlib. Adjust to your needs. Obviously needs some clean up.
def plot_multiple_axes(data, columns, x= "timestamp", colors=["black", "r-", "g-", "c-", "m-", "y-"], window=60):
"""
TODO: Needs some clean up
:type data: pandas.DataFrame
:type columns: list of str
"""
fig, host = plt.subplots(figsize=(20, 4))
axes = [host] + [host.twinx() for c in range(1, len(columns))]
import numpy as np
from sklearn import svm
import sklearn as sk
def exp(majority_vote=False, n=1000):
# data
y = np.array([1,2] * 14)
x = np.random.rand(len(y), 100)
@mgbckr
mgbckr / utop.sh
Created December 17, 2018 17:15
Script to show CPU usage (percent) by user
#!/bin/bash
# start with `watch -n 1 bash utop.sh` for continuous monitoring
top -b -n 1 | awk '
NR <= 7 { print; next }
{ a[$2] += $9 }
END {
for (i in a) {
printf "%-15s\t%s\n", i, a[i];
}
}