Skip to content

Instantly share code, notes, and snippets.

Avatar

Colin grosscol

View GitHub Profile
@grosscol
grosscol / rosenbrock.r
Last active Oct 2, 2020
Rosenbrock Function
View rosenbrock.r
rosen_height <- function(x,y) {
100 * (y-x^2)^2 + (1-x)^2
}
gradient <- function(x,y) {
val_x <- -400*x*(y-x^2)-2*(1-x)
val_y <- 200*(y-x^2)
return( c(val_x, val_y) )
}
@grosscol
grosscol / get-cognito-cfd-target.yaml
Last active Oct 2, 2020
Custom Cloudformation Resource to get CloudFront Distribution of Cognito User Pool
View get-cognito-cfd-target.yaml
---
#
# This template example assumes a UserPool and UserPoolDomain exist.
# The function of this is to produce a custom resource with an attribute
# that can be referenced for DNSName of an Route53::RecordSet AliasTarget.
#
# AliasTarget:
# HostedZone: Z2FDTNDATAQYW2
# DNSNAME: !GetAtt UPDomain.CloudFrontDistribution
@grosscol
grosscol / .Rprofile
Created Sep 19, 2019
.Rprofile with custom lib path
View .Rprofile
options(
repos = c(CRAN = "https://cran.rstudio.com/"),
browserNLdisabled = TRUE,
deparse.max.lines = 2)
# Set lib path
.libPaths( "~/R/x86_64-pc-linux-gnu-library/dev/" )
if (interactive()) {
suppressMessages(require(devtools))
@grosscol
grosscol / pnorm_explore.R
Last active Sep 7, 2019
Exploring rnorm
View pnorm_explore.R
# regarding: https://www.reddit.com/r/Rlanguage/comments/d0ytw7/issues_of_bias_with_rnorm/
# set the RNG seed so the results are reporducible
set.seed(12345)
# Generate 100 target means beteen 0 and 100 from the uniform distribution
generated_means <- runif(100, 0, 100)
# Generate 100 standard deviation values also from uniform distribution
generated_sdev <- runif(100, 1, 20)
@grosscol
grosscol / target.sh
Last active Jul 31, 2019
Hacking at alternatives for symbolic link resolution that work across OSX, BSD, and GNU.
View target.sh
#!/bin/bash
# Consider the following structure where this script is target.sh
# /tmp/
# ├── target.sh
# └── l1
#    ├── one.sh -> ../target.sh
#    └── l2
# └── two.sh -> ../one.sh
# From your home directory run:
@grosscol
grosscol / performance_dimension.json
Last active Apr 22, 2019
Illustrating performance as a dimension or not.
View performance_dimension.json
{
"MAPT_data_points":[
{ "performer": "Alice",
"time": "2019-01-01",
"measure": "Documentation Rate",
"performance": "0.90"
},
{ "performer": "Alice",
"time": "2019-02-01",
"measure": "Documentation Rate",
View str_combinations.R
library(gtools)
demo_input <- c("fname midname lname","doe john e") #only 2 'names' in this example list.
split_list <- strsplit(demo_input, " |-")
make_combinations <- function(x){
# Use permutations from the gtools package
name_grid <- permutations(3,3,x)
apply(X=name_grid, MARGIN=1, FUN=paste0, collapse=' ')
@grosscol
grosscol / draw_shape.R
Created Jan 30, 2019
R homework help: monospace ascii art
View draw_shape.R
# DrawShape
#' @title Draw Shape
#' @param n height of shape in number of rows
#' @description If n is odd, draw a diamond pattern.
#' If n is even, draw an hourglass pattern.
#' @note e.g. n = 6
#' #####
#' ###
#' #
@grosscol
grosscol / munge_mapt_obs.r
Created Jul 30, 2018
Munge mapt obs from tape format to data table.
View munge_mapt_obs.r
library(readr)
library(dplyr)
library(tibble)
# Input CSV
input_path <- '/tmp/dahee_coding.csv'
input_df <- read_csv(input_path)
# Veena's observations are row 1
@grosscol
grosscol / bkgd_ave.R
Created Apr 24, 2018
Background mean per id from count data.
View bkgd_ave.R
library(tibble)
library(dplyr)
count_data <- tibble::tribble(
~id, ~numerator, ~denominator,
"Aly", 14, 20,
"Aly", 13, 20,
"Aly", 12, 20,
"Bob", 11, 20,
"Bob", 12, 20,
You can’t perform that action at this time.