Skip to content

Instantly share code, notes, and snippets.

View brodieG's full-sized avatar

Brodie Gaslam brodieG

View GitHub Profile
@brodieG
brodieG / membug.R
Created February 27, 2016 18:48
Demonstrate Crayon Binary Package Memoise Bug
ls(all=T)
# character(0)
install.packages("crayon")
# trying URL 'http://cran.r-project.org/bin/macosx/mavericks/contrib/3.2/crayon_1.3.1.tgz'
# Content type 'application/x-gzip' length 604079 bytes (589 KB)
# ==================================================
# downloaded 589 KB
#
#
# The downloaded binary packages are in
@brodieG
brodieG / optim.R
Created March 8, 2016 02:41
Demonstrate Some Optimizations to Crayon Substring
## Lightly edited for clarity
R version 3.2.2 (2015-08-14) -- "Fire Safety"
> install.packages("crayon")
trying URL 'http://cran.r-project.org/bin/macosx/mavericks/contrib/3.2/crayon_1.3.1.tgz'
Content type 'application/x-gzip' length 604079 bytes (589 KB)
==================================================
downloaded 589 KB
@brodieG
brodieG / gist:8eaccf0e1bb7cb2f60f1ecfcd26b473c
Last active August 22, 2016 01:44
Illustrate Connection Issues
f1 <- tempfile()
f2 <- tempfile()
cat("hello\n", file=f1)
cat("goodbye\n", file=f2)
con1 <- file(f1)
open(con1)
getAllConnections()
close(con1)
@brodieG
brodieG / browse.err.R
Last active October 18, 2016 01:36
Browser Bugs With on.exit
# Tested on OS X and Ubuntu R 3.3.1, appears fixed in R-devel
# WARNING: you may have to kill your session if you run the code here
fun <- function() {
on.exit(cat('exited\n'))
stop('hello')
}
{
browser()
# type `fun()` at Browser[1]> prompt to cause infinite loop
@brodieG
brodieG / listcompare.R
Last active November 18, 2016 02:27
Compare diffobj vs. all.equal with nested list
list.A <- list(
list(a=1, b=2, c=matrix(1:9, 3)),
letters[1:16],
1:100,
head(warpbreaks, 3)
)
list.B <- list.A
list.B[[1]]$a <- list()
list.B[[1]]$c <- list.B[[1]]$c[-1, ]
list.B[[2]] <- LETTERS[1:16]
@brodieG
brodieG / GIF-Screencast-OSX.md
Created March 18, 2017 00:58 — forked from dergachev/GIF-Screencast-OSX.md
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@brodieG
brodieG / grepso.R
Created April 18, 2017 22:08
Grep Stack Overflow
reg <- "(A|B)*" # overflow
reg <- "([AB])*" # works
string <- paste0(rep("A", 1e4), collapse="")
grep(reg, string, perl=TRUE)
@brodieG
brodieG / valaddin-vetr-benchmrk.md
Created July 2, 2017 14:55
`valaddin` vs `vetr` performance.

Snippet used to compare valaddin to vetr performance. This is not actually generated as part of vignettes because it will then require valaddin as part of the build package, which brings in unwanted dependencies (via suggests) that make the build process slow on travis.

secant <- function(f, x, dx) (f(x + dx) - f(x)) / dx

secant_valaddin <- valaddin::firmly(secant, list(~x, ~dx) ~ is.numeric)
@brodieG
brodieG / datebw-vetr.R
Created July 26, 2017 16:09
Illustration on using `vetr` with `date_between`
date.2 <- rep(Sys.Date(), 2) # length 2 date object
date.1 <- date.2[1]
valid_identifier_regex <- function() "^\\w+$"
date_between <- function(column_name, date_range) {
vetr(
character(1L) && grepl(valid_identifier_regex(), .),
(date.2 || date.1) && !anyNA(.)
)
TRUE
@brodieG
brodieG / Blinky-Verse.R
Last active November 9, 2017 23:36
A Blinking Tidyverse Logo
blinkyverse_logo <- function() {
logo <- c(tidyverse::tidyverse_logo(unicode=FALSE))
logoa <- gsub("*", "\u2b22", logo, fixed=TRUE)
logoa <- gsub("o", "\u2b21", logoa, fixed=TRUE)
logob <- gsub("o", "\u2b22", logo, fixed=TRUE)
logob <- gsub("*", "\u2b21", logob, fixed=TRUE)
logob <- gsub(".", "*", logob, fixed=TRUE)