This file contains hidden or 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
# Taken from: https://github.com/PowerShell/PowerShell/issues/2736 | |
function Format-Json([Parameter(Mandatory, ValueFromPipeline)][String] $json) { | |
$indent = 0; | |
($json -Split '\n' | | |
% { | |
if ($_ -match '[\}\]]') { | |
# This line contains ] or }, decrement the indentation level | |
$indent-- | |
} | |
$line = (' ' * $indent * 2) + $_.TrimStart().Replace(': ', ': ') |
This file contains hidden or 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
public static class LoggerExtensions | |
{ | |
public static ILogger WithCallerInfo(this ILogger logger, | |
[CallerMemberName]string callerMemberName = null, | |
[CallerFilePath]string callerFilePath = null, | |
[CallerLineNumber]int callerLineNumber = 0) | |
{ | |
return logger | |
// substituting 'Caller' with 'Source' because 'ForContext<T>()' adds property 'SourceContext' | |
.ForContext("SourceMemberName", callerMemberName) |
This file contains hidden or 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
[CmdletBinding()] | |
param( | |
[Parameter(ValueFromPipeline)] | |
[ValidateScript({Test-Path -Path $_})] | |
$ProjectToMeasure = $PWD, # Allows to pipe in project directiories | |
[Parameter()] | |
[switch]$ShowResult | |
) | |
begin { |
This file contains hidden or 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
using namespace System.Xml.Linq | |
@( | |
"html" | |
"head" | |
"body" | |
)|Foreach-Object -Process { | |
@" | |
function global:$_ { | |
[CmdletBinding()] |
This file contains hidden or 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
void Main() | |
{ | |
var lazy = new SimpleLazy<string>(() => | |
{ | |
"calculating".Dump(); | |
return "hello"; | |
}); | |
lazy.Value.Dump("1"); | |
lazy.Value.Dump("2"); | |
This file contains hidden or 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
# https://en.wikipedia.org/wiki/Box-drawing_character | |
$lightBox = @{ | |
vert = [char]::ConvertFromUtf32(9474) | |
horz = [char]::ConvertFromUtf32(9472) | |
leftup = [char]::ConvertFromUtf32(9484) | |
leftdown = [char]::ConvertFromUtf32(9492) | |
rightdown = [char]::ConvertFromUtf32(9496) | |
rightup = [char]::ConvertFromUtf32(9488) | |
} |
This file contains hidden or 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
# https://github.com/bozho/AnsiColorOut/blob/master/AnsiColorOut/Console.cs | |
# https://stackoverflow.com/questions/4842424/list-of-ansi-color-escape-sequences | |
$esc=[char]0x001b | |
filter esc { | |
param( | |
[ValidateSet("underline","italic")] | |
[string[]]$Format | |
) |
This file contains hidden or 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
class Context { | |
$Data | |
} | |
filter require_context { | |
if( $_ -is [Context]) { | |
$_ | |
} else { | |
throw "missing context" | |
} |
This file contains hidden or 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
using namespace System.Management.Automation | |
using namespace System.Collections.ObjectModel | |
function inner { | |
param( | |
[int]$Value | |
) | |
$Value | |
} |
This file contains hidden or 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
public class ClassLogger | |
{ | |
private readonly string typeName; | |
public static ClassLogger Make<T>(T instance) | |
{ | |
return new ClassLogger(typeof(T).Name); | |
} | |
public ClassLogger(string typeName) |