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
# Child process exe, opens notepad.exe | |
$null = Add-Type -TypeDefinition 'static class Test{static void Main(string[] args){System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(@"C:\windows\system32\notepad.exe"));}}' -OutputAssembly child.exe | |
# Parent process exe, opens child process | |
$null = Add-Type -TypeDefinition $('static class Test{static void Main(string[] args){System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(@"' + (Get-Item child.exe).FullName + '"));}}') -OutputAssembly parent.exe | |
# Wait for Parent to "complete" | |
$p = Start-Process .\parent.exe -Wait -PassThru |
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
Function Join(InputRange As Range, Optional Separator As String = ",") As String | |
Dim CurrentRange As Range | |
Dim FinalString As String | |
For Each CurrentRange In InputRange | |
If CurrentRange.Text <> Separator Then | |
FinalString = FinalString & CurrentRange.Text & Separator | |
End If | |
Next | |
Join = Left(FinalString, Len(FinalString) - Len(Separator)) | |
End Function |
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
param([Parameter(Position = 0)][string] $Path = 'C:\Users\grave\Downloads\ChessData-master\') | |
$code = @{ | |
Name = 'ResultCounter' | |
Namespace = 'ChessData' | |
PassThru = $true | |
UsingNamespace = @( | |
'System.Collections.Concurrent', | |
'System.IO', | |
'System.Threading.Tasks' | |
) |
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
Measure-Command{ | |
$startNumber = 0 | |
$endNumber = 20000 | |
$random = New-Object System.Random | |
$set = New-Object 'System.Collections.Generic.HashSet[int]' | |
$limit = $endNumber - $startNumber | |
$sequence = while($set.Count -lt $limit) |
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
<# | |
Optimizing for low memory footprints | |
A popular choice for randomizing collection ordering in PowerShell is this simple and effective pipeline: | |
$array |Sort-Object {Get-Random} | |
An equivalent super-easy-to-implement algorithm that comes to mind is the "Fisher-Yates Shuffle" | |
From Wikipedia (https://en.wikipedia.org/wiki/Fisher–Yates_shuffle): |
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
$thisCode = @" | |
is perfectly | |
"@ -split "\s+" # valid |
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
# define workflow | |
workflow test | |
{ | |
$i = 0 | |
while($i -lt 10){ | |
$i++ | |
"$i" | |
Start-Sleep -Seconds 5 | |
Checkpoint-Workflow | |
} |
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
<# | |
PowerShell port of James Bach's counterstring perl function (http://www.satisfice.com/tools.shtml) | |
Paraphrased from the original help text: | |
New-CounterString -Length $n -Char $c; produces a special string of length $n that counts its own characters. | |
"New-CounterString 10" would produce "*3*5*7*10*" which is a ten-character long string, such that each asterisk is at a position in the string equal to the number that precedes it. | |
This is useful for pasting into fields that cut off text, so that you can tell how many characters were actually pasted. You can specify a separator other than asterisk. "New-CounterString 15 A" would produce "A3A5A7A9A12A15A" | |
#> | |
function New-CounterString | |
{ |
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
function Get-ScriptBlock { | |
$var = "Success!" | |
return { $var } | |
} | |
function Get-Closure { | |
$var = "Success!" | |
return { $var }.GetNewClosure() | |
} |
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
function Get-HammingDistance | |
{ | |
param( | |
[Parameter(Mandatory)] | |
[string]$String1, | |
[Parameter(Mandatory)] | |
[string]$String2 | |
) | |
if($String1.Length -ne $String2.Length) |