Skip to content

Instantly share code, notes, and snippets.

@mevanlc
mevanlc / wget_ucd.sh
Created October 12, 2024 22:43
wget a version of the Unicode Standard data files (UCD)
#!/bin/bash
wget -o wget.log -r -np -nH --cut-dirs=2 -P out/ --show-progress \
--reject "index.html*" --reject-regex '\?C=.*' \
https://www.unicode.org/Public/zipped/16.0.0
@mevanlc
mevanlc / powershell-design-pattern.md
Last active September 26, 2024 19:12
PowerShell: Avoiding double-confirmations in Cmdlets that use SupportsShouldProcess

(The content of this article is licensed under "CC-BY" which allows you to share, adapt, remix, and republish this work. All that's required is attribution like this: "© CC-BY <link to where you obtained this article>"). More info at: https://creativecommons.org/licenses/by/4.0/

PowerShell: Avoiding double-confirm prompts in Cmdlets

A PowerShell Design Pattern: Handling Confirmation Prompts in Cmdlets


When writing custom PowerShell Cmdlets, a common scenario arises when your Cmdlet has the SupportsShouldProcess = $true attribute set to leverage PowerShell’s -Confirm infrastructure. This attribute enables built-in confirmation prompts that ask the user to verify potentially impactful actions before proceeding.

git ls-files -z | gxargs -0 dirname | grep -Fxv . | grep -v / | sort -u | gxargs gdu -h --max-depth 0 | sort -h
@mevanlc
mevanlc / gist:948d5277e85575def5bd1800a5603de6
Last active January 1, 2024 11:17
EBNF for broken `::` comments in dosbatch (SSCCE)
<file> ::= ( <statement> | <comment> | <block> )+
<statement> ::= <anytext>+ "\n"+
<comment> ::= "::" <anytext>+ "\n"+
<block> ::= "(" "\n"+ ( <comment> <statement> | <statement> | <block> )+ ")" "\n"+
<anytext> ::= #"[a-z0-9 ]"
<blockerror> ::= "{" "\n"+ ( <comment> <statement> | <statement> | <block> )+ "}" "\n"+

see https://mdkrajnak.github.io/ebnftest/

@mevanlc
mevanlc / global_local_inner_outer.sh
Created December 20, 2023 09:48
Testing the usage of global and local variables inside and outside functions in a number of combinations
#!/bin/sh
decl_outside="assigned outside a function"
echo "printing from outside: \$decl_outside: value before assignment INSIDE a function: [$decl_outside]"
INSIDE1() {
echo "printing from INSIDE1(): \$decl_outside: value before assignment by INSIDE1(): [$decl_outside]"
decl_outside="assigned by INSIDE1()"
echo "printing from INSIDE1(): \$decl_outside: value after assignment by INSIDE1(): [$decl_outside]"
@mevanlc
mevanlc / install_z_sh.sh
Last active February 24, 2024 11:23
Helper script to install z.sh (jump around) - https://github.com/rupa/z
#!/bin/sh
SOURCE_URL="https://raw.githubusercontent.com/rupa/z/master/z.sh"
OUTPUT_LOC="$HOME/.z.sh"
usage_doc="Usage: $0 [-h] [-u url] [-o file]
-h this help
-u <url> download from <url>
default: $SOURCE_URL
-o <file> download to <file>
@mevanlc
mevanlc / cmdhere-undo.reg
Last active September 29, 2024 04:28
Add "Cmd Here" context-menu entry to Windows Explorer. Mnemonic hotkey is spacebar.
Windows Registry Editor Version 5.00
[-HKEY_CLASSES_ROOT\Folder\shell\cmdhere]
[-HKEY_CLASSES_ROOT\Directory\Background\shell\cmdhere]
@mevanlc
mevanlc / winrenice.py
Last active May 9, 2019 08:28
In liu of a 'renice' cmdline utility on Windows. Requires Python and the https://github.com/giampaolo/psutil library.
#!/usr/bin/env python
# Copyright (c) 2019, Giampaolo Rodola', Michael Clark. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# https://github.com/giampaolo/psutil/blob/master/LICENSE
"""
In liu of a 'renice' cmdline utility on Windows.
$ winrenice chrome.exe below
@mevanlc
mevanlc / gpg_agent_daemon_bashrc.sh
Last active May 8, 2019 16:10
Reusing gpg-agent across login sessions (bashrc) on a headless server
# Run:
# sudo apt-get install gnupg-agent
# sudo apt-get install pinentry-curses
# Edit:
# $HOME/.gnupg/gpg-agent.conf:
# pinentry-program /usr/bin/pinentry-curses
# default-cache-ttl 28800000
# max-cache-ttl 28800000
# Edit:
# $HOME/.subversion/config:
@mevanlc
mevanlc / search_and_replace.jse
Created May 15, 2018 22:07
Microsoft JScript - Search and replace in a text file using regex
try
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var shell = new ActiveXObject("WScript.Shell");
var READ = 1, WRITE = 2, APPEND = 8;
var TEXT_DEFAULT = -2, TEXT_UNICODE = -1, TEXT_ANSI = 0;
var argc = WScript.Arguments.Count();
if (argc < 4)
{