Skip to content

Instantly share code, notes, and snippets.

View grosscol's full-sized avatar

Colin grosscol

View GitHub Profile
@grosscol
grosscol / output.txt
Created November 19, 2022 19:09
Compare attributes of candidate against all pathways requirements.
Pathways-attributes matrix
A B C
p0 0 0 0
p1 0 0 1
p2 0 1 0
p3 1 0 0
p4 0 1 1
p5 1 0 1
p6 1 1 0
p7 1 1 1
@grosscol
grosscol / get-cognito-cfd-target.yaml
Last active October 5, 2022 06:47
Custom Cloudformation Resource to get CloudFront Distribution of Cognito User Pool
---
#
# 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 / simple_agent_meetings.R
Created August 31, 2022 03:10
Making a simple agent meeting simulation on Discord
# Generate single round of meetings.
# from a data frame with `agentNo` and `state` cols.
generate_meetings <- function(agent_df){
# 1 Make a list of Buyer agents
is_a_buyer <- agent_df$state == "Buyer"
buyers_ids <- agent_df[is_a_buyer, c('agentNo')]
# 2 Make list of Seller agents
is_a_seller <- agent_df$state == "Seller"
sellers_ids <- agent_df[is_a_seller, c('agentNo')]
@grosscol
grosscol / assigner.R
Created February 22, 2022 20:04
Simple Group Assignments
# Author: Colin Gross
# Date: 2022-02-22
#' Simple group assignments.
#' Randomly order equally distributed group ids
#' @param num_groups Number of study groups
#' @param num_per_group Number of individuals per group.
#' @return named vector of randomly selected group assignments.
simple_grp_assignments <- function(num_groups, num_per_group){
num_indv <- num_groups * num_per_group
@grosscol
grosscol / SampleBirdData.txt
Last active October 20, 2021 22:38
Refactor nested for loop into smaller testable functions
structure(list(StandID = c("BEF 15", "NUL 10", "BEF 16", "NUL 2",
"BEF 17", "NUL 8", "BEF 17", "BEF 17", "BEF 14", "NUL 14", "NUL 1",
"NUL 13", "NUL 15", "NUL 6", "NUL 13", "BEF 11", "BEF 14", "NUL 15",
"BEF 16", "BEF 3", "NUL 14", "BEF 3", "BEF 14", "NUL 3", "BEF 11",
"BEF 2", "NUL 2", "BEF 16", "BEF 8", "BEF 3", "BEF 8", "NUL 4",
"BEF 9", "BEF 17", "BEF 7", "NUL 14", "BEF 17", "NUL 10", "NUL 4",
"NUL 13", "NUL 9", "NUL 10", "BEF 3", "BEF 2", "BEF 3", "NUL 13",
"NUL 15", "NUL 6", "NUL 4", "NUL 7", "BEF 11", "NUL 10", "NUL 5",
"NUL 9", "BEF 1", "NUL 12", "NUL 5", "BEF 8", "NUL 7", "NUL 8",
"BEF 9", "BEF 1", "NUL 2", "NUL 8", "BEF 7", "BEF 8", "BEF 9",
@grosscol
grosscol / rosenbrock.r
Last active October 2, 2020 02:24
Rosenbrock Function
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 / .Rprofile
Created September 19, 2019 14:16
.Rprofile with custom lib path
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 September 7, 2019 22:06
Exploring rnorm
# 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 July 31, 2019 18:05
Hacking at alternatives for symbolic link resolution that work across OSX, BSD, and GNU.
#!/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 / rubobadcop_spec.rb
Created September 4, 2015 19:54
Rubocop & Rspec headache with testing a module
# I either end up with a rubocop error or an rspec error. In each case, the travis build will not pass.
# Rubocop error:
# RSpec/DescribedClass: Use described_class instead of Hydra::Works::GenericFile::Characterization
describe Hydra::Works::GenericFile::Characterization do
let(:demo_class) do
Class.new(Hydra::Works::GenericFile::Base) do
include Hydra::Works::GenericFile::Characterization
end
end