Skip to content

Instantly share code, notes, and snippets.

@ahue
ahue / install-influxdb-grafana.sh
Created February 5, 2021 19:59
Grafana and Influx-DB Install for Raspberry Pi 3
#!/bin/bash
# Create InfluxDB and Grafana 4.4.3 (latest)
source /etc/os-release
OPSYS=${ID^^}
curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add -
test $VERSION_ID = "8" && echo "deb https://repos.influxdata.com/debian jessie stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
test $VERSION_ID = "9" && echo "deb https://repos.influxdata.com/debian jessie stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
curl https://bintray.com/user/downloadSubjectPublicKey?username=bintray | sudo apt-key add -
@ahue
ahue / openhab2backup.sh
Created February 5, 2021 20:01
Openhab2 Backup Script
#!/bin/bash
# create new folder for the day
DATE=`date +%Y-%m-%d_%H-%M-%S`
BACKUP_PATH=~/openhab2-backup
# backup metadata in ./meta
mkdir -p $BACKUP_PATH
sh /usr/share/openhab2/runtime/bin/backup $BACKUP_PATH/openhab2-backup-$DATE.zip
@ahue
ahue / groceries_wiktionary
Last active July 19, 2021 14:57
rhasspy slot program to get german groceries from wiktionary into rhasspy
#! /usr/bin/python3
try:
# For Python 3.0 and later
from urllib.request import urlopen
from urllib.parse import quote
except ImportError:
# Fall back to Python 2's urllib2
from urllib2 import urlopen
from urllib2 import quote
@ahue
ahue / groceries_bring
Created February 14, 2021 07:43
A slot-program for retrieve German grocery terms for Rhasspy
#!/usr/bin/env bash
set -e
url="https://web.getbring.com/locale/articles.de-DE.json"
echo "GET ${url}" >&2
curl -X GET \
-H 'Content-Type: application/json' \
"${url}" | \
jq --raw-output 'to_entries[] as $e | "\($e.value)"' | \
from typing import Union
def scale(x: Union[int|float],
min_x: Union[int|float], max_x: Union[int|float],
a: Union[int|float], b: Union[int|float]) -> float:
"""
Scale a number x relative to domain [min_x, max_x] to a domain [a,b]
Parameters:
x (int|float): The value to scale
@ahue
ahue / cyclical_feature.py
Created February 15, 2021 21:09
Because I tend to forget... building cyclical features
import numpy as np
from typing import Union
def cyclical_feature(x: Union(float|np.array), max_x: float):
"""
Transforms a linear scale feature to a feature pair that represent a cyclical one.
Assumes that the feature is in interval [0, max_x]
See also https://towardsdatascience.com/cyclical-features-encoding-its-about-time-ce23581845ca
@ahue
ahue / motion.conf
Last active March 26, 2021 06:57
Configure raspberry pi zero for motion with gif creation and mqtt
# Rename this distribution example file to motion.conf
#
# This config file was generated by motion 4.1.1
# Documentation: /usr/share/doc/motion/motion_guide.html
############################################################
# Daemon
############################################################
# Start in daemon (background) mode and release terminal (default: off)
@ahue
ahue / gist:98eb5a7744c24bb2b2b358985acefdc4
Created April 14, 2021 20:58
Filter a 3d array on one dimension using and 2d index to receive a 2d array
import numpy as np
def filter_tensor_by_mx(tensor, mx):
tshape = tensor.shape
row_ix = np.arange(mx.shape[0])
col_ix = np.arange(mx.shape[1])
ix = np.array(np.meshgrid(row_ix, col_ix)).T.reshape(-1,2).T
pane = rnd_ix_mx.ravel()
res = tensor[pane, ix[0], ix[1]].reshape(mx.shape)
return res
@ahue
ahue / cardinalities.py
Created May 3, 2021 11:52
Analyize cardinalities of a pandas Data.Frame
import pandas as pd
import seaborn as sns
def cardinalities(df: pd.DataFrame, plot: bool = False):
"""
Analyses cardinalities in a data frame
df DataFrame the data frame to be analyized
plot Plot whether to plot rather than return the result DataFrame
returns (DataFrame, Plot) of a matrix M(i,j) that reads row-wise,
@ahue
ahue / cluster_corr.py
Last active May 4, 2021 08:40
Rearranges the correlation matrix, corr_array, so that groups of highly correlated variables are next to eachother
import scipy
import scipy.cluster.hierarchy as sch
def cluster_corr(corr_array, inplace=False, impute_nan=False):
"""
Original author: @WYegelwel (https://wil.yegelwel.com/cluster-correlation-matrix/)
Rearranges the correlation matrix, corr_array, so that groups of highly
correlated variables are next to eachother