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
# The CONNECT_SERVER URL must have a trailing slash. | |
connectServer <- "https://some-rsc-instance.com/" | |
# Save RSC API key to ~/.Renviron as SAFE_RSC_API_KEY_DEV | |
# - https://docs.rstudio.com/connect/1.7.4/user/cookbook.html | |
connectAPIKey <- Sys.getenv("RSC_API_KEY") | |
# Request a page of up to 25 usage records. | |
resp <- httr::GET( | |
file.path(connectServer, "__api__/v1/instrumentation/shiny/usage?limit=100"), | |
httr::add_headers(Authorization = paste("Key", connectAPIKey)) |
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
# >>> DOCKER >>> | |
# start `n` docker containers in safari (default 1) | |
# option to start in current working directory `--here`; looks for .Rproj and hooks | |
# usage `docker-start [-n num_session] [--here] [<some_docker_image>] [<where_your_repos_live>]` | |
function docker-start () { | |
docker-start-usage() { echo "docker-start [-n num_session] [--here] [<some_docker_image>] [<where_your_repos_live>]" 1>&2; } | |
# https://stackoverflow.com/a/26920580 | |
here_flag=0 | |
# https://stackoverflow.com/a/7680682 |
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
function psql_cmd() { | |
echo "$1" | psql -h $POSTGRES_HOST -U $POSTGRES_USERNAME -d $POSTGRES_DB -p $POSTGRES_PORT | |
} | |
# output data easy to ingest into R or python (includes header; can pass to `tee`) | |
function psql_psv() { | |
echo "$1" | psql -h $POSTGRES_HOST -U $POSTGRES_USERNAME -d $POSTGRES_DB -p $POSTGRES_PORT -A -F' | ' | grep -vE "\(\d+ row[s]\)" | |
} | |
function psql_csv() { |
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
# brew --prefix llvm | |
LLVM_LOC=/usr/local/opt/llvm | |
# brew --prefix gettext | |
GETTEXT=/usr/local/opt/gettext | |
# xcrun --show-sdk-path | |
XCBASE=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk | |
CC=$(LLVM_LOC)/bin/clang -fopenmp | |
CXX=$(LLVM_LOC)/bin/clang++ -fopenmp |
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
# start `n` docker containers in safari (default 1) | |
# usage `docker-start [-n num_session] <some_container>` | |
function docker-start () { | |
docker-start-usage() { echo "docker-start: [-n <number of session>] [<container>]" 1>&2; } | |
local OPTIND n o | |
while getopts "n:" o; do | |
case "${o}" in | |
n) |
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
# quick convert any .md to .html | |
function md2html () { | |
/usr/local/bin/pandoc --standalone --template=https://raw.githubusercontent.com/tajmone/pandoc-goodies/master/templates/html5/github/GitHub.html5 --highlight-style=pygments --css=https://bootswatch.com/3/lumen/bootstrap.min.css --metadata pagetitle=$1 $1 -o ${1%.*}.html | |
} |
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
est_income_tax <- function(x, jointly = F) { | |
# SOURCE | |
# https://www.irs.gov/newsroom/irs-provides-tax-inflation-adjustments-for-tax-year-2022 | |
brackets <- c(0,10275,41775,89075,170050,215950,539900) | |
if(jointly) { | |
# brackets are double for jointly except for the last one | |
brackets <- 2 * brackets | |
brackets[length(brackets)] <- 647850 | |
} | |
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
# cool bash codes | |
# search a directory for all lines that match a pattern (not perfect but useful) ------ | |
## e.g. grep is searching for all lines matching "::" in `R/` to determine package calls | |
## -h hides the file names; -i ignores case | |
## sed -E uses regular expressions to search and match groups; | |
## we then sort and use -u | |
grep -hi :: -R R/* | sed -E 's/(.*)([ ]+[a-z]+::)(.*)/\2/g' | sort -u | |
# COUNT COLUMNS ----------------- |
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
# NA key names using character vector | |
k1 <- c('a', 'b', NA_character_) | |
names(k1) <- k1 | |
v1 <- sample(k1, 1e5, replace = TRUE, prob = c(.2, .2, .6)) | |
# search with "null", but return NA value | |
k2 <- k1 | |
names(k2) <- c('a', 'b', 'null') # new key name | |
# use "null" instead of NA; | |
v2 <- v1 |
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
# e.g. epoch_time = 1562791262 | |
as.POSIXct(1562791262, origin = '1970-01-01', tz = 'GMT') | |
#> [1] "2019-07-10 20:41:02 GMT" | |
as.numeric(as.Date(as.POSIXct(1562791262, origin = '1970-01-01', tz = 'GMT'))) | |
#> [1] 18087 | |
day = (epoch_time) %/% (3600 * 24) # day since 1970-01-01 | |
min = (epoch_time %% (3600 * 24)) %/% 60 # minute of the day |