Skip to content

Instantly share code, notes, and snippets.

View andiwand's full-sized avatar

Andreas Stefl andiwand

  • CERN
  • Geneva
View GitHub Profile
@andiwand
andiwand / focustree.js
Created July 26, 2016 20:20
Javascript focus tree eventing
focustree = (function() {
var entries = [];
var currentFocus = [];
function indexOf(array, element) {
for (var i = 0; i < array.length; i++) {
if (array[i] === element) return i;
}
return -1;
@andiwand
andiwand / observables.js
Last active November 5, 2019 06:20
Javascript observable objects with Proxy (ECMA-262 6th Edition, https://mzl.la/203LEg9)
ObservableArray = function(array) {
if (array == null) array = [];
if (!Array.isArray(array)) throw new TypeError('argument is not an array');
var listeners = [];
this.toString = array.toString;
this.listen = function(listener) {
listeners.push(listener);
@andiwand
andiwand / 01-default-route
Last active December 3, 2022 04:49
OpenWrt / LEDE hotplug script to add default routes correctly.
#!/bin/sh
# OpenWrt / LEDE hotplug script to add default routes correctly.
#
# Location "/etc/hotplug.d/iface/01-default-route".
#
# Fixed mwan3 "No default route in the main routing table" and
# "WARNING: this interface has no default route in the main routing table!" for me.
uci get "network.${INTERFACE}.gateway" > /dev/null 2>&1 || exit
@andiwand
andiwand / fix-default-routes
Last active September 26, 2018 04:07
OpenWrt / LEDE script to fix default routes.
#!/bin/ash
# OpenWrt / LEDE script to fix default routes.
if [ "$#" -ne 1 ]; then
>&2 echo "usage: $0 interface [interface ...]"
exit 1
fi
for arg in "$@"; do
@andiwand
andiwand / check_mwan3
Created August 22, 2017 07:20
nagios check script - openwrt mwan3 status
#/bin/ash
. /lib/functions.sh
. /lib/functions/network.sh
. /lib/mwan3/mwan3.sh
mwan3_iface_status()
{
local device result track_ips tracking IP IPT
#!/usr/bin/env python3
import argparse
import socket
import struct
import threading
def arguments():
parser = argparse.ArgumentParser()
parser.add_argument('--tcp-port', type=int, default=5004)
@andiwand
andiwand / backup_suntrol.py
Last active November 25, 2018 13:49
Backup time vs power data from suntrol-portal.com
#!/usr/bin/env python3
import argparse
import datetime
import requests
import pandas
def date(s):
try:
return datetime.datetime.strptime(s, '%Y-%m-%d')
@andiwand
andiwand / check_time.py
Created November 25, 2018 14:14
nagios script; check access / modified / creation age
#!/usr/bin/env python
import os
import sys
import time
import argparse
def main():
parser = argparse.ArgumentParser(description='check access / modified / creation age')
parser.add_argument('path', help='path to check')

Keybase proof

I hereby claim:

  • I am andiwand on github.
  • I am andiwand (https://keybase.io/andiwand) on keybase.
  • I have a public key ASDyv23uKydhtxOPY8oWlTgjXuiF-16QywVgrvHBOB0gDQo

To claim this, I am signing this object:

@andiwand
andiwand / deepflatten.py
Created February 20, 2020 10:24
Flatten nested Python list with numbers and numpy arrays.
import numbers
import numpy as np
def types(x):
if type(x) is np.ndarray: return x.dtype
if isinstance(x, numbers.Number): return type(x)
result = []
for i in x: result.append(types(i))
return result