Skip to content

Instantly share code, notes, and snippets.

View AlexanderNenninger's full-sized avatar
🏠
Working from home

Alexander Nenninger AlexanderNenninger

🏠
Working from home
  • NTT DATA
  • Berlin → München
  • 12:44 (UTC +02:00)
View GitHub Profile
@AlexanderNenninger
AlexanderNenninger / quad.py
Last active December 12, 2021 17:57
Quadrilateral Calulator
# bin/python3
__title__ = "quad.py"
__author__ = "Alexander Nenninger"
__website__ = "https://gist.github.com/AlexanderNenninger"
__year__ = 2021
__license__ = "MIT"
"""
Calculate coordinates of the corners of a quadrilateral from side- and
use std::collections::HashSet;
use std::error::Error;
use std::fmt;
use std::isize;
use std::num::ParseIntError;
use std::str;
pub const INPUT: &str = "input/day13.txt";
#[derive(Debug)]
@AlexanderNenninger
AlexanderNenninger / callback.rs
Last active February 20, 2022 15:14
Callback pattern in rust.
use std::boxed::Box;
type Callback = Box<dyn Fn(&mut f64, &f64)>;
type Condition = Box<dyn Fn(&f64, &f64) -> bool>;
type Effect = Box<dyn Fn(&mut f64, &f64)>;
fn step(u: &mut f64, t: &mut f64, callback: &Callback) {
callback(u, t);
*t += 1.;
*u += 1.;
@AlexanderNenninger
AlexanderNenninger / event_timer_cb.rs
Last active January 13, 2022 13:32
Callback to track time when last event occured. Written in Rust for referential transparency.
use std::boxed::Box;
type Callback<U, T> = Box<dyn Fn(&mut U, &T)>;
type Condition<U, T> = Box<dyn Fn(&U, &T) -> bool>;
type Effect<U, T> = Box<dyn Fn(&mut U, &T)>;
fn make_callback<U: 'static, T: 'static>(
condition: Condition<U, T>,
effect: Effect<U, T>,
) -> Callback<U, T> {
@AlexanderNenninger
AlexanderNenninger / pylistbench.py
Last active February 13, 2022 21:04
Compare speed of different ways of constructing a list.
stmt_index = 'ls = [0]*10000\nfor i in range(10000):\n ls[i] = i\n'
stmt_append = 'ls = []\nfor i in range(10000):\n ls.append(i)\n'
stmt_comprehension = '[i for i in range(10000)]'
t_index = timeit(stmt_index, number=10000)
# >>> 3.06s
t_append = timeit(stmt_append, number=10000)
# >>> 4.23s
import time
import numba as nb
import numpy as np
def timeit(method):
"Decorator to time a function"
def timed(*args, **kw):
ts = time.time()
@AlexanderNenninger
AlexanderNenninger / ThresholdingAlgo2.py
Created June 21, 2022 07:15 — forked from dlegor/ThresholdingAlgo2.py
Python implementation of smoothed z-score algorithm version 2, from http://stackoverflow.com/a/22640362/6029703
from numba.decorators import jit
import numpy as np
#The original version is here: https://gist.github.com/ximeg/587011a65d05f067a29ce9c22894d1d2
#I made small changes and used numba to do it faster.
@jit
def thresholding_algo2(y, lag, threshold, influence):
signals = np.zeros(len(y))
filteredY = np.array(y)
import numpy as np
from numpy import ndarray
import matplotlib.pyplot as plt
from functools import reduce
def up(index):
i, j = index
return i - 1, j
@AlexanderNenninger
AlexanderNenninger / lazyarrays.jl
Last active August 3, 2023 12:27
Array that computes it's entries on the fly
# Lazy Array implementation. The explicit typing allows for static compilation leading to high performance.
using LinearAlgebra
using BenchmarkTools
# Quick implementation of a lazy Array. Yes, it's really *that* simple.
mutable struct LazyFunctionArray{F<:Function,T,N} <: AbstractArray{T,N}
const f::F # Julia 1.8 const field syntax for convenience
const size::NTuple{N,Int}
ncalls::Int
@AlexanderNenninger
AlexanderNenninger / .gitattributes
Last active April 14, 2024 13:51
Map datasets with metadata to parquet and back. Supports partitioning, cloud buckets etc. thanks to pyarrow.
*.parquet binary merge=ours
*.parquet filter=lfs diff=lfs merge=lfs -text