Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am benmarwick on github.
  • I am benmarwick (https://keybase.io/benmarwick) on keybase.
  • I have a public key ASChwHLecS9Y85PZlJMPf64_Yl8wvwJzBPgrqfYkWbAWrwo

To claim this, I am signing this object:

@benmarwick
benmarwick / random-group-assignment.R
Last active October 2, 2023 05:53
Randomly assign students into seminar reading groups of equal sizes, different groups each week
# get canvas gradebook as CSV...
library(tidyverse)
students <-
readr::read_csv("2023-10-01T2053_Grades-ARCHY_482_A.csv") %>%
# exclude test student
filter(!is.na(`SIS User ID`)) %>%
select(Student) %>%
as.data.frame()
@benmarwick
benmarwick / .spacemacs
Created January 6, 2019 09:49
My Spacemacs config
;; -*- mode: emacs-lisp -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
;; restart after editing with SPC f e R or SPC q R
(defun dotspacemacs/layers ()
"Configuration Layers declaration.
You should not put any user code in this function besides modifying the variable
values."
(setq-default
@benmarwick
benmarwick / object-outline-and-dimensions-opencv.py
Last active January 18, 2025 20:39
Python 3 script to take live video, detect the largest object, trace an outline (contour) and measure linear dimensions, using OpenCV
# in a terminal
# python -m pip install --user opencv-contrib-python numpy scipy matplotlib ipython jupyter pandas sympy nose
import cv2
import pandas as pd
import numpy as np
import imutils
from scipy.spatial import distance as dist
from imutils import perspective
@benmarwick
benmarwick / super-and-sub-script-labels.R
Last active April 11, 2024 23:09
ggplot axis labels with superscript and subscript
library(tidyverse)
# using expression() for the text formatting:
ggplot(mtcars,
aes(disp,
mpg)) +
geom_point() +
# ~ for spaces, and * for no-space between (unquoted) expressions
ylab(expression(Anthropogenic~SO[4]^{"2-"}~(ngm^-3))) +
xlab(expression(italic(delta)^13*C[ap]*"‰")) +
# from http://my.ilstu.edu/~wjschne/444/IndependentSamples.html#(19)
t.report <- function(tt){
tvalue <- tt$statistic %>% formatC(digits = 2, format = "f")
pvalue <- tt$p.value %>% formatC(digits = 2, format = "f")
if (round(tt$parameter, 0) == tt$parameter) {
df <- tt$parameter
} else {
df <- formatC(digits = 2, format = "f")
}
if (tt$p.value < 0.0005) {
@benmarwick
benmarwick / gist:59fb24825693ed615f64a96b8532bea4
Last active December 9, 2018 07:13
Atom for scholarly writing
For writing we will use: https://atom.io/
Background reading:
- http://u.arizona.edu/~selisker/post/workflow/
- https://programminghistorian.org/en/lessons/sustainable-authorship-in-plain-text-using-pandoc-and-markdown
- http://plain-text.co
- https://the-javascripting-english-major.org/1-environment
- https://discuss.atom.io/t/using-atom-for-academic-writing/19222?u=benmarwick
@benmarwick
benmarwick / violin-prices.R
Last active April 29, 2023 21:40
Get violin auction prices from a few websites and plot
library(rvest)
url <- "https://www.maestronet.com/history/makers_list.cfm?ID=1"
links_on_page <-
url %>%
read_html() %>%
html_nodes(".text a") %>%
@benmarwick
benmarwick / gist:e4fa3fdcbf328d6ef6e38f219e9f8a2a
Last active April 29, 2023 21:35
Plot time series of emails resulting from a search, in this case my emails about ARCHY 109 during the Fall quarter of 2018
# get the dates of all emails with a certain search string, and plot
# install.packages(c("gmailr", "lubridate", "tidyverse"))
suppressPackageStartupMessages(library(gmailr))
suppressPackageStartupMessages(library(tidyverse))
archy_109 <-
messages(
search = 'ARCHY 109',
num_results = 1000,
@benmarwick
benmarwick / BITSS-NTU-workshop.R
Created September 16, 2018 17:36
Code for workshop on R for archaeologists at the National Taiwan University as part of my BITSS series
# load the libraries
library(tidyverse)
library(readxl)
# load the data
pottery <-
read_excel("data/HTSKY-RIM.xlsx",
col_types = "text")