Skip to content

Instantly share code, notes, and snippets.

View mmuurr's full-sized avatar

Murat Tasan mmuurr

  • atop my bicycle saddle
View GitHub Profile

Notation

  • 0 = red
  • 1 = green

The three 'players' are Pa, Pb, and Pc.

Complete global space knowledge (pre-blindfold)

Before any blindfolds are removed, and even before any dots are painted, we have the complete set of possibilities as:

@mmuurr
mmuurr / tidyeval-in-dplyr-speed.r
Created January 23, 2021 22:55
tidyeval speed penalty in dplyr
x <- iris
present_names <- c("Sepal.Width", "Sepal.Length")
microbenchmark::microbenchmark(
dplyr::select(x, present_names),
dplyr::select(x, dplyr::all_of(present_names)),
x[present_names],
x[,present_names]
)
@mmuurr
mmuurr / libpq-test.c
Created December 4, 2017 05:00
testing Redshift vs PostgreSQL transactions
#include <stdio.h>
#include <stdlib.h>
#include <libpq-fe.h>
static void error_exit(PGconn *conn) {
PQfinish(conn);
exit(1);
}
int main(int argc, char **argv) {
@mmuurr
mmuurr / cursor-test.c
Created December 3, 2017 02:22
testing Redshift vs PostgreSQL cursor-declaration patterns
#include <stdio.h>
#include <stdlib.h>
#include <libpq-fe.h>
static void error_exit(PGconn *conn) {
PQfinish(conn);
exit(1);
}
int main(int argc, char **argv) {
@mmuurr
mmuurr / cursor-test.c
Created December 3, 2017 01:34
libpq cursor test
#include <stdio.h>
#include <stdlib.h>
#include <libpq-fe.h>
static void error_exit(PGconn *conn) {
PQfinish(conn);
exit(1);
}
int main(int argc, char **argv) {
@mmuurr
mmuurr / README
Last active December 21, 2015 00:01
auto-JSON-ifying behaves inconsistently with vectors of length 0, 1, and 2+.
Put test.js in www/ directory for the Shiny app.
Look at console output for different input values.
When input value is 0, the returned value is an object (empty array).
When input value is 1, the returned value is a string.
When input value is >1, the returned value is back to being an object (a populated array).
This forces parsing of returned values that may vary in the length to include conditional logic, which is unneeded complexity.
Proposal: the returned JSON value should conform to jsonlite's default behavior.
## create a boatload of non-trivial functions
my_functions <- lapply(runif(1e6), function(i) function(x) x^i)
system.time(lapply(my_functions, function(f) f(2)))
## output:
## user system elapsed
## 1.370 0.023 1.398
x <- list(2)
system.time(lapply(my_functions, do.call, x))