Skip to content

Instantly share code, notes, and snippets.

View mpettis's full-sized avatar

Matt Pettis mpettis

  • Personal
  • Minneapolis, MN
View GitHub Profile
@clarle
clarle / hour_summary.R
Last active September 14, 2018 21:50
Summing hours in HH:MM:SS format in R
library(dplyr)
library(tidyr)
library(lubridate)
# Parse data from HH:MM:SS format into something that can be used by `lubridate`
hours %>%
separate(Duration, into = c("hours", "minutes", "seconds"), sep = ":", convert = TRUE) %>%
summarize(total_time = duration(hour = sum(hours), minute = sum(minutes), second = sum(seconds)))
@dgrtwo
dgrtwo / comparing-polynomial-models-covid.R
Created May 5, 2020 19:33
Comparing the CEA's "cubic model" to quadratic and quartic models
library(tidyverse)
library(broom)
US <- read_csv("https://raw.githubusercontent.com/nytimes/covid-19-data/master/us.csv") %>%
mutate(new_deaths = deaths - lag(deaths)) %>%
filter(date >= "2020-02-26")
models <- tibble(degrees = 2:4) %>%
mutate(model = map(degrees, ~ lm(log(new_deaths + 1) ~ poly(date, .), data = US)))
import numpy as np
import tensorflow as tf
def dense(x, weights, bias, activation=tf.identity, **activation_kwargs):
"""Dense layer."""
z = tf.matmul(x, weights) + bias
return activation(z, **activationn_kwargs)
@mrrodriguez
mrrodriguez / clara_tiered_fact_update_rules.clj
Last active July 1, 2020 18:07
Clara tiered fact update rules
(require '[clara.rules :as r])
;;;; Define 3 rules, where the "priority" order is r1, r2, r3, where the highest priority is first
;;;; and the rest is in descending order of priority.
;;;; :type :rule/result "syntetic" fact is used to hold the final changes that can be queried out
;;;; from a session after `r/fire-rules` via `r/query` on the `find-results` query.
;;;; A namespace qualified keyword is used to avoid collision with externally given :type of
;;;; "real" facts.
``` r
library(ggplot2)
library(dplyr)
library(magick)
library(patchwork)
library(gt)
library(ggtext)
mtcars %>%
head() %>%
library(tidyverse)

lag_multiple <- function(x, n_vec){
  map(n_vec, lag, x = x) %>% 
    set_names(paste0("lag", n_vec)) %>% 
    as_tibble()
}

tibble(x = 1:30) %&gt;% 
@djnavarro
djnavarro / ggplot2_geomvector.R
Created March 30, 2019 03:30
Custom ggplot2 geom that plots a (subset of a) vector field
library(ggplot2)
library(dplyr)
library(tibble)
library(tidyr)
GeomVector <- ggproto("GeomVector", Geom,
required_aes = c("x", "y", "direction", "length"),
default_aes = aes(
@dewittpe
dewittpe / build-script.R
Last active November 28, 2021 15:47
Equation Numbering in Rmd
library(rmarkdown)
library(knitr)
render("eqn-numbering.Rmd")

Kim's Very Long and Boring Email Text File about File Versioning and Servers.

Hello all.

This is A Very Long and Boring Email Text File about File Versioning and Servers.

Please feel free to point and laugh, but this is all stuff that I've learnt the hard way, and that we should start to do as we get bigger. It doesn't take long for all this to become a habit; something you don't even think about doing. When it's working properly, it offloads a load of organisational stuff from your brain, too - which is nice, and what computers should help you do.