
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(stringi) | |
library(hrbrthemes) | |
library(archive) | |
library(tidyverse) | |
# I ran readr::type_convert() once and it returns this column type spec. By using it | |
# for subsequent conversions, we'll gain reproducibility and data format change | |
# detection capabilities "for free" | |
cols( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def alphabet_index(c): | |
""" | |
Returns the index of the given character in the English alphabet, counting from 0. | |
""" | |
return ord(c.lower()) - 97 # 'a' is ASCII character 97 | |
def match_length(S, idx1, idx2): | |
""" | |
Returns the length of the match of the substrings of S beginning at idx1 and idx2. | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rcpp::cppFunction('int rcpp_find2(NumericVector needle, NumericVector haystack) { | |
NumericVector::iterator it; | |
it = std::search(haystack.begin(), haystack.end(), needle.begin(), needle.end()); | |
int pos = it - haystack.begin() + 1; | |
if (pos > haystack.size()) pos = -1; | |
return(pos); | |
}') | |
set.seed(010) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"editor.fontFamily": "'Operator Mono Lig', Iosevka, Menlo, Monaco, 'Courier New', monospace", | |
"editor.fontLigatures": true, | |
"editor.fontSize": 14, | |
"editor.tabSize": 2, | |
"editor.wordWrap": "on", | |
"r.rterm.mac" : "/usr/local/bin/rtichoke", | |
"r.rterm.option" : [], | |
"r.lintr.enabled": false, | |
"terminal.external.osxExec": "iTerm.app", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(waffle) | |
library(viridis) | |
library(tidyverse) | |
data_frame( | |
country = c("Rest of World", "Canada*", "Brazil*", "South Korea", "Mexico", | |
"Russia", "Turkey", "Japan", "Taiwan", "Germany", "India"), | |
pct = c(22, 16, 13, 10, 9, 9, 7, 5, 4, 3, 2) | |
) %>% | |
mutate(country = sprintf("%s (%s%%)", country, pct)) %>% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# This self-executing Java program uses the following /embedded shell script/ to compile & execute itself.. | |
# magic constant holding length of script | |
SKIP=26 | |
# parse our name.. | |
FILE=`basename $0 .java` | |
# get some working space, clean up old crud |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
guns_orig <- read_csv("https://docs.google.com/spreadsheet/pub?key=0AswaDV9q95oZdG5fVGJTS25GQXhSTDFpZXE0RHhUdkE&output=csv") | |
guns <- janitor::clean_names(guns_orig) | |
guns <- separate(guns, location, c("city", "state"), sep=",") | |
guns <- mutate(guns, city = trimws(city)) | |
guns <- mutate(guns, state = trimws(state)) | |
guns <- mutate(guns, state = str_replace_all(state, "\\.", "")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
env CC=/usr/local/Cellar/gcc/7.2.0/bin/gcc-7 pip3 install rpy2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(quantmod) # install.packages("quantmod") | |
library(geofacet) # install.packages("geofacet") | |
library(hrbrthemes) # install.packages("hrbrthemes") | |
library(rvest) # install.packages("rvest") | |
library(lucr) # install.packages("lucr") | |
library(tidyverse) # install.packages("tidyverse") | |
get(getSymbols("CPIAUCSL", src='FRED')) %>% | |
as.data.frame() %>% | |
rownames_to_column("date") %>% |