Skip to content

Instantly share code, notes, and snippets.

View emmaly's full-sized avatar
🔄
Synchronizing everything, everywhere, all at once.

Emmaly emmaly

🔄
Synchronizing everything, everywhere, all at once.
View GitHub Profile
@emmaly
emmaly / documents.ps1
Last active September 22, 2022 23:51
PowerShell: where's my Documents folder?
$documentsFolderPath = $([Environment]::GetFolderPath('Personal'))
# other ENUM values are here:
# https://learn.microsoft.com/en-us/dotnet/api/system.environment.specialfolder
@emmaly
emmaly / Find-EmptyFolders.ps1
Last active September 30, 2022 08:41
Find-EmptyFolders.ps1
function Find-EmptyFolders {
Param(
[string]$Path = $pwd,
[int]$MaxDepth = 0,
[switch]$IgnoreAccessDenied,
[switch]$IncludeHidden,
[System.Management.Automation.FlagsExpression`1[System.IO.FileAttributes]]$FileAttributes
)
$getParams = @{
@emmaly
emmaly / filterArray.js
Last active October 10, 2022 20:38
FilterArray
/**
* @param {any[]} input
* @param {Object} filter
* @param {(RegExp|string)} filter.match
* @param {(string|string[])} filter.property
* @param {boolean} [filter.regularExpression=false]
* @param {boolean} [filter.caseSensitive=false]
* @param {boolean} [filter.multiline=false]
*/
function filterArray(input, filter) {
@emmaly
emmaly / reconfigure.sh
Created December 9, 2022 20:30
DPMA Lookup and Reconfigure
#!/bin/bash
ID="$1"
MAC=$(grep -Ei '^[A-Z0-9]+$' <<<"$ID")
if [ -z "$MAC" ]; then
MAC=$(/etc/asterisk/scj/sipmac.sh "$ID")
if [ -z "$MAC" ]; then
echo "$ID was not found" >&2
@emmaly
emmaly / Read-GoReleases.ps1
Last active December 18, 2022 02:15
PowerShell: get newest Go release version from git
<# as a one-liner... because why not. #>
git ls-remote --tags https://go.googlesource.com/go | ForEach-Object { if ($_ -imatch ('^\s*(?<Commit>[0-9a-f]+)\s+refs/tags/go(?<Version>\d+\.\d+(?:\.\d+)?)\s*$')) { [PSCustomObject]@{Commit=$matches.Commit;Version=[Version]$matches.Version} } } | Sort-Object -Property Version -Descending -Top 1
@emmaly
emmaly / TestableTypes.js
Last active December 26, 2022 05:14
JavaScript type match helper
// these are just suggestions and examples...
const TestableTypes = {
"undefined" : "undefined",
"null" : "null",
"object" : "object",
"Object" : "Object",
"boolean" : "boolean",
"Boolean" : "Boolean",
"number" : "number",
@emmaly
emmaly / tracking-number.regex
Created January 14, 2023 02:35
Regular Expression for Tracking Numbers
\b(?:(?<International>[A-Z]{2}[0-9]{9}[A-Z]{2})|(?<FedEx>[0-9]{4} ?[0-9]{4} ?[0-9]{4} ?(?:[0-9]{3})?)|(?<UPS>(?:(?:(?:1Z)[0-9A-Z]{16})|(?:(?:T)[0-9A-Z]{15}[0-9])|(?:[0-9]{9})|(?:[0-9]{26})))|(?<USPS>(?:(?:(?:93|92|94|95)[0-9]{2} ?[0-9]{4} ?[0-9]{4} ?[0-9]{4} ?[0-9]{4} ?[0-9]{2,4})|(?:(?:70|14|23|03)[0-9]{14})|(?:(?:M0|82) ?[0-9]{3} ?[0-9]{3} ?[0-9]{2})|(?:(?:[A-Z]{2})[0-9]{9}(?:[A-Z]{2})))))\b
@emmaly
emmaly / Search-FileAccess.ps1
Created January 15, 2023 05:14
Search-FileAccess PowerShell Script
function Search-FileAccess {
param (
[Parameter(Mandatory=$true)]
[string]$IdentityReferenceRegex,
[Parameter(Mandatory=$true)]
[string]$Path,
[Boolean]$Recurse=$true,
[switch]$Visualization
)
@emmaly
emmaly / DATEMAX(range)
Created January 16, 2023 03:12
Google Sheets Named Functions: DATEMAX and DATEMIN
=
ARRAY_CONSTRAIN(
SORT(
FILTER(
range,
MAP(
range,
LAMBDA(
cell,
ISDATE(cell)
@emmaly
emmaly / Install-WinGetCli.ps1
Last active January 26, 2023 09:30
Install WinGet-CLI on Windows Server
function Get-FilesFromGithubLatestRelease {
# original function from https://github.com/microsoft/winget-cli/issues/1861#issuecomment-1193136622
param (
[parameter(Mandatory)][string]$Project, # e.g. paintdotnet/release
[parameter(Mandatory)][string[]]$Patterns, # regex
[switch]$Prerelease
)
$releases = Invoke-RestMethod -Method Get -Uri "https://api.github.com/repos/$Project/releases"
$release = $releases | Where-Object { $_.prerelease -eq $Prerelease } | Select-Object -First 1