Skip to content

Instantly share code, notes, and snippets.

View powercode's full-sized avatar

Staffan Gustafsson powercode

  • DICE
  • Stockholm, Sweden
  • 11:53 (UTC +02:00)
View GitHub Profile
@powercode
powercode / Ripgrep.ArgumentCompleters.ps1
Last active April 10, 2017 18:40
Argument completer for ripgrep (rg)
using namespace System.Collections.Generic
using namespace System.Management.Automation
class RGCompleter {
static [bool] ShouldAdd([string] $completionText, [string] $wordToComplete, [string[]] $previousCommand, [string[]] $multiOpt) {
if ($completionText.StartsWith($wordToComplete, [StringComparison]::OrdinalIgnoreCase)){
if ($completionText -in $previousCommand -and $completionText -notin $multiOpt) {
return $false
}
return $true
#requires -Version 5.0
using namespace System.Management.Automation
using Namespace System.Collections
using Namespace System.Collections.Generic
<#
.SYNOPSIS
Combine items from the pipeline into a string, optionally adding single or double quotes
@powercode
powercode / touch.ps1
Created March 17, 2017 19:40
Touch in PowerShell
using namespace System.Management.Automation
function Update-LastWriteTime {
[CmdletBinding(DefaultParameterSetName='Path', SupportsShouldProcess)]
[OutputType([IO.FileInfo])]
[Alias('touch')]
param(
[Parameter(Mandatory, ParameterSetName="Path", Position=0, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[string[]] $Path,
[Alias('PSPath')]
@powercode
powercode / solutions.ps1
Last active December 20, 2016 15:33
Sample solutions to practice tasks
# practice tasks
# task1: Get all processes that on your machine where the processname starts with 'po'
Get-Process -name po*
#task 2: Get all processes where the handlecount > 1000
Get-Process | Where-Object HandleCount -gt 1000
#task 3: How many files are there in %windir%\System32
Get-ChildItem -File -LiteralPath $env:windir/System32 | Measure-Object
@powercode
powercode / StandardDeviation.ps1
Last active August 1, 2020 03:07
Calculate Standard Deviation is PowerShell
using namespace System.Collections.Generic
using namespace System.Linq
class StandardDeviation{
hidden [decimal] $Average
StandardDeviation([decimal] $average){
$this.Average = $average
}
@powercode
powercode / MatchInfoV5.format.ps1xml
Last active April 18, 2019 01:35
MatchInfoV5.format.ps1xml
<Configuration>
<!-- Add with Update-FormatData -PrependPath -->
<ViewDefinitions>
<View>
<Name>MatchInfo</Name>
<ViewSelectedBy>
<TypeName>Microsoft.PowerShell.Commands.MatchInfo</TypeName>
</ViewSelectedBy>
<CustomControl>
<CustomEntries>