Skip to content

Instantly share code, notes, and snippets.

View dantonnoriega's full-sized avatar

Danton Noriega-Goodwin dantonnoriega

View GitHub Profile
@dantonnoriega
dantonnoriega / auto-tab-flexdashboard.Rmd
Last active January 8, 2022 19:22
Loop to auto build flexdashboard content, specifically columns with tabs where each tab is an htmlwidget (like highcharts). Be sure to look at the raw code.
---
title: "Loop to Auto Build Tabs Containing htmlwidgets"
output: flexdashboard::flex_dashboard
---
```{r setup, echo =FALSE, eval = TRUE}
library(tidyverse)
library(flexdashboard)
library(highcharter)
@dantonnoriega
dantonnoriega / vikjafjellet.R
Last active December 15, 2016 18:55
highcharter version of the example found at http://www.highcharts.com/demo/spline-irregular-time
library(highcharter)
library(tidyverse)
# set up the series data (so many list of lists...)
## dates are one of the toughest things to plot
## the key to understanding this is in the function `highcharter::hc_add_series_time_values`
## in it, you will find how highcharter parses dates, using `highcharter::datetime_to_timestamp`
## which accepts as.Date values, converts to as.POSIXct then to numeric * 1000
<!-- Styles for R syntax highlighter -->
<style type="text/css">
pre .operator,
pre .paren {
color: rgb(104, 118, 135)
}
pre .literal {
color: rgb(88, 72, 246)
}
@dantonnoriega
dantonnoriega / wake-forest-inmate-data.R
Last active June 23, 2017 19:58
get inmate data for wake county, nc
# variables
OUTPUT_DIR = "~/Dropbox/Jails/data")
DATE <- format(Sys.time(), '%Y-%m-%d')
FILENAME <- sprintf("%s-wake-county-records.csv", DATE)
url <- 'http://p2c.wakeso.net/jqHandler.ashx?op=s'
# set up form request
# query found using Chrome developer tools.
# Ran Query > Go to "Network" tab > find "jqHandler.ashx?op=s"
@dantonnoriega
dantonnoriega / durham-county-inmate-data.R
Last active May 18, 2017 02:55
extract data from durham county jail records
library(httr)
library(tidyverse)
library(xml2)
library(rvest)
devtools::install_github('dantonnoriega/xmltools')
# SET UP VARIABLES
# record_type:
# "0" (all incarcerated)
# "1" (last 24 hours)
@dantonnoriega
dantonnoriega / percent_sign_latex_html.rmd
Created May 24, 2017 03:31
how to get a percent sign when spinning with latex or html
---
title: TEST
output:
pdf_document:
latex_engine: xelatex
html_document:
fig_caption: true
---
```{r, echo = FALSE}
@dantonnoriega
dantonnoriega / highcharter-htmlwidget-webshot-example.R
Last active October 25, 2022 12:56
htmlwidget-webshot-example.R
# Creating html plots with highcharter and generating high resolution PNGs of plots with webshot
library(highcharter)
# set up directories
OUTPUT_HTML <- '~/Downloads/hc-webshot-example/html'
OUTPUT_PNG <- '~/Downloads/hc-webshot-example/png'
if(!dir.exists(OUTPUT_HTML)) dir.create(OUTPUT_HTML, recursive = TRUE)
if(!dir.exists(OUTPUT_PNG)) dir.create(OUTPUT_PNG, recursive = TRUE)
@dantonnoriega
dantonnoriega / parse-utm-script.R
Last active September 6, 2017 03:21
Parse UTM CSV export
# script UTM
# functions
get_utm <- function(x) {
# empty frame
ef <- structure(list(cf_affiliate_id = character(1), utm_source = character(1),
utm_medium = character(1), utm_campaign = character(1), utm_term = character(1),
utm_content = character(1), webinar_delay = character(1),
purchase_product_ids = character(1), purchase_taxamo_transaction_key = character(1),
@dantonnoriega
dantonnoriega / zsh-regex-file-rename-example.sh
Created September 24, 2017 02:49
quick example that downloads some videos from youtube (CS106B Programming Abstraction) then renames the files using regex in zsh for file names ($match). Really cool and useful!
# $match example for zsh
# inspiration:
# https://stackoverflow.com/questions/13043344/search-and-replace-in-bash-using-regular-expressions
# reprex
mkdir CS106B
cd CS106B
# download mp4s of programmming abstraction
@dantonnoriega
dantonnoriega / us-state-ansi-fips.csv
Last active April 14, 2025 19:49
csv file of us state ansi fips codes that follows the us census variable names
stname st stusps
Alabama 01 AL
Alaska 02 AK
Arizona 04 AZ
Arkansas 05 AR
California 06 CA
Colorado 08 CO
Connecticut 09 CT
Delaware 10 DE
District of Columbia 11 DC