Skip to content

Instantly share code, notes, and snippets.

View hrbrmstr's full-sized avatar
💤
#tired

boB Rudis hrbrmstr

💤
#tired
View GitHub Profile
---
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)

Keybase proof

I hereby claim:

  • I am hrbrmstr on github.
  • I am hrbrmstr (https://keybase.io/hrbrmstr) on keybase.
  • I have a public key whose fingerprint is 8BEC EF50 9D70 C613 A59C 5AD7 CBB9 4084 59AD 8A98

To claim this, I am signing this object:

@hrbrmstr
hrbrmstr / resolver.cpp
Created August 4, 2014 03:00
Rcpp + Boost version of gethostbyname and gethostbyaddr
#include <Rcpp.h>
#include <boost/asio.hpp>
using namespace Rcpp;
Function message("message"); // lets us use R's message() function
//[[Rcpp::export]]
std::vector< std::string > gethostbyname(std::string hostname) {
@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()) %>%
@hrbrmstr
hrbrmstr / pantone_cotd.R
Created August 29, 2014 13:57
Quick R function to get the Pantone "Color of the Day" color from https://www.pantone.com/pages/colorstrology/colorstrology.aspx
library(XML)
library(httr)
library(stringr)
pantone_cotd <- function(cotd_url = "https://www.pantone.com/pages/colorstrology/colorstrology.aspx") {
# have to fake a real user agent to get the color
agent <- "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.78.2 (KHTML, like Gecko) Version/7.0.6 Safari/537.78.2"
try(pantone <- GET(cotd_url, user_agent(agent)))
@hrbrmstr
hrbrmstr / rvestEx1.R
Created September 17, 2014 16:09
rvsest example
library(XML)
library(httr)
library(rvest)
library(magrittr)
# setup connection & grab HTML the "old" way w/httr
freak_html <- htmlParse(content(GET("http://torrentfreak.com/top-10-most-pirated-movies-of-the-week-130304/"), as="text"))
# do the same the rvest way, using "html_session" since we may need connection info in some scripts
freak <- html_session("http://torrentfreak.com/top-10-most-pirated-movies-of-the-week-130304/")
@hrbrmstr
hrbrmstr / 500miles.R
Last active August 29, 2015 14:06
More accurate Proclaimers geographical humor (in R)
library(ggplot2)
library(ggmap)
vectorDestination <- function(lonlatpoint, travelvector) {
Rearth <- 6372795
Dd <- travelvector$magnitude / Rearth
Cc <- travelvector$direction
@hrbrmstr
hrbrmstr / cantons.R
Last active November 12, 2018 13:50
Swiss Cantons - R version of http://bl.ocks.org/mbostock/4207744
library(rgeos)
library(rgdal) # needs gdal > 1.11.0
library(ggplot2)
# map theme
devtools::source_gist("https://gist.github.com/hrbrmstr/33baa3a79c5cfef0f6df")
map = readOGR("readme-swiss.json", "cantons")
map_df <- fortify(map)
@hrbrmstr
hrbrmstr / themes.R
Last active April 16, 2018 19:48
various themes
theme_map <- function(base_size=9, base_family="") {
require(grid)
theme_bw(base_size=base_size, base_family=base_family) %+replace%
theme(
axis.line=element_blank(),
axis.text=element_blank(),
axis.ticks=element_blank(),
axis.title=element_blank(),
panel.background=element_blank(),
panel.border=element_blank(),
@hrbrmstr
hrbrmstr / costarica.R
Last active June 30, 2021 20:54
Costa Rica - R version of http://bl.ocks.org/arce/9357998
library(rgeos)
library(rgdal) # needs gdal > 1.11.0
library(ggplot2)
# map theme
devtools::source_gist("https://gist.github.com/hrbrmstr/33baa3a79c5cfef0f6df")
# grab each of the layers
limites = readOGR("division.json", "limites")