Skip to content

Instantly share code, notes, and snippets.

Avatar
👀
¯\_(ツ)_/¯

Adam Spannbauer AdamSpannbauer

👀
¯\_(ツ)_/¯
View GitHub Profile
@AdamSpannbauer
AdamSpannbauer / Sketch.js
Last active Jan 22, 2021
A base class for a p5js React Component
View Sketch.js
/*
A base class to create p5js sketches as React components.
Requires p5js: `npm install p5`
## Usage
### Extend Sketch and create a p5js sketch
```
@AdamSpannbauer
AdamSpannbauer / non_param_effect_size.py
Created Aug 6, 2020
Functions for non-parametric effect size calculations.
View non_param_effect_size.py
import numpy as np
from scipy import stats
# ---------------------------
# Independent samples -------
# ---------------------------
def cles_ind(x1, x2):
"""Calc common language effect size
@AdamSpannbauer
AdamSpannbauer / docstring.R
Created Jun 9, 2020
An extension of R's `help()` / `?` to work with roxygen style documentation written in a Pythonic / docstring style for non-packaged functions.
View docstring.R
# An extension of help / `?` to work with roxygen documentation in a
# Pythonic / docstring style for non-packaged functions.
.fun_body = function(fun) {
#' Get body of function (including comments) as a character vector
#'
#' @param fun name of function obj to return body of
#'
#' @return character vector of function body (1 element per line)
View plot_normal_area.py
# Modified from https://www.science-emergence.com/Articles/How-to-plot-a-normal-distribution-with-matplotlib-in-python-/
import numpy as np
import scipy.stats
import matplotlib.pyplot as plt
def plot_area(mean, std, pt1, pt2, fill):
plt.plot([pt1, pt1], [0.0, scipy.stats.norm.pdf(pt1, mean, std)], color='black')
plt.plot([pt2, pt2], [0.0, scipy.stats.norm.pdf(pt2, mean, std)], color='black')
@AdamSpannbauer
AdamSpannbauer / example_default_dict.py
Created Jan 22, 2020
Example for default dict to handle missing keys.
View example_default_dict.py
from collections import defaultdict
import numpy as np
def api_call(response_ok=True):
if response_ok:
return {'Released': 2010, 'Ratings': [{'Value': 98}]}
else:
return defaultdict(lambda: np.nan)
@AdamSpannbauer
AdamSpannbauer / print_vif.py
Last active Sep 1, 2020
VIF utility function for checking multicollinearity with stats models
View print_vif.py
import warnings
import statsmodels.api as sm
from statsmodels.stats.outliers_influence import variance_inflation_factor
def print_vif(x):
"""Utility for checking multicollinearity assumption
:param x: input features to check using VIF. This is assumed to be a pandas.DataFrame
:return: nothing is returned the VIFs are printed as a pandas series
View test.txt
("exit" to quit) Question: What market does FitBit compete in?
Search Rank Squad Rank Combined Rank Answer Context
0 2.0 6.0 1.5 crowded market ... rather crowded ma...
1 7.0 1.0 1.5 oncology ...te in the oncology ...
2 8.0 3.0 3.0 streaming services market ...trate the streaming ...
3 5.0 7.0 4.0 leash ...ck a long leash. Boe...
4 4.0 9.0 5.0 iPhones ...io of new iPhones - ...
5 1.0 13.0 6.5 wearables ...hough, is wearables,...
6 9.0 5.0 6.5 murky ...'re in a "murky" mar...
7 15.0 2.0 8.0 ad market ...ce in the ad market ...
View gist:d0f8271b358ba4adbc4fa18bf0da5865
>>> from whoosh.analysis import StandardAnalyzer
>>>
>>> [token.text for token in StandardAnalyzer()("This is an example analysis")]
@AdamSpannbauer
AdamSpannbauer / help2.R
Last active May 2, 2019
Experiment utility function to display docstring-esque help for R functions in Global Environment
View help2.R
# Experimental utility function
message("--------------------------------------------------------------------------------\n")
message("Overwriting `?` function with custom utility to display in memory function help.\n")
message("--------------------------------------------------------------------------------\n\n")
help2 = function(f, ...) {
#' Extend `help()` to show in memory function documentation
#'
#' @details Supports python docstring-esque roxygen documentation.
@AdamSpannbauer
AdamSpannbauer / diamond_problem.py
Created Jan 25, 2019
demonstrating diamond problem stuff with super in python
View diamond_problem.py
class A:
def x(self):
print('x: A')
class B(A):
def x(self):
super().x()
print('x: B')