Skip to content

Instantly share code, notes, and snippets.

View fearthecowboy's full-sized avatar
🏠
Happily Working from home

Garrett Serack fearthecowboy

🏠
Happily Working from home
View GitHub Profile
#!/usr/bin/env -S deno run --reload -A --ext=ts
` <#`;
import { readdir } from "node:fs/promises";
import { join,resolve } from "node:path";
import { argv } from "node:process";
let size = 0;
let count = 0;
@fearthecowboy
fearthecowboy / sample.ts.ps1
Created January 26, 2024 19:34
PowerShell and Deno Script
#!/usr/bin/env -S deno run --reload -A
` <#`
// this is all typescript code here.
console.log("we're running typescript using deno");
/*#>
# this is PowerShell code here.
if (-not (get-command deno)) { irm https://deno.land/install.ps1 | iex }
deno run --reload -A ($MyInvocation.MyCommand.Path) @args
#*/
#!/usr/bin/env -S bash # > NUL 2>&1 || echo off && goto init:
function shh() { return; } ; shh \\<<shh
## THIS IS THE START OF THE POWERSHELL SCRIPT #################################
# Copyright 2018 the Deno authors. All rights reserved. MIT license.
# TODO(everyone): Keep this script simple and easily auditable.
$ProgressPreference='SilentlyContinue'
$ErrorActionPreference = 'Stop'
if ($v) {
$Version = "v${v}"
@fearthecowboy
fearthecowboy / FluentConsole.ps1
Created June 9, 2022 19:16
FluentConsole for PowerShell
<##
FluentConsole Functions
(C) 2022 Garrett Serack
License: MIT
Usage:
dot source this into your script (. FluentConsole.ps1 )
and then you can use the colon-prefixed functions.
You can separate colon-function calls with ';' or '|' or a newline.
@fearthecowboy
fearthecowboy / test.ps1
Created April 29, 2022 20:53
This one script can be saved as any of [.cmd, .bat, .ps1, .sh] and will run under cmd.exe, powershell, pwsh, bash and zsh.
#!/usr/bin/env -S bash # > NUL 2>&1 || echo off && goto init:
function shh() { return; } ; shh \\<<shh
## THIS IS THE START OF THE POWERSHELL SCRIPT #################################
write-host "Setting variable in powershell"
$env:abc=300
return;
## THIS IS THE END OF THE POWERSHELL SCRIPT ###################################
<#
@fearthecowboy
fearthecowboy / universal.ps1.cmd
Created March 9, 2021 21:02
This file can be saved as .ps1 or .cmd and works for both. Even supports cmdline arguments!
@(echo off) > $null
if #ftw NEQ '' goto :init
($true){ $Error.clear(); }
# unpack arguments if they came from CMD
$hash=@{};
get-item env:argz* |% { $hash[$_.name] = $_.value }
if ($hash.count -gt 0) {
$args=for ($i=0; $i -lt $hash.count;$i++) { $hash["ARGZ[$i]"] }
}
@fearthecowboy
fearthecowboy / sample.cmd
Last active March 3, 2021 22:48
This file is a legal .cmd script and a legal powershell script.
@(echo off) > $null
set null( New-Module -ScriptBlock { function goto { }; function :{ } } )#=
: # This file is both a .cmd script and a powershell script. if you save it as
: # sample.cmd and run it it from cmd.exe it will run the same as if you
: # saved it as sample.ps1 and run it.
: # well, in this case, I added some echos on the cmd side...
goto :CMDSTART
Set-ExecutionPolicy -Scope LocalMachine Unrestricted -force
$ProgressPreference=0
function ResolvePath {
param (
[string] $FileName
)
$FileName = Resolve-Path $FileName -ErrorAction SilentlyContinue `
-ErrorVariable _frperror
Object.defineProperties(Array.prototype, {
where: { value: Array.prototype.filter },
select: { value: Array.prototype.map },
any: { value: Array.prototype.some },
all: { value: Array.prototype.every },
insert: { value: function (position: number, items: Array<any>) { return (<Array<any>>this).splice(position, 0, ...items); } },
selectMany: { value: function (callbackfn: (value: any, index: number, array: Array<any>) => Array<any>) { return (<Array<any>>this).select(callbackfn).flat(); } },
groupByMap: { value: function (keySelector: (each: any) => any, selector: (each: any) => any) {
const result = new Map<any, Array<any>>();
@fearthecowboy
fearthecowboy / split.js
Last active February 12, 2020 17:47
Split identifier into words
const identifier = "SomethingNOTGarrettButTLAsInASetOfEverLongerWordsTLAWithIsOfAPIsAPIssNotNOManThatYouUseWith_a_TLA";
// split identifier into words
identifier.replace(/([a-z]+)([A-Z])/g, '$1 $2').
replace(/(\d+)/g, ' $1 ').
replace(/\b([A-Z]+)([A-Z])s([^a-z])(.*)/g, '$1$2« $3$4').
replace(/\b([A-Z]+)([A-Z])([a-z]+)/g, '$1 $2$3').
replace(/«/g, 's').trim().
split(/[\W|_]+/)
// returns: