Skip to content

Instantly share code, notes, and snippets.

View blairj09's full-sized avatar

James Blair blairj09

  • Posit, PBC
View GitHub Profile
@blairj09
blairj09 / nested-arrow-r.md
Created March 31, 2023 22:14
Exploring querying nested data arrow using R

Arrow and Nested Data

# Packages ----
library(arrow)

Attaching package: 'arrow'

# Pi Simulation ----
estimate_pi <- function(n = 10000) {
z <- replicate(n, sqrt(runif(1, -1, 1)^2 + runif(1, -1, 1)^2))
4*sum((z<=1))/length(z)
}
n_sims <- 100000
# Active window
(results_active <- bench::mark(estimate_pi(n_sims), min_time = Inf, max_iterations = 20))
@blairj09
blairj09 / apis.R
Last active December 6, 2021 21:24
# API1.R
library(plumber)
library(mypkg)
# Logging Stuffs
#* @post /foo
function() {
mypkg::foo()
}
Building Jupyter notebook...
Bundle created with Python version 3.9.0 is compatible with environment Local with Python version 3.9.0 from /opt/python/3.9.0/bin/python3.9
Bundle requested Python version 3.9.0; using /opt/python/3.9.0/bin/python3.9 which has version 3.9.0
2021/11/15 23:13:56.187554195 Running on host: usw2-prd-rstd03
2021/11/15 23:13:56.187572790 Environment will be built with Python "3.9.0 | packaged by conda-forge | (default, Nov 26 2020, 07:57:39) [GCC 9.3.0]" at /opt/python/3.9.0/bin/python3.9
2021/11/15 23:13:56.187782318 Running as user: rstudio-connect
2021/11/15 23:13:56.214056251 Skipped packages: rsp-jupyter==1.4.1717, setuptools==58.5.1
2021/11/15 23:13:56.214065199 Using cached environment: u9lAJLJ_6f3fVxMrMJ4oiQ
2021/11/15 23:13:57.257138517 WARNING: The directory '/home_efs/rstudio-connect/.cache/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with s
@blairj09
blairj09 / app.py
Created October 22, 2021 21:29
Simple FastAPI
from fastapi import FastAPI
from fastapi.responses import RedirectResponse
import uvicorn
app = FastAPI(
title = "Hello World"
)
@app.get("/")
async def home():
@blairj09
blairj09 / static.html
Created May 21, 2020 22:27
Static HTML returned from a curl request to an Ubuntu apt repo
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<!-- Applications (such as Dictionary.app) can recognize that a
webpage has been restricted by looking for the following comment: -->
<!-- com.apple.parentalcontrols.webcontentfilter.accessrestricted -->
<title>Access Restricted</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
@blairj09
blairj09 / simple-stan.R
Created May 16, 2019 20:17
Reprex for simple Stan model in R
# Example from https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started
library(rstan)
schools_dat <- list(J = 8,
y = c(28, 8, -3, 7, -1, 1, 18, 12),
sigma = c(15, 10, 16, 11, 9, 11, 10, 18))
fit <- stan(model_code = '
data {
int<lower=0> J; // number of schools

Keybase proof

I hereby claim:

  • I am blairj09 on github.
  • I am blairj09 (https://keybase.io/blairj09) on keybase.
  • I have a public key ASDSdsn21D_MxA6TGkSggFPTxQJnEX2N-rN1KZA65ohuEwo

To claim this, I am signing this object:

---
title: Scraping Friends
description: An adventure with `rvest`
author: James Blair
date: '2017-07-18'
slug: friends
categories: []
tags:
- R
- SoDS17
---
title: Scraping Friends
description: An adventure with `rvest`
author: James Blair
date: '2017-07-18'
slug: friends
categories: []
tags:
- R
- SoDS17