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
# 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
# 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
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
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
[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
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
# 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
# To enable ANSI sequences in a PowerShell console run the following commands. | |
# After that you can use wttr.in in you PowerShell just lake that: | |
# (curl http://wttr.in/ -UserAgent "curl" ).Content | |
# | |
# More on it: | |
# http://stknohg.hatenablog.jp/entry/2016/02/22/195644 (jp) | |
# | |
Add-Type -Namespace Win32 -Name NativeMethods -ErrorAction SilentlyContinue -MemberDefinition @" | |
[DllImport("kernel32.dll", SetLastError=true)] |
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
function XName { | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory,Position=0)] | |
[ValidateNotNullOrEmpty()] | |
[string]$LocalName | |
) | |
process { | |
[System.Xml.Linq.XName]$LocalName |