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
#Increase a number within a string by one | |
$data = 'XX3.txt', 'XX33.txt', 'XX333.txt' | |
$data | foreach{ | |
[RegEx]::Replace($_, '(\d{1,3})', {1+$args[0].Value}) | |
} | |
#Capitalize the second word within a sentence string | |
$script:counter = 0 | |
[regex]::Replace('this is a test','\w+', { | |
$script:counter++ | |
if ($counter -eq 2){ |
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 Edit-ISETemplate{ | |
$ISETemplatePath = "$([Environment]::GetFolderPath('MyDocuments'))\WindowsPowerShell\ISETemplate.ps1" | |
if (!Test-Path){ | |
New-Item $ISETemplatePath -ItemType File | |
} | |
psedit "$ISETemplatePath" | |
} | |
Register-ObjectEvent $psise.CurrentPowerShellTab.Files CollectionChanged -Action { | |
# files collection |
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
#build the cartesian product for an array of arrays | |
function CartesianProduct($row, $currCol=0){ | |
if ($currCol -eq 0){ | |
$wordIndices = New-Object int[] $row.Length | |
} | |
$wordIndex = 0 | |
#walk through the items in the current column | |
foreach($word in $row[$currCol]){ | |
#add the index to the indices for the current column | |
$wordIndices[$currCol] = $wordIndex |
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 CartesianProduct($htRow, $currCol=0){ | |
$colCount = $htRow.Keys.Count | |
if ($currCol -eq 0){ | |
$wordIndices = New-Object int[] $colCount | |
} | |
$wordCount = ($htRow.Values | select)[$currCol].Count | |
#walk through the items in the current | |
for ($wordIndex = 0; $wordIndex -lt $wordCount; $wordIndex++){ | |
#add the index to the indices for the current column | |
$wordIndices[$currCol] = $wordIndex |
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 Open-Registry{ | |
[CmdletBinding()] | |
[Alias("regJump")] | |
param( | |
[Parameter(Position=0)] | |
$regKey | |
) | |
#check for clipbaord only if no argument provided | |
if (!$regKey){ | |
#split the clipboard content by crlf and get of trailing crlf in case clipboard populated via piping it to clip.exe |
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
$regeditInstance = [Diagnostics.Process]::Start("regedit","-m") | |
#wait the regedit window to appear | |
while ($regeditInstance.MainWindowHandle -eq 0){ | |
sleep -Milliseconds 100 | |
} |
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
Sub CrossJoinSheets() | |
Dim cn As ADODB.Connection | |
Dim sql As String | |
Dim outputSheet As Worksheet | |
Dim rs As ADODB.Recordset | |
Set rs = New ADODB.Recordset | |
Set cn = New ADODB.Connection | |
With cn | |
.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" & _ | |
"Data Source=" & ActiveWorkbook.FullName & ";" & _ |
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
Private Function isSaved() As Boolean | |
Dim lastSaved As String | |
On Error GoTo EHandler | |
s = ActiveWorkbook.BuiltinDocumentProperties("last save time") | |
isSaved = True | |
Exit Function | |
EHandler: | |
isSaved = False | |
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
Sub CrossJoinRanges() | |
Dim cn As ADODB.Connection | |
Dim sql As String | |
Dim outputSheet As Worksheet | |
Dim rs As ADODB.Recordset | |
Set rs = New ADODB.Recordset | |
Set cn = New ADODB.Connection | |
With cn | |
.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" & _ | |
"Data Source=" & ActiveWorkbook.FullName & ";" & _ |
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
$Title = "Title" | |
$Info = "Pick Something!" | |
$options = echo Option1 Option2 Option3 | |
$defaultchoice = 2 | |
$selected = $host.UI.PromptForChoice($Title , $Info , $Options, $defaultchoice) | |
$options[$selected] |
OlderNewer