Skip to content

Instantly share code, notes, and snippets.

View mschrader15's full-sized avatar

Max Schrader mschrader15

View GitHub Profile
@ericpre
ericpre / lowess.py
Last active February 11, 2023 00:41 — forked from agramfort/lowess.py
LOWESS : Locally weighted regression
"""
This module implements the Lowess function for nonparametric regression.
Functions:
lowess Fit a smooth nonparametric regression curve to a scatterplot.
For more information, see
William S. Cleveland: "Robust locally weighted regression and smoothing
scatterplots", Journal of the American Statistical Association, December 1979,
volume 74, number 368, pp. 829-836.
William S. Cleveland and Susan J. Devlin: "Locally weighted regression: An
approach to regression analysis by local fitting", Journal of the American
@yong27
yong27 / apply_df_by_multiprocessing.py
Last active April 12, 2023 04:35
pandas DataFrame apply multiprocessing
import multiprocessing
import pandas as pd
import numpy as np
def _apply_df(args):
df, func, kwargs = args
return df.apply(func, **kwargs)
def apply_by_multiprocessing(df, func, **kwargs):
workers = kwargs.pop('workers')
@javipus
javipus / .gitignore
Last active April 14, 2024 14:05
Kullback-Leibler Divergence Estimator.
__pycache__/*
@Kukanani
Kukanani / save_and_load_sklearn_gmm
Created April 10, 2018 22:49
Save and load a Scikit-learn GMM to file using np.save
import numpy as np
from sklearn import mixture
# make a GMM
gmm = mixture.GaussianMixture(n_components=n_components, covariance_type=cv_type)
# fit the GMM however you'd like
# save to file
gmm_name = 'new_gmm'
np.save(gmm_name + '_weights', gmm.weights_, allow_pickle=False)
@atabakd
atabakd / kl.py
Last active June 20, 2025 05:54
KL divergence for multivariate samples
# https://mail.python.org/pipermail/scipy-user/2011-May/029521.html
import numpy as np
def KLdivergence(x, y):
"""Compute the Kullback-Leibler divergence between two multivariate samples.
Parameters
----------
x : 2D array (n,d)
@EdwinChan
EdwinChan / nested.py
Last active August 1, 2025 20:37
Trick for using multiprocessing with nested functions and lambda expressions
import concurrent.futures
import multiprocessing
import sys
import uuid
def globalize(func):
def result(*args, **kwargs):
return func(*args, **kwargs)
result.__name__ = result.__qualname__ = uuid.uuid4().hex
setattr(sys.modules[result.__module__], result.__name__, result)
@azlen
azlen / bulletpaths.js
Last active September 11, 2025 03:00
All Paths Lead to Roam
/*
* credit to Dhrumil Shah (@wandcrafting) and Robert Haisfield (@RobertHaisfield)
* for the original concept which was part of their RoamGames submission
* and can be found at: https://www.figma.com/file/5shwLdUCHxSaPNEO7pazbe/
*
*/
/* ======= OPTIONS ======== */
/* note: if you change these, reload the page to see the effect */
@jpswinski
jpswinski / geoparquet.cpp
Last active September 29, 2025 13:46
Minimal example C++ code to write a GeoParquet file using Apache Arrow
/*
* File: geoparquet.cpp
*
* Purpose: A minimal example to build a GeoParquet file using Apache Arrow.
*
* Prerequisites: The Apache Arrow library is needed and can be installed as follows
* $ git clone https://github.com/apache/arrow.git
* $ cd arrow/cpp
* $ mkdir build
* $ cd build
@tejaslodaya
tejaslodaya / apply_df_by_multiprocessing.py
Created February 3, 2017 09:12
pandas DataFrame apply multiprocessing
import multiprocessing
import pandas as pd
import numpy as np
def _apply_df(args):
df, func, num, kwargs = args
return num, df.apply(func, **kwargs)
def apply_by_multiprocessing(df,func,**kwargs):
workers=kwargs.pop('workers')
@reywood
reywood / how-to.md
Last active January 4, 2026 21:28
How to get a stack trace from a stuck/hanging python script

How to get a stack trace for each thread in a running python script

Sometimes a python script will simply hang forever with no indication of where things went wrong. Perhaps it's polling a service that will never return a value that allows the program to move forward. Here's a way to see where the program is currently stuck.

Install gdb and pyrasite

Install gdb.

# Redhat, CentOS, etc