Skip to content

Instantly share code, notes, and snippets.

View maxsei's full-sized avatar

Maximillian Schulte maxsei

View GitHub Profile
@maxsei
maxsei / convolution_and_correlation.py
Created October 15, 2021 14:23
Compute convolution and correlation of two series manually using only numpys basic functionality
import numpy as np
def correlate(data, kernel):
# Set up data indexes to use in the kernel multiplication broadcast.
# let len(data) = 1000 and len(kernel) = 5
# array([[ 0, 1, 2, 3, 4],
# [ 1, 2, 3, 4, 5],
# [ 2, 3, 4, 5, 6],
# ...,
@maxsei
maxsei / merge_sort.py
Created November 8, 2021 20:44
implementation of merge sort in python
#!/usr/bin/env python
def merge_sort(unsorted_arr):
if len(unsorted_arr) < 2:
return unsorted_arr
# Pivot into left and right
pivot = len(unsorted_arr) // 2
left = unsorted_arr[:pivot]
@maxsei
maxsei / req-tree.txt
Created December 15, 2021 15:21
tensorflow vs pytorch dependencies
pip==21.3.1
tensorflow==2.7.0
- absl-py [required: >=0.4.0, installed: 1.0.0]
- six [required: Any, installed: 1.16.0]
- astunparse [required: >=1.6.0, installed: 1.6.3]
- six [required: >=1.6.1,<2.0, installed: 1.16.0]
- wheel [required: >=0.23.0,<1.0, installed: 0.37.0]
- flatbuffers [required: >=1.12,<3.0, installed: 2.0]
- gast [required: >=0.2.1,<0.5.0, installed: 0.4.0]
- google-pasta [required: >=0.1.1, installed: 0.2.0]
@maxsei
maxsei / walk_nested.py
Last active October 24, 2022 17:57
Python function that walks through a nested object. Typically this is parsed json data.
import json
from typing import MutableSequence
from typing import Mapping
from copy import deepcopy
def walk_nested(obj, keys=None):
# Default for keys.
if keys is None:
keys = []
@maxsei
maxsei / arrays_vs_pointers.c
Created July 29, 2022 19:30
illistrate the difference between pointers and arrays in c
#include<stdio.h>
#include<stdlib.h>
int main(void) {
int *ptr = calloc(5, sizeof(int));
printf("sizeof(ptr) = %ld\n", sizeof(ptr));
for (void *end = &ptr[5]; ptr != end; ptr++)
@maxsei
maxsei / rotate_images_example.go
Created August 7, 2022 18:06
rotate images of red checkers and red corners
package main
import (
"fmt"
"image"
"image/color"
"image/png"
"os"
)
@maxsei
maxsei / lifo_limiter.go
Created August 11, 2022 18:29
This is an attempt at making something that kills go routines in a stack of go routines in a LIFO order
package main
import (
"sync/atomic"
"log"
"time"
)
func main() {
msgs := make(chan struct{})
@maxsei
maxsei / struct_field_tags.go
Created September 13, 2022 19:21
error prone way of iterating through go struct tags as a map[string]string data structure in golang
package main
import (
"fmt"
"reflect"
"strings"
".../model"
)
@maxsei
maxsei / wtf_args.go
Created September 26, 2022 19:54
weird thing that happens when you try to create immutable arg function
package main
import (
"os"
"fmt"
)
func Args() []string{
args := make([]string, len(os.Args), 100)
fmt.Printf("os.Args: %v\n", os.Args)
@maxsei
maxsei / nix-build.mak
Created October 2, 2022 17:47
basic makefile for working with nix builds
build: # builds defualt.nix
nix-build
clean:
find -type l -exec sh -c 'main(){ \
local drv=$$(nix-store -q --roots $$1 | cut -d " " -f 3); \
rm $$1 && nix-store --delete $$drv; \
}; main $$1' sh {} \;