Skip to content

Instantly share code, notes, and snippets.

Avatar

Noam Ross noamross

View GitHub Profile
@noamross
noamross / test-dolt.R
Created Sep 1, 2021
Reprex of trying to write data to Dolt with RMariaDB
View test-dolt.R
library(sys)
library(RMariaDB)
library(DBI)
library(withr)
# Clean up from previous session
unlink("doltdb", recursive = TRUE)
try(dbDisconnect(conn), silent = TRUE)
@noamross
noamross / toggle-radio-layer-legends.R
Created Aug 13, 2021
A quick hack to have the legends associated with radio-button "Base Groups" in R leaflet maps toggle along with layers
View toggle-radio-layer-legends.R
library(leaflet)
library(tidyverse)
outline <- quakes[chull(quakes$long, quakes$lat),]
map <- leaflet(quakes) %>%
addTiles(group = "OSM (default)") %>%
# Overlay groups
addCircles(~long, ~lat, ~10^mag/5, stroke = F, group = "Quakes") %>%
addPolygons(data = outline, lng = ~long, lat = ~lat,
View mapbox-ontop.R
library(ggplot)
library(sf)
library(ggspatial)
library(snapbox)
library(raster)
worldclim <- raster::getData('worldclim', var='prec', res=2.5, lon = 142.61, lat = -23.64)
area <- st_bbox(
c(xmin = 101.03, ymin = -44.82, xmax = 168.23, ymax = -9.09),
View preprocess_zipped_data.sh
#!/bin/bash
funzip $1| # uncompress first file in zip
tr -d '\000' | #remove null characters
sed "/^\s*$/d; s/ \{1,\}\t/\t/g; s/\t \{1,\}/\t/g; s/\r//" | #removes empty lines, whitespace around tabs, extra newlines
cut -s -f 1,3,4,5,6,8,12,13,14,15,16,17,18,19,20,21,23,24,25,26,34,35,36,38,40,42,44,45,46,85,86,87,88,89 #| #only select certain columns
pv -N Process -c |
gzip -9 |
pv -N Compress -c > $1.gz
@noamross
noamross / smooth_re2.R
Created Jun 12, 2020
Smooth construct, predict, and plot for random effects with numeric inputs
View smooth_re2.R
#' Create a random effect basis with integers rather than factors
#' @import mgcv
#' @export
smooth.construct.re2.smooth.spec <- function (object, data, knots) {
if (!is.null(object$id))
stop("random effects don't work with ids.")
if(any(sapply(data, is.numeric))) data <- lapply(data, as.factor) ## <-- All I did was this (and below)
form <- as.formula(paste("~", paste(object$term, collapse = ":"),
"-1"))
object$X <- model.matrix(form, data)
@noamross
noamross / partition.R
Last active Oct 27, 2020
A quick greedy algorithm to partition unequal-sized groups into near-equal shards
View partition.R
#' Function to partition unequal sized groups into shards of similar size.
#'
#' Based on the greedy algorithm described in [The Wikipedia article on the
#' the partitioning problem](https://en.wikipedia.org/wiki/Partition_problem#The_greedy_algorithm)
#'
#' @param groups_vector An integer vector of group ids, such as a group ID
#' column in a data frame
#' @param n_shards The number of shards to split groups up into
#' @examples
#' n_groups <- 200
View keybase.md

Keybase proof

I hereby claim:

  • I am noamross on github.
  • I am noamross (https://keybase.io/noamross) on keybase.
  • I have a public key ASB-BxfY2ry-bqcNtfdHGtsrS2Xwb0kBX2i_fgE1znBsSQo

To claim this, I am signing this object:

@noamross
noamross / test.Rmd
Last active Apr 3, 2019
flexdashboard/shiny tests
View test.Rmd
---
title: "test"
output:
flexdashboard::flex_dashboard:
orientation: rows
runtime: shiny
---
```{r setup, include = FALSE}
library(shiny)
@noamross
noamross / criticmarkup.lua
Last active Jun 16, 2021
A pandoc filter for MS Word track changes to criticmarkup
View criticmarkup.lua
-- a lua filter for panodoc
-- run pandoc your_word_doc.docx --track-change=all -t markdown --lua-filter=criticmarkup.lua
-- TODO: Detect substitutions in adjacent insertion/deletions
-- TODO: capture whole comment hightlight rather than just start point of comment
function Span(elem)
if elem.classes[1] and elem.classes[1] == "insertion" then
local opener = { pandoc.RawInline(FORMAT, "{++ ") }
local closer = { pandoc.RawInline(FORMAT, " ++}") }
return opener .. elem.content .. closer
elseif
@noamross
noamross / test.Rmd
Last active Oct 27, 2018
Test RVG PPTx
View test.Rmd
---
title: "Test RVG pptx"
output:
powerpoint_presentation:
keep_md: TRUE
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(ggplot2)