Skip to content

Instantly share code, notes, and snippets.

@flxai
flxai / tmux-grid
Created July 18, 2019 16:13
Run commands in tmux grid layout
#!/bin/bash
# Run a number of commands within tmux in a grid layout
# Session name
s=exp
# Command
c="for i in {1..10}; do echo -n .; sleep 1; done; read"
if tmux has-session -t $s 2>/dev/null; then
echo "Session '$s' exists already, bailing out!"
@flxai
flxai / compare_emd_loss.py
Created February 9, 2019 16:57
compare-emd-loss-wasserstein-distance
import torch
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import wasserstein_distance
from emd import EMDLoss
def gaussian(x, mu, sig):
return np.exp(-np.power(x - mu, 2.) / (2 * np.power(sig, 2.)))
@flxai
flxai / seatfinder-download-and-plot.py
Created October 26, 2018 00:20
Download and plot seatfinder data
import requests
import os
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
BASE_URL = 'https://seatfinder.bibliothek.kit.edu/kassel/getdata.php?location%5B0%5D=UBA0EP,UBA1EP,UBA2EP,UBA3EP,UBB0EP,UBB0GP,UBB1EP,UBB1GP,UBB2EP,UBB2GP,LeoEG,LeoOG&values%5B0%5D=manualcount,seatestimate&after%5B0%5D=-1year&before%5B0%5D=now'
DELIMITER = ';'
FILE_MANUAL_COUNT = 'seatfinder_manual_count.csv'
@flxai
flxai / fd-power-watch.sh
Last active September 13, 2016 15:48
flipdot Shutdown on disconnected power supply
#!/bin/bash
# When the power supply is disconnected, shut down machine after a defined time
# and warning messages
# Time in seconds to shutdown device after disconnected power supply
grace_time=500
timeout=0
while :; do
state=$(upower -i "$battery" | grep state | awk '{print $2}')
@flxai
flxai / fd-wol.sh
Created September 8, 2016 21:31
flipdot Wake On LAN
#!/bin/bash
# Pings a list of hosts and send a Wake On LAN request on success
wake_mac='e8:9a:8f:fd:e6:ce'
declare -a ping_hosts=(\
192.168.3.36 \ # flipdot display
guest.fd \
drinks-touch.fd \
drinks.fd \
)
#!/bin/bash
# Count users currently logged into a list of Freifunk Kassel nodes
url_base=https://graphite.freifunk-kassel.de
url_params="rawData=true"
time_offset="5min"
node_pre="ffks.nodes."
node_post=".clients"
@flxai
flxai / flipdots.py
Created April 26, 2016 23:47
Send image to flipdot display
#!/usr/bin/env python3
import socket
import sys
from PIL import Image
host = '192.168.3.36';
port = 2323;
w = 48
@flxai
flxai / extractpartition.sh
Created April 22, 2016 17:57
Partition extraction from image files
#!/bin/bash
# Extracts a partition from a full disk image containing a partition table
# Colors
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
cyan='\033[0;36m'
nc='\033[0m' # no color
#!/bin/bash
for f in $(ls -tr1 "$1"); do
d="$(stat -c%y $f | awk '{print $1}')T00:00:00"
echo $d $f
git add $f
GIT_COMMITER_DATE="$d" GIT_AUTHOR_DATE="$d" git commit -m "Add $f"
echo
done
@flxai
flxai / ffks-sort-nodes.sh
Created December 31, 2015 09:28
Sets file system modification time according to files certain contents
#!/bin/bash
grn='\e[0;32m'
red='\e[0;31m'
clr='\e[0m'
for f in $1/*; do
fn=$(basename $f)
# file system time stamp
fsts=$(stat -c%y $f | awk '{print $1}')
# key file time stamp