Skip to content

Instantly share code, notes, and snippets.

View hrbrmstr's full-sized avatar
💤
#tired

boB Rudis hrbrmstr

💤
#tired
View GitHub Profile
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(
@hrbrmstr
hrbrmstr / boyermoor.py
Created April 4, 2018 13:24 — forked from jonocarroll/boyermoor.py
Boyer-Moore Implementations for @coolbutuseless' comparisons
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.
"""
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)
@hrbrmstr
hrbrmstr / keybindings.json
Last active March 29, 2018 02:34
user-settings.js
{
"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",
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)) %>%
@hrbrmstr
hrbrmstr / Ick.java
Created March 2, 2018 22:12 — forked from phlash/Ick.java
Self-executing single-file Java programs...
#!/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
@hrbrmstr
hrbrmstr / altway.r
Last active February 26, 2018 17:52
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, "\\.", ""))
@hrbrmstr
hrbrmstr / rpy2-on-macos-r-3.4.bash
Created February 26, 2018 12:37
Getting rpy2 to work on macOS 10.12 / 10.13 with pip3 and gcc
env CC=/usr/local/Cellar/gcc/7.2.0/bin/gcc-7 pip3 install rpy2
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") %>%