Skip to content

Instantly share code, notes, and snippets.

Avatar

Chris Kuech chriskuech

  • Datum Source, ex MSFT
View GitHub Profile
@chriskuech
chriskuech / deploy.sh
Created Apr 5, 2019
Elastic Beanstalk NodeJS deployment script
View deploy.sh
#!/bin/bash
# ensure there are no uncommitted changes
git diff-index --quiet HEAD -- || { echo "Untracked changes" >&2; exit 1; }
# derive variables
branch="$(git symbolic-ref --short HEAD)"
timestamp="$(date +%Y%m%dT%H%M%S)"
# do work on a separate branch
@chriskuech
chriskuech / Export-PfxToBase64ps1
Last active Apr 8, 2019
Export PFX from Windows as Base64 string without password
View Export-PfxToBase64ps1
##
# Export PFX from Windows as Base64 string without password
#
$thumbprint = ""
[Convert]::ToBase64String((Get-Item Cert:\CurrentUser\My\$thumbprint).Export("pkcs12"))
View defensive-powershell-2.ps1
# declarative
[ValidateRange(0, 10)]
[int]$n = Read-Host
# imperative
[int]$n = Read-Host
if ($n -lt 0 -or $n -gt 10) {
throw [IndexOutOfRangeException]::new()
}
View defensive-powershell-4.ps1
[AttributeName("param1", "param2")]
$name = "value"
View defensive-powershell-5.ps1
[ValidateSet("ca", "eu", "us")]
$region = Read-Host
View defensive-powershell-6.ps1
function Deploy-Cluster {
Param(
[Parameter(Mandatory)]
[ValidatePattern("^[a-z]+-[a-z]+-[a-z]+-[0-9]+$")]
[string] $ClusterId
)
...
View defensive-powershell-7.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 defensive-powershell-8.ps1
function Get-Cluster {
[OutputType([Cluster])
Param(
[ValidateNotNullOrEmpty()]
[string[]] $serviceIds
)
$serviceIds | ForEach-Object {
$service, $flightingRing, $region, $idx = $_ -split "-"
[Cluster]@{