Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@r2evans
r2evans / plumber.R
Created March 11, 2023 15:35
r-plumber-clientdata
# Simple plumber api that shows most of the headers and env-vars as seen
# by the app when visited.
#
# MIT License
# Copyright (c) 2023 Bill Evans <bill@8pawexpress.com>
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
@r2evans
r2evans / app.R
Created March 11, 2023 15:31
r-shiny-clientdata
# Simple shiny app that shows most of the headers and env-vars as seen
# by the app when visited.
#
# MIT License
# Copyright (c) 2023 Bill Evans <bill@8pawexpress.com>
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
@r2evans
r2evans / gitlabci.bash
Last active January 28, 2022 14:34
Run GitLab CI jobs locally
#!/bin/bash
# gitlabci, v0.2, 2022-01-28
# Run GitLab-CI jobs (e.g., tests, coverage), locally.
# (c) 2022 Bill Evans bill@8pawexpress.com
# This script is intended to preempt the vicious cycle of:
# - Commit. Push. Watch the online CI test fail.
# - Commit a small typo. Push. Watch the CI test fail.
# - Commit two more characters. Push. Glare at the CI test.
#
#' Convert an StackOverflow URL to a local filename
#'
#' @param url character string, typically starting with
#' "https://stackoverflow.com/..."
#' @param dir logical, whether this should be a directory or a file
#' @param ext character, file extension
#' @param create logical, whether to create it or just report on it
#' @param force logical, whether to resort to a question number if the
#' user cannot be found
#' @param base character, the path under which all others will be
@r2evans
r2evans / coord_cartesian_panels.R
Last active April 25, 2023 03:54
per-facet panel range clipping
#' Cartesian coordinates per facet-panel
#'
#' This function mimics the behavior of [ggplot2::coord_cartesian()],
#' while supporting per-panel limits when faceted.
#'
#' @details
#'
#' A 'panel_limits' data frame may contain:
#'
#' - zero or more faceting variables, all of which must be found
@r2evans
r2evans / DBI RODBC comparison.R
Created August 15, 2020 02:23
Comparison of DBI/odbc, DBI/RODBCDBI, and RODBC db access for R
## ------------------------------------------------------------------
## SETUP
# docker run -d -p "31433:1433" --name testss \
# -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=Mysecretpassword1" \
# -e "MSSQL_PID=Developer" --cap-add SYS_PTRACE \
# microsoft/mssql-server-linux
# ... and add 'testss' as a DSN in the system- or user- odbc configuration

Clipboard selection over remote (ssh) and optionally multi-plexed (tmux) connections. This is primarily from a windows machine using git-for-windows, mintty, and tmux remotely. Untested otherwise.

Other (non-Windows) solutions/recommendations include xclip on the remote end; these will not work unless there is an X-windows server running on the local (Windows) machine.

The remainder is effectively the results of my trial-and-error process.

mintty and OSC-52

Instead, this uses OSC-52 escape sequences. Because they can be considered a security risk (the remote end might be able to see the local end's clipboard values arbitrarily), the capability is disabled by default.

@r2evans
r2evans / tryCatchPatterns.R
Last active August 15, 2019 19:16
exception handling by pattern (or sub-class)
#' Pattern-matching tryCatch
#'
#' Catch only specific types of errors at the appropriate level.
#' Supports nested use, where errors not matched by inner calls will
#' be passed to outer calls that may (or may not) catch them
#' separately.
#'
#' @details
#'
#' Exception handling with a little finer control over *where* a
@r2evans
r2evans / MapReduce.R
Last active June 15, 2019 20:39
Combination of R's Reduce function with Map's k-ary arguments
#' 'Reduce' with arbitrary number of arguments
#'
#' Applies a function to the corresponding elements of given vectors,
#' in a reductionist way. (This is *not* related to the [Apache Hadoop
#' MapReduce](https://hadoop.apache.org/) project ... while this may
#' suggest the name 'MapReduce' is a poor choice for this function, it
#' is a logical combination of R's [Map()] and [Reduce()] functions.)
#'
#' @details
#'
#!/bin/bash
# changing a single repo with subdirs like this:
#
# origrepo
# +-- subdir1
# +-- subdir2
#
# into a different/new repo with rearranged dirs (and discarded files),
# editing the full history