Skip to content

Instantly share code, notes, and snippets.

View randyzwitch's full-sized avatar

Randy Zwitch randyzwitch

View GitHub Profile
@randyzwitch
randyzwitch / rsitecatalyst-mulitpage.R
Last active December 10, 2015 13:56
RSiteCatalyst Sankey Chart - Many-to-Many
#Multi-page pathing
library("d3Network")
library("RSiteCatalyst")
#### Authentication
SCAuth("name", "secret")
#### Get All Possible Paths with ("::anything::", "::anything::")
pathpattern <- c("::anything::", "::anything::")
next_page <- QueuePathing("zwitchdev",
@randyzwitch
randyzwitch / jsonlite-logging.R
Created October 2, 2014 15:08
JSON logging using jsonlite
#Example
{
"timestamp": 1324830675.076,
"status": "404",
"short_message": "File does not exist: /var/www/no-such-file",
"host": "ord1.product.api0",
"facility": "httpd",
"errno": "ENOENT",
"remote_host": "50.57.61.4",
"remote_port": "40100",
@randyzwitch
randyzwitch / breakout-data.R
Created November 6, 2014 21:25
Daily Pageviews RSiteCatalyst
#Installing BreakoutDetection package
install.packages("devtools")
devtools::install_github("twitter/BreakoutDetection")
library(BreakoutDetection)
library("RSiteCatalyst")
SCAuth("company", "secret")
#Get pageviews for each day in 2014
pageviews_2014 <- QueueOvertime('report-suite',
@randyzwitch
randyzwitch / breakoutdetection-default.R
Created November 6, 2014 21:30
BreakoutDetection - Default example
res <- breakout(formatted_df, min.size=24, method='multi', beta=.001, degree=1, plot=TRUE)
res$plot
@randyzwitch
randyzwitch / breakout-5.R
Created November 6, 2014 22:17
BreakoutDetection - Min Size change
res <- breakout(formatted_df, min.size=5, method='multi', beta=.001, degree=1, plot=TRUE)
res$plot
@randyzwitch
randyzwitch / aa-ggplot2.R
Created November 7, 2014 02:08
Adobe Analytics Anomaly Detection ggplot
#Plot data using ggplot2
library(ggplot2)
#Calculate points crossing UCL or LCL
pageviews_w_forecast$outliers <-
ifelse(pageviews_w_forecast$pageviews > pageviews_w_forecast$upperBound.pageviews, pageviews_w_forecast$pageviews,
ifelse(pageviews_w_forecast$pageviews < pageviews_w_forecast$lowerBound.pageviews, pageviews_w_forecast$pageviews, NA))
#Add LCL and UCL labels
LCL <- vector(mode = "character", nrow(pageviews_w_forecast))
@randyzwitch
randyzwitch / redundant-twitter.jl
Created November 17, 2014 20:11
Redundant Julia code
#############################################################
#
# Help section Functions for Twitter API
#
#############################################################
function get_help_configuration(; options=Dict{String, String}())
r = get_oauth("https://api.twitter.com/1.1/help/configuration.json", options)
@randyzwitch
randyzwitch / meta-twitter.jl
Last active August 29, 2015 14:09
Metaprogramming in Julia
funcname = (:get_help_configuration, :get_help_languages, :get_help_privacy, :get_help_tos, :get_application_rate_limit_status)
endpoint = ("help/configuration.json", "help/languages.json", "help/privacy.json", "help/tos.json", "application/rate_limit_status.json")
for (func, endp) in zip(funcname, endpoint)
@eval function ($func)(; options=Dict{String, String}())
r = get_oauth($"https://api.twitter.com/1.1/$endp", options)
return r.status == 200 ? JSON.parse(r.data) : r
@randyzwitch
randyzwitch / macros-twitter.jl
Created November 23, 2014 04:00
Update: Macros in Julia for code refactoring
macro endpoint(name, path)
quote
function $(esc(name))(; options=Dict{String, String}())
r = get_oauth($"https://api.twitter.com/1.1/$path", options)
return r.status == 200 ? JSON.parse(r.data) : r
end
end
end
@endpoint get_help_configuration "help/configuration.json"
REQUEST:
{
"reportDescription":{
"dateFrom":"2013-01-01",
"dateTo":"2013-11-16",
"reportSuiteID":"",
"segment_id":"53c059aee4b07cd3c4332163",
"metrics":[
{
"id":"bouncerate"