Skip to content

Instantly share code, notes, and snippets.

@cdmh
cdmh / gist:4906f4144858a45907116b49d92c172b
Created August 11, 2017 20:25
convert parkrun results web page to CSV
library(tidyverse)
library(htmltab)
# right-click and save HTML
# this is the results page, e.g. http://www.parkrun.org.uk/henleyonthames/results/weeklyresults/?runSeqNumber=2
doc <- read_file("results _ henleyonthames parkrun_2.html")
df <- as_tibble(htmltab(doc=doc, which="//table[@id='results']"))
colnames(df) <- c("pos", "name", "time", "age_cat", "age_grade", "gender", "gender_pos", "note", "total_runs")
df$pos <- as.numeric(df$pos)
@cdmh
cdmh / sorted_vector.h
Created August 31, 2016 16:42
Functions to keep a vector of pair<Key,Value> sorted by Key. Can replace a std::map for performance or space saving, depending on use case
// sorted vector functions
template<typename Key, typename T>
typename std::vector<std::pair<Key, T>>::iterator
lookup(std::vector<std::pair<Key, T>> &vec, Key key)
{
auto const end = vec.end();
auto it = lower_bound(vec.begin(), end, key, [](std::vector<std::pair<Key, T>>::value_type const &elem, Key key) {
return elem.first < key;
});
@cdmh
cdmh / makefile
Last active December 20, 2021 11:53
A Super-Simple Makefile for Medium-Sized C/C++ Projects
# From https://spin.atomicobject.com/2016/08/26/makefile-c-projects/
TARGET_EXEC ?= a.out
BUILD_DIR ?= ./build
SRC_DIRS ?= ./src
SRCS := $(shell find $(SRC_DIRS) -name *.cpp -or -name *.c -or -name *.s)
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)