Skip to content

Instantly share code, notes, and snippets.

View ateucher's full-sized avatar

Andy Teucher ateucher

View GitHub Profile
@ateucher
ateucher / if_ifelse.md
Created July 7, 2017 20:22
R: if vs ifelse

R: if vs ifelse

Inspired by a question about when to use if vs ifelse

First we'll make a simple function that determines whether or not someone is awesome:

is_awesome <- function(name) {
@ateucher
ateucher / add-shadow.sh
Created May 31, 2017 20:53
Add a drop-shadow (like OS-X screenshots)
#!/bin/bash
convert "$1" \( +clone -background grey25 -shadow 60x15+5+10 \) +swap -background transparent -layers merge +repage "${1%.*}-shadow.png"
@ateucher
ateucher / rs_lig.sh
Last active May 11, 2017 21:38
Enable ligatures in RStudio
#!/bin/sh
## Enables ligatures in RStudio. This is for Windows. You will need to open this in a shell with admin priveleges (with sed available).
## On other OSes you will need to change the path to 'www/index.htm' and possibly run with sudo.
## source: https://github.com/tonsky/FiraCode/wiki/RStudio-instructions
sed -e "s/<body>/<body><style>*{text-rendering: optimizeLegibility;}<\/style>/" "c:\Program Files\Rstudio\www\index.htm" > \
"c:\Program Files\Rstudio\www\index.htm.tmp" && \
mv "c:\Program Files\Rstudio\www\index.htm.tmp" "c:\Program Files\Rstudio\www\index.htm"
Commands that got postgres (installed via homebrew) running for me:
$ rm -rf /usr/local/var/postgres
$ initdb /usr/local/var/postgres -E utf8
$ pg_ctl -D /usr/local/var/postgres -l logfile start
$ createuser -s postgres
$ python designatedlands.py create_db
From:
http://stackoverflow.com/questions/7975556/how-to-start-postgresql-server-on-mac-os-x
@ateucher
ateucher / package_deps.R
Last active December 21, 2017 19:01
Get and plot package dependencies using metacran services
#' Search for packages that are dependent on a particular package
#'
#' @param pkg The name of the package
#' @param size Maximum number of dependencies to search for
#' @param ... Additional argumentst passed on to \link{seer}{see}
#'
#' @return A \code{tibble} with columns \code{package} and \code{relationship}
#' @export
#'
#' @examples
@ateucher
ateucher / setup-gh-cli-auth-2fa.md
Last active May 3, 2024 11:06
Setup git on the CLI to use 2FA with GitHub

These are instructions for setting up git to authenticate with GitHub when you have 2-factor authentication set up. This authentication should be inherited by any GUI client you are using. These are intentionally brief instructions, with links to more detail in the appropriate places.

  1. Download and install the git command-line client (if required).

  2. Open the git bash window and introduce yourself to git (if required):

    git config --global user.name 'Firstname Lastname'
    git config --global user.email '[email protected]'
    
# Inspired by Aman Verma's work in rcaaqs
rolling_mean <- function(x, width, thresh = width) {
avail <- !is.na(x)
x[is.na(x)] <- 0
rolled_sum <- cumsum(x) - dplyr::lag(cumsum(x), width, default = 0)
rolled_avail <- cumsum(avail) - dplyr::lag(cumsum(avail), width, default = 0)
ret <- rolled_sum / rolled_avail
ret[rolled_avail < thresh] <- NA
ret
@ateucher
ateucher / recenter_doy.R
Created January 7, 2017 01:02
Create (and optionally recenter) day of year from date
#' Convert a date to a day of year, optionally setting an arbitrary date as the
#' first day in a year.
#'
#' @param date a vector of dates in a standard unambigous format ("YYYY/MM/DD")
#' @param start_doy the first day of the year ("mm/dd"). Default January 1 ("01/01"), but can be set
#' to any month/day to set an arbitrary start date from which to calculate day of year
#'
#' @return integer vector with values from 1:365 (or 366 if a leap year)
#' @export
#'
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.