Skip to content

Instantly share code, notes, and snippets.

# list of lists
url <- "https://en.wikipedia.org/wiki/Lists_of_World_Heritage_Sites"
# Table of sites per country can be found at each of these pages
# probably the simplest entry point
# Africa
africa <- "https://en.wikipedia.org/wiki/List_of_World_Heritage_Sites_in_Africa"
# Americas
@benmarwick
benmarwick / point_dist_to_polygon.Rmd
Created February 16, 2019 10:45
Two methods to get distance from point to enclosing polygon boundary
---
title: 'C14 analysis: Coastal vs Inland'
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
Import and clean the data:
@benmarwick
benmarwick / wikipedia-page-edit-proportions.R
Last active February 11, 2019 13:10
Inspect the edit history of a bunch of wikipedia pages to measure the proportion of the page contributed by each editor
library(tidyverse)
the_pages <- c(
"https://en.wikipedia.org/wiki/Angela_McGowan",
"https://en.wikipedia.org/wiki/Caroline_Bird_(archaeologist)",
"https://en.wikipedia.org/wiki/Jo_McDonald",
"https://en.wikipedia.org/wiki/Laurajane_Smith",
"https://en.wikipedia.org/wiki/Louise_Zarmati",
"https://en.wikipedia.org/wiki/Marcia-Anne_Dobres",
"https://en.wikipedia.org/wiki/Sarah_Colley",
@benmarwick
benmarwick / academicjobs.wikia.com.R
Last active April 7, 2023 17:17
Scraping academic jobs on wikia.com
library(tidyverse)
base_url <- "http://academicjobs.wikia.com/wiki/Archaeology_Jobs_"
# starts at 2010-2011
years <- map_chr(2010:2019, ~str_glue('{.x}-{.x +1}'))
# though it seems to start at 2007-8: https://academicjobs.fandom.com/wiki/Archaeology_07-08
urls_for_each_year <- str_glue('{base_url}{years}')

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 April 23, 2024 01:28
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) {