Skip to content

Instantly share code, notes, and snippets.

Avatar

Chris Kuech chriskuech

  • Datum Source, ex MSFT
View GitHub Profile
View use-classes-2.ps1
class Cluster {
[ValidatePattern("^[A-z]+$")]
[string] $Service
[ValidateSet("TEST", "STAGE", "CANARY", "PROD")]
[string] $FlightingRing
[ValidateSet("EastUS", "WestUS", "NorthEurope")]
[string] $Region
[ValidateRange(0, 255)]
[int] $Index
View bad-hyper-settings.js
// Future versions of Hyper may add additional config options,
// which will not automatically be merged into this file.
// See https://hyper.is#cfg for all currently supported options.
module.exports = {
config: {
// choose either `'stable'` for receiving highly polished,
// or `'canary'` for less polished but more frequent updates
updateChannel: 'stable',
View medium-fp-diverr.ps1
function div($n, $d) {$n / $d} # a seemingly pure function
div 1 0 # throws 'Attempted to divide by zero' error
View medium-fp-errorhandling.ps1
$ErrorActionPreference = "Stop"
function Assert-True {
[CmdletBinding()] # add ErrorAction support
Param([boolean]$Value)
if (-not $Value) {
throw "Failed assertion"
}
}
View medium-config-override.ps1
Select-ClusterSetPartialConfig ".\Configs" "PROD-EU-NorthEurope" `
| Sort-Object `
| % {$_ | Get-Content | ConvertFrom-Json} `
| Merge-Object -Strategy Override
View medium-config-fail.ps1
Select-ClusterSetPartialConfig ".\Configs" "PROD-EU-NorthEurope" `
| % {$_ | Get-Content | ConvertFrom-Json} `
| Merge-Object -Strategy Fail
View medium-config-partials.ps1
function Select-ClusterSetPartialConfig([string]$Container, [string[]]$Vector) {
$clusterId = $Vector -join "-"
Get-ChildItem $Container `
| ? {$clusterId -like ($_.BaseName -replace "_", "*")}
}
View medium-todos-workitems.ps1
# constant parameters
$org = "MyAzureDevOpsOrgName"
$project = "MyAzureDevOpsProjectName"
$areaPath = "/the/area/path/containing/my/work/items"
$tag = "the-tag-that-identifies-work-items-as-automanaged"
$query = @"
SELECT *
FROM WorkItems
WHERE [Tags] CONTAINS '$tag'
View medium-todos-full.ps1
Param(
# Path to the repo containing TODO-annotated files
[Parameter(Mandatory)]
[ValidateScript({Test-Path $_ -PathType Container})]
[string]$RepoRoot
)
& {
enum Priority {
Low = 3
View medium-todos-defaultsort.ps1
... # previous param definition
& {
... # previous class and enum definitions
... # previous transformations
} | Sort Priority, FilePath, Line