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
// inspired by https://www.youtube.com/watch?v=RWyZkNzvC-c&t=553s | |
// $ dotnet fsi chaos2.fsx | |
// latency test | |
// 0.969491 | |
open System | |
open System.Threading | |
let chaos (name:string) (shouldChaos:unit -> bool) (chaos:unit -> unit) = | |
fun (service:unit -> 't) -> | |
if shouldChaos () then |
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
// inspired by https://www.youtube.com/watch?v=RWyZkNzvC-c&t=553s | |
// $ dotnet fsi chaos.fsx | |
// latency test | |
// 0.919409 | |
open System | |
open System.Threading | |
let chaos (name:string) (shouldChaos:unit -> bool) (chaos:unit -> unit) (service:unit -> 't) = | |
if shouldChaos () then | |
printfn "%s" name |
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
[CmdletBinding()] | |
param () | |
Set-StrictMode -Version Latest | |
$verbose = if ($PSBoundParameters.ContainsKey('Verbose')) { | |
$PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent } else { $false } | |
"Verbose enabled: $verbose" | Write-Host |
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
$tenantId = 'your_tenant_id' | |
$clientId = 'your_client_id' | |
$clientSecret = 'your_client_secret' | |
$tokenResponse = (Invoke-WebRequest -Uri "https://login.microsoftonline.com/$tenantId/oauth2/token" ` | |
-Method Post -UseBasicParsing ` | |
-Body "grant_type=client_credentials&client_id=$clientId&client_secret=$clientSecret").Content | |
"$(($tokenResponse | ConvertFrom-Json).access_token)`n" | Write-Host |
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 Require-AzCliVersion { | |
[OutputType([void])] | |
param( | |
[Parameter(Mandatory, ValueFromPipeline)] [ValidatePattern("^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,9}$")] [string] $Version, | |
[switch] $Fail | |
) | |
$actual = ('az version' | Invoke-Expression | ConvertFrom-Json).'azure-cli' | |
if ($actual -eq $Version) { | |
"Azure CLI present in pinned version $Version" | Write-Verbose | |
} else { |
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
# PS> 20 | Get-RandomString -Alphanumeric $false -NoQuotes $true | |
# PS> p({BFhlH*}KG#S{i{Ih5 | |
function Get-RandomString { | |
[OutputType([string])] | |
param( | |
[Parameter(Mandatory, ValueFromPipeline)] [int] $Length, | |
[bool] $Alphanumeric = $true, | |
[bool] $NoQuotes = $false | |
) |
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 Set-GitChanges { | |
gaa | |
gcam Staging | |
ggp | |
} | |
Import-Module posh-git | |
Import-Module git-aliases -DisableNameChecking | |
Set-Alias -Name stage -Value Set-GitChanges |
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
using System; | |
sealed class ConsoleEx | |
{ | |
public void Write(ConsoleColor color, string format, params object[] arg) | |
{ | |
var current = Console.ForegroundColor; | |
Console.ForegroundColor = color; | |
Console.Write(format, arg); | |
Console.ForegroundColor = current; |
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
using System.Collections.Generic; | |
using System.Reflection; | |
public static class PropertyInfoExtensions | |
{ | |
public static bool IsEnumerable(this PropertyInfo property) => | |
(property.PropertyType.IsGenericType && | |
property.PropertyType.GetGenericTypeDefinition() == typeof(IEnumerable<>)) || | |
property.PropertyType.GetInterface(typeof(IEnumerable<>).FullName) != null; | |
} |
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
/* | |
public class YourClass | |
{ | |
[JsonProperty("type")] | |
[JsonConverter(typeof(StringEnumConverter), converterParameters: typeof(LowerCaseNamingStrategy))] | |
public YourEnum YourProperty { get; set; } | |
} | |
*/ | |
using Newtonsoft.Json.Serialization; |