Skip to content

Instantly share code, notes, and snippets.

View hrbrmstr's full-sized avatar
💤
#tired

boB Rudis hrbrmstr

💤
#tired
View GitHub Profile
library(epidata) # install.packages("epidata")
library(hrbrthemes) # install.packages("hrbrthemes")
library(tidyverse)
xdf <- get_median_and_mean_wages("l")
select(xdf, -median, -average) %>%
gather(measure, value, -date) %>%
mutate(measure = str_replace_all(measure, "_", " ")) %>%
mutate(measure = str_to_title(measure)) %>%
> parse_ns_file("~/packages/iptools/")
$imports
$imports[[1]]
[1] "AsioHeaders"
$imports[[2]]
[1] "stats"
$imports[[3]]
[1] "stringi"
@hrbrmstr
hrbrmstr / stat-hilbert.r
Created February 4, 2018 02:58
faster IPv4 Hilbert curves in R + ggplot2
library(Rcpp)
library(dplyr)
library(ggplot2) # devtools::install_github("tidyverse/ggplot2")
#' @param ips a vector of numeric IPv4 addresses
#' @param addr_space_bits_per_image (will depend on CIDR being shown - default = full IPv4)
#' @param addr_space_bits_per_pixel (normally 1 pixel == 256 addrs; this mods that)
cppFunction('
List ips_to_xy(std::vector<unsigned> ips,
int addr_space_bits_per_image = 32L,
cc routed_unused unrouted_unused used unused_combined pct_used pct_unused pct_lab used_ct unused_ct continent id
ad 24 0 119 24 0.8321678321678322 0.16783216783216784 16.8% 30464 6144 Europe AND
ae 2953 975 8326 3928 0.6794516076383221 0.3205483923616778 32.1% 2131456 1005568 Asia ARE
af 112 165 304 277 0.5232358003442341 0.47676419965576594 47.7% 77824 70912 Asia AFG
ag 60 29 118 89 0.5700483091787439 0.42995169082125606 43.0% 30208 22784 Americas ATG
ai 6 2 36 8 0.8181818181818182 0.18181818181818182 18.2% 9216 2048 Americas AIA
al 407 54 511 461 0.5257201646090535 0.4742798353909465 47.4% 130816 118016 Europe ALB
am 494 37 1788 531 0.7710219922380336 0.22897800776196636 22.9% 457728 135936 Asia ARM
ao 2671 22 650 2693 0.1944361352078971 0.8055638647921028 80.6% 166400 689408 Africa AGO
ap 0 2 7 2 0.7777777777777778 0.2222222222222222 22.2% 1792 512 Asia NA
@hrbrmstr
hrbrmstr / firehose.r
Created January 24, 2018 02:54
databot firehose
library(httr)
library(tidyverse)
GET(
url = "https://projects.propublica.org/electionbot/api/v1/firehose.json",
httr::add_headers(
Accept = "application/json, text/javascript, */*; q=0.01",
`Accept-Language` = "en-US,en;q=0.5",
`Cache-Control` = "max-age=0",
Connection = "keep-alive",
library(purrr)
script <- '
library(js) ; library(foo)
#
library("V8")
ls()
library(package=rvest)
TRUE
library(package="hrbrthemes")
library(ggalt)
library(cdcfluview)
library(hrbrthemes)
library(tidyverse)
ili <- ilinet("national", years = 2013:2018)
update_geom_font_defaults(font_rc)
theme_set(theme_ipsum_rc(grid="XY", strip_text_face = "bold"))
Only including this file so the title of the gist isn't `.gitignore`
library(grid)
library(gridExtra)
mydf <- data.frame(id = c(1:5), value = c("A","B","C","D","E"))
mytheme <- ttheme_default(base_size = 10,
core = list(fg_params=list(hjust=0, x=0.01),
bg_params=list(fill=c("white", "lightgrey"))))
tg <- tableGrob(mydf, cols = NULL, theme = mytheme, rows = NULL)
@hrbrmstr
hrbrmstr / git-create-remote.sh
Created January 16, 2018 04:59 — forked from simonecorsi/git-create-remote.sh
This function will walk you through the creation of a remote repository on github without wasting your precious time going to the website :)
# This function will walk you through the creation of a remote repository on github
# without wasting your precious time going to the website :)
# how:
# - source it in your (bash|zsh)rc
# - change the alias at the bottom of the script to your needs
# - call it, follow instructions... profit
function createRemoteGitRepository() {
local RED='\033[0;31m'
local NC='\033[0m' # No Color
local GITHUB_USER=''