Skip to content

Instantly share code, notes, and snippets.

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

Adam Spannbauer AdamSpannbauer

👀
¯\_(ツ)_/¯
View GitHub Profile
@AdamSpannbauer
AdamSpannbauer / get_twitter_time_dataframe.R
Created March 10, 2017 02:58
Get tweets from a user's timeline
get_timeline_df <- function(user, n_tweets=200, oauth_sig) {
i <- 0
n_left <- n_tweets
timeline_df <- NULL
#loop until n_tweets are all got
while (n_left > 0) {
n_to_get <- min(200, n_left)
i <- i+1
#incorporae max id in get_url (so as not to download same 200 tweets repeatedly)
if (i==1) {
##################################################################
# ADDRESSING https://github.com/AdamSpannbauer/lexRankr/issues/8
##################################################################
# GET EXAMPLE DATA
#----------------------------------------------------------
library(xml2)
library(rvest)
options(stringsAsFactors = FALSE)
##################################################################
# ADDRESSING https://github.com/AdamSpannbauer/lexRankr/issues/8
##################################################################
# Monduiz'S EXAMPLE CODE
##################################################################
library(rvest)
library(tidyverse)
library(stringr)
library(purrr)
#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)
@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 / 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 / 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 / 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 / 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",
# Create/Draw a Binary Fractal Tree
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)
trunk_df = data.frame(x=c(0, 0),