This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$base = 10 | |
$num = '' | |
$esc = [char]27 | |
$red = "$esc[31m" | |
$blue = "$esc[34m" | |
$reset = "$esc[39m" | |
for ($i = 1; $i -lt 10; $i++) { | |
$num = $num + $i | |
(' ' * ($base-$i-1)) + $num + ' x ' + $red + [string]($base*0.8) + $reset + ' + ' + $blue + $i + $reset + ' = ' + [string]([int32]$num * ($base * 0.8) + $i) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#region SAVE_RUNTIME | |
#region SELFMODIFICATION | |
$NewLastRunTime = '18/03/2021 14:51:46' #MODIFY_HERE | |
#region SELFMODIFICATION | |
$LastRunTime = [datetime]::Parse($NewLastRunTime) | |
$Me = $MyInvocation.MyCommand.Source | |
$Myself = Get-Content $Me | |
$Myself ` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create the code usually written as function as scriptblock | |
# it can be run directly in the main script as any other scriptblock | |
$loopcode = { | |
param($user,$counter) | |
write-host ("User: {0} {1}" -f $user,$counter) | |
} | |
# convert the scriptblock to string to be able to reuse it in foreach -parallel | |
# functions cannot be used in foreach -parallel | |
$codestring = [string]$loopcode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### all this goes into the begin {} block of a cmdlet | |
# check and/or set function cache | |
# scope must be global to remain in memory until the function is called again | |
# variable will be names "cache_" + name of the function | |
# initial value will be an empty hashtable, so you can add data nodes as needed in your function | |
$CacheName = "cache_$($MyInvocation.InvocationName)" | |
if ( -not ( Get-Variable -Name $CacheName -Scope global -ErrorAction SilentlyContinue ) ) { | |
New-Variable -Name $CacheName -Value @{} -Scope global | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#region WORKING_1 | |
class Log { | |
hidden [System.Diagnostics.Stopwatch] $Timer = [System.Diagnostics.Stopwatch]::New() | |
Log() { | |
$this.Timer.Start() | |
} |