Skip to content

Instantly share code, notes, and snippets.

View samcofer's full-sized avatar
🏠
Working from home

Sam Cofer samcofer

🏠
Working from home
View GitHub Profile
@samcofer
samcofer / Dockerfile.pak-pkg
Last active February 25, 2025 02:13
Pak based package installation for R
# Start from the RStudio Workbench base image
FROM rstudio/rstudio-workbench:jammy
# Set repository options globally for all R sessions
RUN echo 'options(repos = c( CRAN = "https://packagemanager.posit.co/cran/__linux__/jammy/latest", CRAN_20240401 = "https://packagemanager.posit.co/cran/__linux__/jammy/2024-04-01", BioCsoft = "https://bioconductor.org/packages/3.13/bioc", BioCann = "https://bioconductor.org/packages/3.13/data/annotation", BioCexp = "https://bioconductor.org/packages/3.13/data/experiment", BioCworkflows = "https://bioconductor.org/packages/3.13/workflows" ))' > /opt/R/4.4.1/lib/R/etc/Rprofile.site
# Install pak for efficient dependency resolution
RUN /opt/R/4.4.1/bin/Rscript -e 'install.packages("pak", repos = "https://packagemanager.posit.co/cran/__linux__/jammy/latest")'
# Install required R packages using pak
@samcofer
samcofer / snowflake-keypair.R
Created February 13, 2025 16:09
Snowflake Keypair Authenitcation via Posit Connect
# Use SSH key if on Connect, otherwise use managed credentials
if (Sys.getenv("RSTUDIO_PRODUCT") == "CONNECT"){
# grab ssh key from environment variable and cache as tempfile
cached_key <- tempfile()
readr::write_file(openssl::base64_decode(Sys.getenv("SNOWFLAKE_SSH_KEY")), file = cached_key)
# The ambient credential feature in odbc::snowflake() causes unexpected overwrites, so we'll use the base Snowflake driver.
con <- dbConnect(
odbc::odbc(),
driver = "Snowflake",
#!/bin/bash
# LDAP Connection details
LDAP_SERVER="ldap://cofer.me"
BIND_DN="CN=ldap-bind,CN=Users,DC=cofer,DC=me"
PASSWORD="password"
BASE_DN="DC=cofer,DC=me"
# Output CSV file
OUTPUT_FILE="ad-users.csv"
@samcofer
samcofer / package-download.R
Last active August 20, 2024 16:47
Script to download all R packages from an renv.lock file
# Load required libraries
library(jsonlite)
# Path to the renv.lock file
file_path <- "renv.lock"
# Read and parse the JSON content from the file
renv_data <- fromJSON(file_path)
@samcofer
samcofer / ssl-script.sh
Created June 3, 2024 20:01
Script to generate a self-signed certificate in bash
#!/bin/bash
# Check if URL is passed as an argument
if [ $# -eq 0 ]; then
echo "Error: Please provide a URL as an argument."
exit 1
fi
# Set the URL
URL=$1
@samcofer
samcofer / 0-rebuild-cache-information-after-os-upgrade.txt
Last active February 14, 2025 20:05
Update local renv and python cache
#Placeholder to change the name of the gist
@samcofer
samcofer / App.R
Created April 24, 2024 20:52
Shiny Geyser with ggplot
# Load necessary libraries
library(ggplot2)
library(shiny)
# Load Old Faithful geyser data
data <- faithful
# Define UI
ui <- fluidPage(
titlePanel("Old Faithful Geyser Data"),
@samcofer
samcofer / audit-trigger.sql
Created January 31, 2024 19:13
Postgres SQL Auditing Trigger
-- Create all objects and audit table
create TABLE t_history (
id serial,
tstamp Timestamp DEFAULT now(),
schemaname text,
tabname text,
operation text,
who text DEFAULT current_user,
new_val jsonb,
@samcofer
samcofer / 0-Posit Linux Aliases
Last active September 26, 2024 17:24
Posit Linux Aliases
#Posit Linux Aliases