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
library(tidyverse) | |
set.seed(7) | |
N = 1000 | |
x = rnorm(N) | |
p = plogis(0.2*x - 0.8) | |
y = rbinom(N, 1, p) | |
tibble(x, y) %>% | |
mutate(z = cut_number(x, 5)) %>% |
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
// 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); | |
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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/[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> |
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") |