Skip to content

Instantly share code, notes, and snippets.

View russellpierce's full-sized avatar

Russell S. Pierce russellpierce

View GitHub Profile
@russellpierce
russellpierce / package_combos.txt
Last active November 11, 2022 16:17
DuckDb ds hang
docker run --rm -it python:3.10-buster /bin/bash
## Can't test
pyarrow == 5.0.0
## Happy
???
## Unhappy python:3.10-buster
@russellpierce
russellpierce / 2021-06-23-TidyTuesday.R
Created June 23, 2021 18:23
Does the increase in # of ranks with time change the way we look at the Tidy Tuesday park data for Texas?
# 2021-06-23: Tidy Tuesday
# Inspired by, and some code copied from Jesse Mostipak
# https://twitter.com/kierisi/status/1407171923633651717
## Background ##
# Thought Experiment/Example:
# Imagine I'm the 5th tallest kid in a class of 40.
# Then my class size doubles to 80.
# Now I'm probably not the 5th tallest anymore.

A first blog post using that one tool

hi

@russellpierce
russellpierce / glue.tf
Last active November 30, 2021 19:18
Basic Terraform Setup for AWS Glue
# Discussion on Medium: https://medium.com/@russell.s.pierce/setting-up-aws-glue-with-terraform-8f601cf36366
resource "aws_iam_role" "glue" {
name = "AWSGlueServiceRoleDefault"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
@russellpierce
russellpierce / periscope.R
Created July 28, 2017 04:14
Create an embed URL for Periscope in R
#' Create Embed for Periscope
#'
#' Code not complete
#'
#' @param dashboard
#' @param filters
#' @param api_key
# '@author Russell S. Pierce, \email{Russell.Pierce@@zapier.com}
# '@author Christopher Peters, \email{chris.peters@@zapier.com}
#' @return
@russellpierce
russellpierce / athena.R
Created January 14, 2017 17:23
Connect to AWS Athena using R (with the option to use IAM credentials)
#repsych is on github and is here only for the glibrary idiom
library(repsych)
#install and load the following packages
glibrary(whisker, lubridate, magrittr, rappdirs, awsjavasdk, rJava)
if (!aws_sdk_present()) {
install_aws_sdk()
}
load_sdk()
@russellpierce
russellpierce / send_slack_message.R
Created September 10, 2016 21:29
Use Zapier to Send a Slack Message
#' Send a message to Slack
#'
#' To use, set options(zapier_slack_webhook="yourZapierPostWebhookHere")
#'
#' @param message
#' @param channel
#' @param bot_name
#' @param bot_icon_url
#' @param image_url
#' @param emoji
@russellpierce
russellpierce / forkable_JDBC.R
Last active August 18, 2017 17:39
Connect to a JDBC db in R via a single node cluster
# Very raw dump of prototype code that allows for connection to a JDBC db via a ad-hoc one node cluster. This demo code was designed to connect to redshift using Amazon's JDBC drivers - because sometimes you just want to do things the hard way
# To make this work, you'll need to update the classPath, driverPath, and of course, the host settings.
#library(plyr); needs to be available, but doesn't need to be attached
library(whisker)
library(R6)
library(logging)
library(R.utils) #tempvar
library(parallel) #makeCluster and friends
@russellpierce
russellpierce / require_package_version_github.R
Last active August 18, 2017 17:35
Guarantee that the required version (or higher) of a package is installed and load it; otherwise get from github
#' Require and install package version
#'
#' Guarantee that the required version (or higher) is installed.
#' This function will install from github in the desired version isn't found on CRAN or the current machine version is insufficient.
#'
#' @param packageName A quoted string, e.g. 'lubridate'
#' @param githubLoc e.g., 'hadley/lubridate'
#' @param requiredVersion e.g. '1.4'
#'
#' @return boolean ; TRUE if successful, FALSE otherwise
@russellpierce
russellpierce / parallelRDS.R
Created May 29, 2015 09:05
Provided the right tools are installed, i.e. xz and pigz, will offload the compression handling to an external program and leave R free to do the data import. This ends up being quite a bit more efficient for large files. Some tweaks may be needed for operating systems other than Ubuntu; there may be additional dependencies on the github repo dr…
library(parallel)
saveRDS.xz <- function(object,file,threads=parallel::detectCores()) {
pxzAvail <- any(grepl("(XZ Utils)",system("pxz -V",intern=TRUE)))
if (pxzAvail) {
con <- pipe(paste0("pxz -T",threads," > ",file),"wb")
base::saveRDS(object, file = con)
close(con)
} else {
saveRDS(object,file=file,compress="xz")