This file contains hidden or 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(data.table) | |
library(sp) | |
library(rgdal) | |
library(rgeos) | |
# Via CA GIS Data site | |
ca = readOGR("~/Downloads/CA_Counties", "CA_Counties_TIGER2016") | |
travel_zone = gBuffer( | |
ca[ca$NAME == "Santa Clara", ], |
This file contains hidden or 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(data.table) | |
DT = fread("~/Downloads/spotifyclass.csv") | |
# add new columns. they're great predictors! | |
DT[ , paste0("V", 1:nrow(DT)) := replicate(.N, rnorm(.N), simplify = FALSE)] | |
summary(lm(DT$target ~ ., data = DT[ , .SD, .SDcols = patterns("^V")]))$r.squared |
This file contains hidden or 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
# caveat -- doesn't have 100% overlap w the dictionary | |
CENTER=u | |
LETTERS=${CENTER}cfinot | |
grep $CENTER /usr/share/dict/words | grep -E "^[$LETTERS]{4,}$" |
This file contains hidden or 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 | |
# built on ImageMagick tools via convert; constituent SO answers: | |
# https://askubuntu.com/a/101527/362864 | |
# https://askubuntu.com/a/1052902/362864 | |
# https://stackoverflow.com/a/20075227/3576984 | |
# https://unix.stackexchange.com/a/24019/112834 | |
# INPUT: foo.gif | |
# step 0: isolate foo to its own folder | |
TMPDIR=/tmp/__flop_mirror__ |
This file contains hidden or 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
test_xml = ' | |
<div> | |
<div> | |
<div> | |
<div> | |
<p>1</p> | |
<p>2</p> | |
<p>3</p> | |
</div> | |
</div> |
This file contains hidden or 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
# NB: not fully reproducible since I've had to censor some stuff / obscure credentialling | |
library(data.table) | |
mtcars = cbind(car = rownames(mtcars), mtcars) | |
mtcars = lapply(mtcars, function(x) if (is.character(x)) sQuote(x, "'") else x) | |
colnames = toString(names(mtcars)) | |
mtcars$sep = ', ' | |
# \n\t are bells&whistles to make cat(query) look nicer | |
mtcars$collapse = '),\n\t(' | |
query = sprintf("select * from (values\n\t(%s)\n)\nt(%s)", do.call(paste, mtcars), colnames) | |
presto_rest_endpoint = file.path('/path/to/rest', 'statement') |
This file contains hidden or 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
# sources: | |
# https://prestodb.io/docs/current/functions/datetime.html | |
# https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html | |
# NB: when multiple matches are possible (e.g. %h=%I), the higher one is "preferred" | |
# NB: %r/%T are basically blocked out from being returned Java->Presto by putting | |
# them at the bottom, as a way of preferring the more verbose "full" form | |
# NB: the following supported formats don't have an exact equivalent: %w, %x, %v | |
time_fmt_mapping = fread('posix,java | |
%Y,yyyy | |
%y,yy |
This file contains hidden or 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
P0 = c(...) # initial principal | |
R = c(...) # annualized interest | |
r = (1+R)^(1/12)-1 # monthly interest | |
np = length(P0) | |
X = ... # monthly willingness-to-pay | |
BB = 1e7 # repetitions | |
# slightly more principled... find how many months it takes if |
This file contains hidden or 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(data.table) | |
library(microbenchmark) | |
get_reduce = function(FUN, ELEMENT) { | |
function(..., na.rm=FALSE) { | |
l = list(...) | |
if (length(l) == 1L && is.list(l[[1L]])) l = l[[1L]] | |
if (length(l) == 1L && (identical(FUN, `|`) || identical(FUN, `&`))) l[[1L]] = as.logical(l[[1L]]) | |
if (na.rm) { | |
# TODO: nafill to support complex input, then use nafill here |
This file contains hidden or 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(data.table) | |
library(rtweet) | |
library(ggplot2) | |
library(ggrepel) | |
nyt_words = get_timeline( | |
'NYT_first_said', | |
n = 900, | |
exclude_replies = TRUE, | |
include_rts = FALSE |