Skip to content

Instantly share code, notes, and snippets.

View justinjm's full-sized avatar
🌊

Justin Marciszewski justinjm

🌊
View GitHub Profile
@justinjm
justinjm / Dockerfile
Created March 13, 2023 12:34 — forked from bimission/Dockerfile
RobynDockerfile
FROM gcr.io/deeplearning-platform-release/r-cpu
# install dependencies
RUN apt-get update && \
apt-get install -y \
autoconf \
automake \
g++ \
gcc \
cmake \
# Takes an ordered vector of numeric values and returns a small bar chart made
# out of Unicode block elements. Works well inside dplyr mutate() or summarise()
# calls on grouped data frames.
sparkbar <- function(values) {
span <- max(values) - min(values)
if(span > 0 & !is.na(span)) {
steps <- round(values / (span / 7))
blocks <- c('▁', '▂', '▃', '▄', '▅', '▆', '▇', '█')
paste(sapply(steps - (min(steps) - 1), function(i) blocks[i]), collapse = '')

Keybase proof

I hereby claim:

  • I am justinjm on github.
  • I am hianalytics (https://keybase.io/hianalytics) on keybase.
  • I have a public key ASArdGwJEbzw7JyWuRaLCyd-RW0s00eecjmU_p1jERz7OQo

To claim this, I am signing this object:

@justinjm
justinjm / global.R
Created June 8, 2018 17:20 — forked from raymondben/global.R
gauth shiny example
library(googleAuthR)
library(shiny)
library(shinyjs)
@justinjm
justinjm / revenue-forecast-google-merch-store.R
Last active December 2, 2019 05:00
Source code for the E-Nor blog post "Predictive Modeling for eCommerce KPIs"
# config ------------------------------------------------------------------
## load packages
library(googleAuthR)
library(bigQueryR)
library(dplyr)
library(prophet)
library(ggplot2)
library(plotly)
library(scales)

There are packages for this now!

2017-08-03: Since I wrote this in 2014, the universe, specifically Kirill Müller (https://github.com/krlmlr), has provided better solutions to this problem. I now recommend that you use one of these two packages:

  • rprojroot: This is the main package with functions to help you express paths in a way that will "just work" when developing interactively in an RStudio Project and when you render your file.
  • here: A lightweight wrapper around rprojroot that anticipates the most likely scenario: you want to write paths relative to the top-level directory, defined as an RStudio project or Git repo. TRY THIS FIRST.

I love these packages so much I wrote an ode to here.

I use these packages now instead of what I describe below. I'll leave this gist up for historical interest. 😆

@justinjm
justinjm / get_data.R
Last active September 15, 2017 22:04
A function to export multiple datasets from the Google Analytics Core Reporting API v4
library(googleAuthR)
library(googleAnalyticsR)
library(dplyr)
#' Get Google Analytics Data for Dashboards
#'
#' Extract and join session and hit level data from GA, save as
#' rds files for dashboards
#'
#' @param dates date range list of pairs, from and to dates
@justinjm
justinjm / bigquery_schema.py
Created August 3, 2016 20:10 — forked from igama/bigquery_schema.py
Sense / infer / generate a big query schema string for import #bigquery
import mimetypes
import sys
from collections import OrderedDict
filename = sys.argv[1]
def file_type(filename):
type = mimetypes.guess_type(filename)
return type