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 / fix_google_photo_whatsapp_backup_dates.py
Created October 9, 2021 11:45
fix google photo dates coming from whatsapp backup
import os
import re
import argparse
import piexif
from datetime import datetime, timedelta
parser = argparse.ArgumentParser()
parser.add_argument('path')
args = parser.parse_args()
@andiwand
andiwand / any_thing.h
Last active August 26, 2021 14:36
C++ type erasure example that could be used as a base class to get a simple interface with value semantics from a abstract class hierarchy. Small object optimization not implemented yet.
template <typename Thing> class AnyThing {
public:
using Base = AnyThing<Thing>;
AnyThing() = default;
AnyThing(const AnyThing &other) { copy_(other); }
AnyThing(AnyThing &&other) noexcept { move_(std::move(other)); }
@andiwand
andiwand / parquet.py
Created February 29, 2020 13:52
estimates and plots parquet for a given room plan
import itertools
import matplotlib.pyplot as plt
from descartes.patch import PolygonPatch
from shapely.geometry import Polygon
from shapely import affinity, ops
#room = Polygon([[0, 0], [5, 0], [5, 5], [10, 5], [10, 10], [0, 10]])
room = Polygon([[0, 0], [4, 0], [4, 4], [0, 4]])
board_width = 2.2
@andiwand
andiwand / diis.py
Last active February 26, 2020 20:05
Python / numpy implementation of DIIS mixing. https://en.wikipedia.org/wiki/DIIS
import numpy as np
from numpy.linalg import multi_dot
# only necessary for FlatMixingDecorator
import w2dyn.auxiliaries.deepflatten as deepflatten
class InitialMixingDecorator(object):
def __init__(self, init_count, init_mixer, mixer):
self.init_count = init_count
self.init_mixer = init_mixer
@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

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 / 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')
@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')
#!/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 / 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