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.R
Created July 24, 2018 17:12
Create/Draw a Binary Fractal Tree with plotly in R
# Create/Draw a Binary Fractal Tree
library(plotly)
# basic strucure for line shape in plotly
base_line = list(
type = "line",
line = list(color = "black"),
xref = "x",
yref = "y",
@AdamSpannbauer
AdamSpannbauer / barnsley_fern.R
Created July 23, 2018 19:14
generate/draw/animate Barnsley fern in R
# Barnsley fern in R
# reference: https://en.wikipedia.org/wiki/Barnsley_fern
library(plotly)
# FUNCTIONS FOR GENERATING BARNSLEY FERN POINTS ################################
transform_1 = function(x, y) {
x = 0
y = 0.16 * y
return(c(x, y))
@AdamSpannbauer
AdamSpannbauer / wordcloud2_url_click.R
Last active June 13, 2018 12:08
wordcloud2 browseURL click event
## install PR of wordcloud2 that adds click events
# devtools::install_github("Lchiffon/wordcloud2#35")
library(shiny)
library(shinyjs)
library(wordcloud2)
# define dummy data to use in example
wordcloud_df = data.frame(word = c('bing', 'google'),
freq = c(1, 2),
@AdamSpannbauer
AdamSpannbauer / query_chunker_R6_class.R
Created June 11, 2018 19:58
an R6 class for chunking large sql queries (written for use with SQL Server). this is a translation of https://gist.github.com/AdamSpannbauer/b04c1f6243ce07a5d2e0c9eb78502a55
library(R6)
QueryChunker = R6Class('QueryChunker',
public = list(
query = NULL,
chunk_query = NULL,
connection = NULL,
post_process_func = NULL,
chunk_size = 1000L,
offset_size = 0,
@AdamSpannbauer
AdamSpannbauer / query_chunker_function_factory.R
Last active June 11, 2018 13:43
a function factory for creating a generator function for chunking large sql queries (written for use with SQL Server)
create_query_chunker = function(query,
dbi_connection,
post_process_func=NULL,
chunk_size=5000L,
debug_print=FALSE) {
#' @title Create a chunked query fetcher
#'
#' @description Creates a generator function that can be repeatedly
#' called to return the next n rows of query (where n = \code{chunk_size})
#'
@AdamSpannbauer
AdamSpannbauer / pytube_download_func.py
Created January 19, 2018 16:48
example pytube function for downloading youtube video
import os
import re
from pytube import YouTube
def downloadYtMp4(ytURL, dlDir=os.getcwd()):
#find youtube video
yt = YouTube(ytURL)
#
#filter to only mp4 files and take last in list (sorted lowest to highest quality)
hqMp4 = yt.filter('mp4')[-1]
@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')
#load needed packages
library(xml2)
library(rvest)
library(lexRankr)
#url to scrape
my_url = "http://www.freepatentsonline.com/y2014/0278285.html"
#read page html
page = xml2::read_html(my_url)
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)
##################################################################
# ADDRESSING https://github.com/AdamSpannbauer/lexRankr/issues/8
##################################################################
# Monduiz'S EXAMPLE CODE
##################################################################
library(rvest)
library(tidyverse)
library(stringr)
library(purrr)