Skip to content

Instantly share code, notes, and snippets.

View hrbrmstr's full-sized avatar
💤
#tired

boB Rudis hrbrmstr

💤
#tired
View GitHub Profile
@hrbrmstr
hrbrmstr / graphics.js
Created August 27, 2015 16:47
nice straightforward D3 example from NPR
var $graphic = $('#graphic');
var fmt_year_abbr = d3.time.format('%y');
var fmt_year_full = d3.time.format('%Y');
var graphic_data;
var graphic_data_url = 'data.csv';
var graphic_default_width = 600;
var is_mobile;
var mobile_threshold = 540;
var pymChild = null;
@hrbrmstr
hrbrmstr / plot.cox.zph
Last active August 28, 2015 14:21
specify smooth line color and confidence band line colors with smoothcol & confcol
plot.cox.zph <- function (x, resid = TRUE, se = TRUE, df = 4, nsmo = 40, var, smoothcol="black", confcol="black", ...) {
xx <- x$x
yy <- x$y
d <- nrow(yy)
df <- max(df)
nvar <- ncol(yy)
pred.x <- seq(from = min(xx), to = max(xx), length = nsmo)
temp <- c(pred.x, xx)
lmat <- splines::ns(temp, df = df, intercept = TRUE)
pmat <- lmat[1:nsmo, ]
@hrbrmstr
hrbrmstr / mass_shootings.Rmd
Last active August 28, 2015 20:47
code for Rmd
---
title: "Mass Shootings Are Horrifying Enough Without Fudging The Numbers"
author: "Bob Rudis (@hrbrmstr)"
date: "August 28, 2015"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, fig.retina=2)
```
@hrbrmstr
hrbrmstr / global.R
Last active August 29, 2015 13:56
sochi 2014 in R using google docs scraper & line+dot plot facets. see it in action at http://shiny.dds.ec/sochi2014 or run it locally via "shiny::runGist(8949172)" which can be invoked directly from a command-prompt (on any operating system) thusly: "Rscript -e "shiny::runGist(8949172,launch.browser=TRUE)"
library(shiny)
library(ggplot2)
library(RCurl)
library(reshape2)
library(shiny)
library(ggplot2)
library(scales)
library(grid)
library(gridExtra)
shinyServer(function(input, output) {
output$countPlot <- renderPlot({
@hrbrmstr
hrbrmstr / build.sh
Last active August 29, 2015 14:00
For dds.ec blog post "Making Better DNS TXT Record Lookups With Rcpp" - (all code MIT license)
export PKG_LIBS=`Rscript --vanilla -e 'Rcpp:::LdFlags()'`
export PKG_CPPFLAGS=`Rscript --vanilla -e 'Rcpp:::CxxFlags()'`
R CMD SHLIB -lldns txt.cpp
---
title: "Vectorize() Vectorization Example"
author: "Bob Rudis (@hrbrmstr)"
date: "May 16, 2014"
output: md_document
---
```{r echo=FALSE, message=FALSE, error=FALSE, warning=FALSE}
library(Rcpp)
# We need this to ensure knitr+Rcpp can link to the boost library
---
title: "Rcpp Vectorization Example"
author: "Bob Rudis (@hrbrmstr)"
date: "May 17, 2014"
output: md_document
---
```{r echo=FALSE, message=FALSE, error=FALSE, warning=FALSE}
library(Rcpp)
library(bitops)
library(scales)
@hrbrmstr
hrbrmstr / statebins-vcdb-pop.R
Created August 27, 2014 03:58
statebins in R
library(data.table)
library(verisr)
library(dplyr)
library(statebins)
vcdb <- json2veris("/Users/bob/Desktop/r/VCDB-d3/VCDB/data/json/")
tbl_dt(vcdb) %>%
filter(victim.state %in% state.abb) %>%
group_by(victim.state) %>%
summarize(count=n()) %>%