Skip to content

Instantly share code, notes, and snippets.

Avatar
💤
#tired

boB Rudis hrbrmstr

💤
#tired
View GitHub Profile
@hrbrmstr
hrbrmstr / graphics.js
Created Aug 27, 2015
nice straightforward D3 example from NPR
View graphics.js
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 Aug 28, 2015
specify smooth line color and confidence band line colors with smoothcol & confcol
View plot.cox.zph
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, ]
View mass_shootings.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 Aug 29, 2015
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)"
View global.R
library(shiny)
library(ggplot2)
library(RCurl)
library(reshape2)
View server.R
library(shiny)
library(ggplot2)
library(scales)
library(grid)
library(gridExtra)
shinyServer(function(input, output) {
output$countPlot <- renderPlot({
@hrbrmstr
hrbrmstr / build.sh
Last active Aug 29, 2015
For dds.ec blog post "Making Better DNS TXT Record Lookups With Rcpp" - (all code MIT license)
View build.sh
export PKG_LIBS=`Rscript --vanilla -e 'Rcpp:::LdFlags()'`
export PKG_CPPFLAGS=`Rscript --vanilla -e 'Rcpp:::CxxFlags()'`
R CMD SHLIB -lldns txt.cpp
View vectorize-part-1.Rmd
---
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
View vectorize-part-2.Rmd
---
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)
View statebins-vcdb-pop.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()) %>%