Skip to content

Instantly share code, notes, and snippets.

View AdamSpannbauer's full-sized avatar
👀
¯\_(ツ)_/¯

Adam Spannbauer AdamSpannbauer

👀
¯\_(ツ)_/¯
View GitHub Profile
@AdamSpannbauer
AdamSpannbauer / fractal_tree_gganimate.R
Created July 25, 2018 02:00
Create/animate fractal trees at various angles for branch splits
# Create/animate fractal trees at various angles for branch splits
library(gganimate)
library(ggplot2)
library(uuid)
options(stringsAsFactors = FALSE)
# create line segment from (0, 0) to (0, len) to be trunk of fractal tree
create_trunk = function(len = 1) {
end_point = c(0, len)
@AdamSpannbauer
AdamSpannbauer / diamond_problem.py
Created January 25, 2019 12:56
demonstrating diamond problem stuff with super in python
class A:
def x(self):
print('x: A')
class B(A):
def x(self):
super().x()
print('x: B')
@AdamSpannbauer
AdamSpannbauer / help2.R
Last active May 2, 2019 17:34
Experiment utility function to display docstring-esque help for R functions in Global Environment
# 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 / wordcloud2_clickeven_with_reset.R
Created January 12, 2018 19:15
wordcloud2 example of click event and input resetting
#current preferred version of wc2
devtools::install_github("Lchiffon/wordcloud2#32")
#function to give wordcloud2 click interactivity
wc2ClickedWord = function(cloudOutputId, inputId) {
#ARGUMENTS
# - cloudOutputId: string; outputId of wordcloud2 obj being rendered (should be identical to the value passed to wordcloud2Output)
# - inputId: string; inputId of word clicked on (ie you will reference in server the word by input$inputId)
#OUPUT
# - referencing input in server will return a string of form word:freq (same as hover info shown in wordcloud; ie 'super:32')
library(data.table)
library(gganimate)
library(ggplot2)
#toy example data
dt = data.table(time=1:10, x=round(runif(10, 50, 100), 0))
#number of frames per bar
n_frames_per_bar = 20
#create sequence per time (to imitate the bar growing from ground)
>>> from whoosh.analysis import StandardAnalyzer
>>>
>>> [token.text for token in StandardAnalyzer()("This is an example analysis")]
("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 ...
@AdamSpannbauer
AdamSpannbauer / example_default_dict.py
Created January 22, 2020 11:53
Example for default dict to handle missing keys.
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)
# 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 / docstring.R
Created June 9, 2020 10:38
An extension of R's `help()` / `?` to work with roxygen style documentation written in a Pythonic / docstring style for non-packaged functions.
# 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)