Skip to content

Instantly share code, notes, and snippets.

@benjamin-chan
benjamin-chan / logo_library.lgo
Last active October 28, 2019 05:12
Hazel's LOGO code
to bcd:continue
start_mazegaze
end
to bcd:instructions
cs right 90 label "every_command_will_start_with_BCD:_or_will_be_a_random_series_of_letters. wait 275 cs right 90 label "Dont_be_confused_by_this._it's_for_programming_reasons. wait 275 cs right 90 label "the_computer_will_show_you_a_maze_for_several_seconds. wait 275 cs right 90 label "then_it_will_ask_you_how_to_solve_the_maze. wait 275 cs right 90 label "Solve_it_right_or_you'll_have_to_start_over. wait 275 cs right 90 label "type_BCD:continue
end
to bcd:start
cs bk 100 fd 160 pu fd 40 pd rt 90 fd 80 pu fd 40 pd fd 80 rt 90 fd 200 rt 90 fd 200 rt 90 fd 160 rt 90 fd 40 bk 40 rt 90 fd 80 lt 90 fd 40 lt 90 fd 80 lt 90 fd 40 rt 90 pu fd 40 rt 90 fd 80 rt 90 pd fd 160 rt 90 fd 40 pu bk 80 rt 90 pd fd 120 rt 90 fd 40 rt 90 fd 120 rt 90 fd 40 rt 90 fd 120 lt 90 fd 40 rt 90 fd 40 pu fd 40 rt 90 fd 10 pd label "s wait 375 cs
@benjamin-chan
benjamin-chan / lastDayOfMonth.R
Last active October 23, 2019 17:30
Last day of month function
lastDayOfMonth <- function (date = Sys.Date()) {
require(magrittr)
require(lubridate)
date %>%
format("%Y-%m") %>%
sprintf("%s-01", .) %>%
as.Date() %>%
+ lubridate::period(1, "month") - 1
}
# lastDayOfMonth()
@benjamin-chan
benjamin-chan / OHA_palette.R
Last active October 12, 2021 20:29
OHA color palette
pal <- c(rgb( 0, 85, 149, maxColorValue = 255), # Medium Electric Blue "#005595"
rgb(236, 137, 2, maxColorValue = 255), # Tangerine "#EC8902"
rgb(125, 168, 48, maxColorValue = 255), # Green (RYB) "#7DA830"
rgb( 0, 136, 184, maxColorValue = 255), # Blue (NCS) "#0088B8"
rgb( 83, 109, 96, maxColorValue = 255), # Stormcloud "#536D60"
rgb(160, 28, 63, maxColorValue = 255), # Deep Carmine "#A01C3F"
rgb( 30, 25, 77, maxColorValue = 255), # Space Cadet "#1E194D"
rgb(100, 100, 100, maxColorValue = 255), # Granite Gray "#646464"
rgb(127, 127, 127, maxColorValue = 255), # Gray (HTML/CSS Gray) "#7f7f7f"
rgb(166, 166, 166, maxColorValue = 255), # Quick Silver "#A6A6A6"
@benjamin-chan
benjamin-chan / simulation.md
Last active June 10, 2019 23:17
Game show simulation

Simulate a game show

Rules

  • 3 players
  • 3 doors, prize is behind one of the doors
  • 1st player chooses a door
  • If 1st player chooses the winning door, then game ends
  • If 1st player does not choose the winning door, then game continues
  • 2nd player chooses a door
library(checkpoint)
checkpoint("2018-01-01")
library(magrittr)
library(tidyverse)
library(knitr)
library(DiagrammeR)
library(devtools)
sessionInfo()
install.packages("cluster")
install.packages("ggdendro")
install.packages("factoextra")
library(cluster)
library(ggdendro)
library(factoextra)
hc <-
df %>%
select(-id) %>%
@benjamin-chan
benjamin-chan / quickPick.R
Last active February 6, 2018 22:58
Simulate frequency of lottery quick picks
library(checkpoint)
checkpoint("2018-01-01")
library(magrittr)
library(tidyverse)
library(parallel)
library(doParallel)
s <- 1e6 # Number of lottery tickets
cores <- detectCores()
clear
use "C:\Users\chanb\Box Sync\Share\BDPDropIn\Hinson\Simple_GCS.dta"
bysort recordid : egen meanGCS = mean(gcs)
bysort recordid : egen sdGCS = sd(gcs)
bysort recordid : egen countNonMissingGCS = count(gcs)
gen group1 = 0
replace group1 = 1 if sdGCS == 0 /* Assign to group1 if all GCS values are the same */
bysort recordid : egen minGCS = min(gcs) /* Calculate minimum GCS */
@benjamin-chan
benjamin-chan / scanFilm.md
Last active August 20, 2020 14:46
Convert film sizes from scanning to printing
library(magrittr)
library(dplyr)
library(knitr)

ratio <- 1 / 25.4  # in to mm conversion ratio
df <- 
  expand.grid(edge = c("Short", "Long"),
              film = c("35mm", "6X6", "6X7", "4X5"),
              dpiScan = 800 * (2 ^ seq(0, 3)),

Developing BW film

  • Paterson tank
  • 10 oz (300 ml) per roll
  1. Developer
  • Varying times; see Massive Dev Chart
  • Agitate for 30 sec
  • Put tank down sharply to pop bubbles
  • Agitate 10 sec every 60 sec