Skip to content

Instantly share code, notes, and snippets.

@jimbrig
jimbrig / PowerShellSingleFileScriptTemplate.ps1
Created August 30, 2024 14:59 — forked from deadlydog/PowerShellSingleFileScriptTemplate.ps1
PowerShell template for a single-file script
<#
.SYNOPSIS
PUT SHORT SCRIPT DESCRIPTION HERE AND ADD ANY ADDITIONAL KEYWORD SECTIONS AS NEEDED (.PARAMETER, .EXAMPLE, ETC.).
#>
[CmdletBinding()]
param (
# PUT PARAMETER DEFINITIONS HERE AND DELETE THIS COMMENT.
)
process {
@jimbrig
jimbrig / PowerShellUtilities.psm1
Created August 30, 2024 14:57 — forked from deadlydog/PowerShellUtilities.psm1
Powershell Invoke-ScriptBlockWithRetries function to execute arbitrary PowerShell code and automatically retry if an error occurs
function Invoke-ScriptBlockWithRetries {
[CmdletBinding(DefaultParameterSetName = 'RetryNonTerminatingErrors')]
param (
[Parameter(Mandatory = $true, HelpMessage = "The script block to execute.")]
[ValidateNotNull()]
[scriptblock] $ScriptBlock,
[Parameter(Mandatory = $false, HelpMessage = "The maximum number of times to attempt the script block when it returns an error.")]
[ValidateRange(1, [int]::MaxValue)]
[int] $MaxNumberOfAttempts = 5,
@jimbrig
jimbrig / Makefile
Created August 28, 2024 19:27 — forked from thierrymoudiki/Makefile
R package workflow (assuming you're on macOS or Linux)
.PHONY: buildsite check clean coverage docs getwd initialize install load render setwd start test usegit
.DEFAULT_GOAL := help
define BROWSER_PYSCRIPT
import os, webbrowser, sys
from urllib.request import pathname2url
# The input is expected to be the full HTML filename
filename = sys.argv[1]
filepath = os.path.abspath(os.path.join("./vignettes/", filename))
@jimbrig
jimbrig / bsTheme.R
Created August 27, 2024 15:19 — forked from jtrive84/bsTheme.R
Function to change shiny bootstrap theme
sfThemeSelector = function() {
# --------------------------------------------------------------------------
# Allow dynamic update of bootstrap theme.
# --------------------------------------------------------------------------
div(
div(
selectInput(
"shinytheme-selector", "Select theme:",
c("default", shinythemes:::allThemes()),
@jimbrig
jimbrig / index.md
Created August 26, 2024 15:15 — forked from jcheng5/index.md
Resources for "Shiny × AI" by Joe Cheng, at posit::conf(2024)
@jimbrig
jimbrig / llm_factory.py
Created August 17, 2024 18:34 — forked from daveebbelaar/llm_factory.py
LLM Factory with Instructor
from typing import Any, Dict, List, Type
import instructor
from anthropic import Anthropic
from config.settings import get_settings
from openai import OpenAI
from pydantic import BaseModel, Field
class LLMFactory:
@jimbrig
jimbrig / chrome_flags.updated.js
Created August 15, 2024 19:59 — forked from kkeybbs/chrome_flags.updated.js
Backup chrome flags to json and restore the backup on another machine.
// 2022-04-03, tested with Chrome 99.0.4844.84 on MacBook Pro m1
/*
Open chrome://flags/
F12 open developer console, swtich to tab "Console"
Paste below codes
- input backup() to download flags backup file
- input restore() to select one backup to restore
*/
function saveFile(filename, data) {
@jimbrig
jimbrig / UsefulAttributes.md
Created August 7, 2024 01:03 — forked from StartAutomating/UsefulAttributes.md
Potentially Useful Attributes in PowerShell

PowerShell, as a language, is very self-discoverable.

When you Get-Command, you get a rich object about a command.

This can have a lot of metadata.

You can and should also use inline help (like this script does).

Sometimes, I want more metadata than the command or parameter can actually provide.

@jimbrig
jimbrig / pluck_recursive.R
Created June 28, 2024 22:43 — forked from wch/pluck_recursive.R
From a tree, recursively pluck all elements with a particular name
# @drob's version from https://twitter.com/drob/status/1501747414780239879
pluck_recursive <- function(lst, name) {
if (is.list(lst)) {
if (!is.null(lst[[name]])) {
return(lst[[name]])
}
return(unname(unlist(purrr::map(lst, pluck_recursive, name))))
}
}
@jimbrig
jimbrig / gist:0f5a53b44ae75193eefdcc14df04b3f6
Created June 27, 2024 17:00 — forked from pitch-gist/gist:2999707
HTML: Simple Maintenance Page
<!doctype html>
<title>Site Maintenance</title>
<style>
body { text-align: center; padding: 150px; }
h1 { font-size: 50px; }
body { font: 20px Helvetica, sans-serif; color: #333; }
article { display: block; text-align: left; width: 650px; margin: 0 auto; }
a { color: #dc8100; text-decoration: none; }
a:hover { color: #333; text-decoration: none; }
</style>