Skip to content

Instantly share code, notes, and snippets.

View n3wjack's full-sized avatar

n3wjack

View GitHub Profile
@n3wjack
n3wjack / Write-BeFlag.ps1
Created April 21, 2025 19:31
Print a Belgian flag with PowerShell
cls;$d=((" "*3),'Black'),(("█"*40),'Black'),(("█"*40),'Yellow'),(("█"*40),'Red'); 1..40 | % { $d | % { Write-Host $_[0] -ForegroundColor $_[1] -NoNewLine -BackgroundColor Blue }; write-host; sleep -Milliseconds 10 }
# Substitute variables late. Define the template before the variables are in context.
# See also: https://learn.microsoft.com/en-us/powershell/scripting/learn/deep-dives/everything-about-string-substitutions?view=powershell-7.3
$message = 'Hello, $Name!'
$name = 'Kevin Marquette'
$string = $ExecutionContext.InvokeCommand.ExpandString($message)
<#
A simple way to create a busy-spinner in Powershell.
#>
$global:animation = @{ Chars = "-\|/"; Ix = 0; Counter = 0 }
# Animate one step every 500 calls. Lower the number for a faster animation.
function Animate() {
$a = $global:animation
@n3wjack
n3wjack / check-function.ps1
Created June 25, 2020 14:26
A simple nice looking system check function for PowerShell, using a script block as input.
function Do-Check ($message, $function)
{
write-host "[ ] $message" -nonewline
$result = Invoke-Command $function
if ($result)
{
$resultMsg = "[ OK ]"
$color = "green"
}
@n3wjack
n3wjack / Matomo-event-sample.js
Created November 9, 2019 14:54
JS code to add an click event to Matomo
document.querySelectorAll('.sd-content a').forEach(function (i) { i.addEventListener("click", function(){ _paq.push(['trackEvent', 'Share button', 'Click', i.title]); }) });
@n3wjack
n3wjack / statepattern-test.ps1
Created August 4, 2019 11:38
A state pattern test in Powershell
# Make a test file
"0" | set-content testfile.txt
1..100 | % { $_ | add-content testfile.txt }
$l = get-content testfile.txt
# ***** Regular implemenation *****
@n3wjack
n3wjack / progress-bar.ps1
Last active November 25, 2018 12:52
A simple powershell progress bar without messing with RawUI.CursorPosition
1..20 | % { write-host ("#"*$_ + "|" * (20-$_) + "`r") -nonewline ; sleep -Milliseconds 200 } ; ""
@n3wjack
n3wjack / test.csv
Last active June 14, 2018 12:11
test csv
id name
1 joe
2 bill
3 jane
@n3wjack
n3wjack / Write-Colors.ps1
Last active April 30, 2018 13:36
Write colorful console output using a simple function
function Write-Colors ($data)
{
foreach ($token in $data)
{
if ($token -is [array])
{
if ($token.Length -eq 2)
{
Write-Host $token[0] -Foregroundcolor $token[1] -NoNewLine
}
@n3wjack
n3wjack / Remove-BuildArtifacts.ps1
Last active February 17, 2017 12:59
Remove bin & obj folder recursively, aka clean up .NET build artifacts
$d = ls obj,bin -r -directory; $d | % { "Removing $_" ; remove-item $_ -Recurse }