Skip to content

Instantly share code, notes, and snippets.

View geotheory's full-sized avatar

Robin Edwards geotheory

View GitHub Profile
breed name owner ticket cabin kenneled survived
King Charles Spaniel NA William Ernest Carter 113760 B96 B98 TRUE FALSE
Airedale Terrier NA William Ernest Carter 113760 B96 B98 TRUE FALSE
Chow Chow Chow-Chow Harry Anderson 19952 E12 TRUE FALSE
French Bulldog Gamin de Pycombe Robert Williams Daniel 113804 A TRUE FALSE
Airedale Terrier Kitty John Jacob Astor 11754 C62 TRUE FALSE
Pomeranian Bebe/Lady Margaret Bechstein Hays 11767 C54 FALSE TRUE
Pomeranian NA Elizabeth Jane Anne Rothschild 17603 C FALSE TRUE
Pekingese Sun Yat Sen Henry Sleeper Harper & Myra Raymond Harper 17572 D33 FALSE TRUE
toy dog Freu Freu Helen Margaret Bishop 11967 B49 FALSE FALSE
# remotes::install_github("moodymudskipper/safejoin")
require(safejoin)
require(tidyverse)
#> Loading required package: tidyverse
d1 = tibble(id = c(1,2,3), x = c('A','B','C'), y = c(5,7,9))
d2 = tibble(id = c(2,3,4), x = c('B','CC','D'), y = c(7,9,11))
safe_full_join(d1, d2, by = 'id', conflict = ~ coalesce(.y, .x))
# string markdown to html conversion (HT https://github.com/matt-dray)
purrr::map_chr(
c("# title", "regular **bold**"),
~ markdown::renderMarkdown(text = .x)
)
#> [1] "<h1>title</h1>\n"
#> [2] "<p>regular <strong>bold</strong></p>\n"
// debug javscript errors with alerts
window.onerror = function (msg, url, lineNo, columnNo, error) {
var error_msg = ['msg: ' + msg, 'url: ' + url, 'lineNo: ' + lineNo, 'columnNo: ' + columnNo, 'error: ' + error].join('\n');
window.alert(error_msg);
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="//cdn.jsdelivr.net/npm/[email protected]/dist/phaser.js"></script>
<!-- <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/phaser-arcade-physics.min.js"></script> -->
</head>
<body>
<div id="game-area"></div>
<h1 style="left: 20px; top: 20px; position:absolute;">Mouse</h1>
// stringify an even object for inspection
function stringifyEvent(e) {
const obj = {};
for (let k in e) {
obj[k] = e[k];
}
return JSON.stringify(obj, (k, v) => {
if (v instanceof Node) return 'Node';
@geotheory
geotheory / sitemap.R
Created February 19, 2021 22:24
R sitemap generator
# source: https://github.com/jeroen/curl/blob/master/examples/sitemap.R
#
### R sitemap example, Jeroen Ooms, 2016
#
# This code demonstrates the new multi-request features in curl 2.0. It creates
# an index of all files on a web server with a given prefix by recursively following
# hyperlinks that appear in HTML pages.
#
# For each URL, we first perform a HTTP HEAD (via curlopt_nobody) to retrieve
# the content-type header of the URL. If the server returns 'text/html', then we
require(raster, quietly=T)
require(dplyr, quietly=T, warn.conflicts=F)
download.file('https://data.worldpop.org/GIS/Population/Global_2000_2020/2020/LBN/lbn_ppp_2020_UNadj.tif',
destfile = 'lebanon-pops.tif')
download.file('https://data.worldpop.org/GIS/Pixel_area/Global_2000_2020/LBN/lbn_px_area_100m.tif',
destfile = 'lebanon-areas.tif')
pop_grid <- raster('lebanon-pops.tif')
area_grid <- raster('lebanon-areas.tif') / 1000000 # square meters to kms
# dummy dataset
require(gutenbergr)
d = ggplot2::diamonds
d$txt = gutenberg_download(1184)$text[1:nrow(d)]
filename = "~/Downloads/dat.csv"
readr::write_csv(d, filename)
#-------------------