This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) | |
#------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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%; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#acad1a | |
#a55151 | |
#be551e | |
#b0bb1e | |
#ca551e | |
#debb1e | |
#0de55a | |
#aba5ed | |
#acac1a | |
#accede |