Skip to content

Instantly share code, notes, and snippets.

View geotheory's full-sized avatar

Robin Edwards geotheory

View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="//cdn.jsdelivr.net/npm/phaser@3.52.0/dist/phaser.js"></script>
<!-- <script src="https://cdn.jsdelivr.net/npm/phaser@3.52.0/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)
#-------------------
@geotheory
geotheory / pandoc.css
Created January 7, 2021 14:45 — forked from killercup/pandoc.css
Add this to your Pandoc HTML documents using `--css pandoc.css` to make them look more awesome. (Tested with Markdown and LaTeX.)
/*
* I add this to html files generated with pandoc.
*/
html {
font-size: 100%;
overflow-y: scroll;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
}
# test if a file is a valid zip archive
# can be used to distinguish old MS documents from current xml formats (e.g. doc from docx)
valid_zip = function(filepath, zippath = "/usr/bin/zip"){
zip_status = suppressWarnings(system(paste0(zippath, ' -T "', filepath, '"'), intern = TRUE))
return(length(stringr::str_subset(zip_status, 'OK$')) > 0)
}
# e.g.
# valid_zip("file.doc")
require(tidyverse)
mm_ratio = function(x) mean(x) / median(x)
x = map(10^seq(2,6,length.out = 200), ~ list(unif = runif(.x), exp = rexp(.x), log = rlnorm(.x)))
d = x %>% map_df(~ tibble(n = length(.x$unif),
unif = mm_ratio(.x$unif),
exp = mm_ratio(.x$exp),
log = mm_ratio(.x$log)))
require(robotstxt)
#> Loading required package: robotstxt
rt = robotstxt::get_robotstxt('bbc.com')
paths_allowed('https://bbc.com/notexists', rt_robotstxt_http_getter = rt)
#> bbc.com
#>
#> [1] TRUE
#acad1a
#a55151
#be551e
#b0bb1e
#ca551e
#debb1e
#0de55a
#aba5ed
#acac1a
#accede