Skip to content

Instantly share code, notes, and snippets.

View geotheory's full-sized avatar

Robin Edwards geotheory

View GitHub Profile
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)) %>%
@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%;
}
@geotheory
geotheory / recursive_split
Created November 1, 2020 01:36 — forked from zachary-waller/recursive_split
Recursive Split: Split a dataframe into a nested list and reassemble back into a dataframe
library(purrr)
library(rrapply)
# Split a data frame into a nested list using a different column for each level.
# This uses rrapply::rrapply() to avoid having to do any nested loops (map, lapply,
# for loop, whatever).
# Nested lists can be useful for avoiding searching through your data: the data
# has already been indexed in the list. This can be pretty handy for saving time
# if you need to do lots of filtering stuff.
@geotheory
geotheory / snowflake.R
Created October 4, 2020 17:59 — forked from qykong/snowflake.R
twitter id decomposation in R
library(bit64)
twepoch <- as.integer64('1288834974657')
base <- as.integer64(2)
datacenter_id_bits <- 5
worker_id_bits <- 5
sequence_id_bits <- 12
max_datacenter_id <- 1 * base^datacenter_id_bits
max_worker_id <- 1 * base^worker_id_bits
max_sequence_id <- 1 * base^sequence_id_bits
@geotheory
geotheory / export-cognito-users.sh
Created February 24, 2020 09:27 — forked from chrisdiana/export-cognito-users.sh
Export AWS Cognito User Pool
# Export as Text Table
aws --region XXXXXXXXX cognito-idp list-users --user-pool-id XXXXXXXXXXXXX --output table > ~/users.txt
# Export as JSON
aws --region XXXXXXXXX cognito-idp list-users --user-pool-id XXXXXXXXXXXXX --output json > ~/users.json
# Export User Pool with more than 60 users (pagination)
aws --region XXXXXXXXX cognito-idp list-users --user-pool-id XXXXXXXXXXXXX --pagination-token INCREDIBLYLONGSTRINGHERE --output json > ~/users-2.json
@geotheory
geotheory / url_requests.js
Created January 31, 2018 11:16 — forked from anaynayak/url_requests.js
phantom.js script to log all http requests from a page
var page = require('webpage').create(),
system = require('system'),
address;
if (system.args.length === 1) {
console.log('Usage: phantomjs url_requests.js http://some.url.com');
phantom.exit(1);
} else {
address = system.args[1];
var logUrl = function (req) {
{"x": "dogs and cats"}
@geotheory
geotheory / readwrite_sf.R
Created April 4, 2017 07:43 — forked from zross/readwrite_sf.R
Read and write from R to postgresql/postgis
library(sf)
library(RPostgreSQL)
dat <- data.frame(ID = 1:2,
long = c(-74.003234, -73.983317),
lat = c(40.731863, 40.722684))
dat_sf <- st_as_sf(dat, coords = c("long", "lat"),
crs = 4326,
agr = "identity")
con <- dbConnect(PostgreSQL(), dbname = "mydb", host = "localhost")
st_write_db(con, dat_sf, "mydata")
@geotheory
geotheory / ggplot_resources.md
Created November 16, 2016 08:38 — forked from Pakillo/ggplot_resources.md
ggplot2: tutorials and complementary packages
@geotheory
geotheory / ubilinux-flashall-osx.diff
Last active October 31, 2016 01:11 — forked from ximus/ubilinux-flashall-osx.diff
get flashall.sh to work on osx
--- flashall.sh
+++ (clipboard)
@@ -220,15 +220,14 @@
flash-command --alt u-boot-env0 -D "${VARIANT_FILE}"
echo "Flashing U-Boot Environment Backup"
- flash-command --alt u-boot-env1 -D "${VARIANT_FILE}" -R
+ flash-command --alt u-boot-env1 -D "${VARIANT_FILE}"
echo "Rebooting to apply partition changes"
- dfu-wait no-prompt