Skip to content

Instantly share code, notes, and snippets.

@peterhurford
peterhurford / programming-checklist.md
Last active February 17, 2022 13:52
A programming checklist for you to fill out every time you make a pull request to make sure you end up with good code
  • Did you write tests? Are they mutually exclusive and collectively exhaustive? Do they pass?
  • Did you get a code review?
  • Have you verified that your code works, outside of tests?
  • Is your code DRY?
  • Did you follow the single responsibility principle at different levels of detail throughout all your functions, objects, files, folders, repositories, etc.?
  • Is your code readable? Can someone else tell you what it does?
  • Is your code self-documenting? Did you explain strange choices? Did you write documentation about how it works?
  • Do all your variables have self-explaining names?
  • Did you avoid writing overly long functions?
  • Do you document what your function inputs are? Are you explicit about what preconditions must be true about your function inputs? Are you explicit about what postconditions will hold about your function outputs, if the preconditions hold?
@peterhurford
peterhurford / parallelization.md
Created October 17, 2015 22:04
How does code get parallelized?

Computer code is a series of executed statements. Frequently, these statements are executed one at a time. If one part of your code takes a long time to run, the rest of your code won't run until that part is finished.

However, this isn't how it has to be. We can often make the exact same code go much faster through parallelization, which is simply running different parts of the computer code simaltaneously.

Asynchronous Code

The first example of this is asynchronous code. The idea here is that many times you do things like send a call to another computer, perhaps over the internet, using an API. Normally, code then has to simply wait for the other computer to give it a response over the API. But asynchronous code can simply keep on going and then the API call returns later.

This makes code harder to reason about and handle because you don't know when the API call will return or what your code will be like when it returns, but it makes your code faster because you don't have to wait arou

@peterhurford
peterhurford / open-source.md
Last active February 5, 2022 08:51
What is on an open source project website?: Five case studies

What is on an open source project website?: Five case studies

Looking at Rails, Angular, jQuery, Prediction.io, and Redis pages to find commonalities.

Lessons Learned

  • Layout matters. A nice layout inspires trust in your project.
  • Layout is similar. All the sites had a top bar with the prominent navigation. All the main pages had introductory text.
  • GitHub Issues is used ubiquitously for bug tracking.
  • IRC seems important for communities. Gitter seems like a good choice.
@peterhurford
peterhurford / r-interview.md
Last active January 12, 2022 21:55
R Interview Questions

1.) If I have a data.frame df <- data.frame(a = c(1, 2, 3), b = c(4, 5, 6), c(7, 8, 9))...

1a.) How do I select the c(4, 5, 6)?

1b.) How do I select the 1?

1c.) How do I select the 5?

1d.) What is df[, 3]?

@peterhurford
peterhurford / advanced-r-abridged.md
Last active June 2, 2021 17:26
Advanced R, Abridged

Advanced R, Abridged

"Advanced R" by Hadley Wickham is widely considered the best resource to improve your knowledge at R. However, going through it and answering every exercise takes a long time. This guide is designed to give you the most essential parts of Advanced R so that you can get going right away. It still will take a long time, but not as long.

--

1.) Quickly skim these chapters (without doing the exercises) to make sure you're familiar with the concepts:

@peterhurford
peterhurford / meat_consumption_kg_meat_per_capita_per_country.csv
Created April 17, 2017 00:51
Meat consumption (kg meat consumed per capita) per country
COUNTRY BEEF PIG POULTRY SHEEP TOTAL
ARG 40.41400058 8.24187459 36.4689953 1.174247185 86.29911766
AUS 22.8010372 20.25072536 42.00750521 7.423454044 92.48272181
BGD 0.885267859 5.14E-04 1.223173534 1.163676301 3.272631248
BRA 24.15640871 11.20721696 39.36312514 0.393513724 75.12026453
BRICS 4.289081407 15.79587836 10.29847417 1.654767905 32.03820184
CAN 17.37132968 15.74658647 34.15846671 0.81704465 68.09342751
CHL 14.96778476 17.51448686 30.93243359 0.411750266 63.82645548
CHN 3.817396071 31.56769795 11.61724318 2.965417779 49.96775498
COL 12.10121226 5.084564383 26.43592901 0.202352547 43.8240582
@peterhurford
peterhurford / data_science_101.md
Created May 4, 2017 18:12
Initial stab at a Data Science 101 Curriculum
@peterhurford
peterhurford / mint.R
Last active February 3, 2019 03:12
Look at Mint transaction data via R
## Load libraries
if (!require(readr)) { install.packages("readr") }; library(readr)
if (!require(magrittr)) { install.packages("magrittr") }; library(magrittr)
if (!require(dplyr)) { install.packages("dplyr") }; library(dplyr)
if (!require(tibbletime)) { install.packages("tibbletime") }; library(tibbletime)
if (!require(lubridate)) { install.packages("lubridate") }; library(lubridate)
if (!require(devtools)) { install.packages("devtools") }; library(devtools)
if (!require(shinyview)) { install_github("peterhurford/shinyview") }; library(shinyview)
## Load Mint transactions
@peterhurford
peterhurford / ballot_initiatives_model.R
Created December 17, 2018 02:37
Model predicting state-level ballot initiative outcomes
# Install and load libraries
if (!require("dplyr")) { install.packages("dplyr") }; library(dplyr)
if (!require("devtools")) { install.packages("devtools") }; library(devtools)
if (!require("readr")) { install.packages("readr") }; library(readr)
if (!require("recombinator")) { install_github("robertzk/recombinator") }; library(readr)
# Download data from https://docs.google.com/spreadsheets/d/1LzUHVgbyQddvESuW_WhJwNUn52023vYerlsho39em2I/edit#gid=0
states <- read_csv("~/Downloads/AR US States.csv")
@peterhurford
peterhurford / r-packages-abridged.md
Last active November 7, 2018 19:38
"R Packages" by Hadley Wickham, Abridged

R Packages, Abridged

Consider completing "Advanced R, Abridged" and "Git 101 Exercises" first.

"Advanced R" by Hadley Wickham is widely considered the best resource to improve your knowledge at building an R package. This guide is designed to give you the most essential parts of R Packages so that you can get going right away. It still will take a long time, but not as long.

--

  1. Read the following chapters of "R Packages" by Hadley Wickham: