Skip to content

Instantly share code, notes, and snippets.

View techthoughts2's full-sized avatar
🕵️‍♂️
Investigating a better artifact workflow

Jake Morrison techthoughts2

🕵️‍♂️
Investigating a better artifact workflow
View GitHub Profile
@techthoughts2
techthoughts2 / route53.yml
Created March 22, 2019 14:44
Creates an Amazon Route 53 hosted zone
AWSTemplateFormatVersion: '2010-09-09'
Description: Creates an Amazon Route 53 hosted zone
Parameters:
DomainName:
Type: String
Description: The DNS name of an Amazon Route 53 hosted zone e.g. jevsejev.io
AllowedPattern: (?!-)[a-zA-Z0-9-.]{1,63}(?<!-)
ConstraintDescription: must be a valid DNS zone name.
Resources:
DNS:
@techthoughts2
techthoughts2 / python.json
Last active February 23, 2023 11:02
Collection of Python Snippets for VSCode
{
"if": {
"prefix": "if",
"body": ["if ${1:expression}:", "\t${2:pass}"],
"description": "Code snippet for an if statement"
},
"if/else": {
"prefix": "if/else",
"body": ["if ${1:condition}:", "\t${2:pass}", "else:", "\t${3:pass}"],
"description": "Code snippet for an if statement with else"
@techthoughts2
techthoughts2 / pester_parameter_mock
Last active January 5, 2023 04:55
Pester test a command that should be called with certain parameters
# test a command that should be called with certain parameters
#------------------------------------------------------------------------------
It 'should call the API with the expected parameters' {
Mock -CommandName Invoke-RestMethod {
} -Verifiable -ParameterFilter { $Uri -like 'https://api.telegram.org/bot*getStickerSet*' }
# "https://api.telegram.org/bot$BotToken/getStickerSet"
$getTelegramStickerPackInfoSplat = @{
BotToken = $token
StickerSetName = 'STPicard'
}
# https://learn.microsoft.com/en-us/powershell/scripting/learn/deep-dives/everything-about-shouldprocess?view=powershell-7.3
[CmdletBinding(ConfirmImpact = 'Low',
SupportsShouldProcess = $true)]
# $PSCmdlet.ShouldProcess('TARGET')
# $PSCmdlet.ShouldProcess('TARGET','OPERATION')
# $PSCmdlet.ShouldProcess('MESSAGE','TARGET','OPERATION')
# -Confirm --> $ConfirmPreference = 'Low'
# ShouldProcess intercepts WhatIf* --> no need to pass it on
DynamicParam {
if (-not [String]::IsNullOrWhiteSpace($CICDChoice) -and $script:repoToCICD.ContainsKey($CICDChoice) ) {
$attrRepo = [System.Management.Automation.ParameterAttribute]::new()
$attrRepo.ParameterSetName = 'Choice'
$attrRepo.Mandatory = $true
$attrRepo.HelpMessage = 'TBD'
$attrRepoValidation = [System.Management.Automation.ValidateSetAttribute]::new([String[]]$script:repoToCICD[$CICDChoice])
$attributeCollection = [System.Collections.ObjectModel.Collection[System.Attribute]]::new()
# use generic list to add objects in a performant way
$starTrekShowInfo = New-Object System.Collections.Generic.List[string]
$starTrekShowInfo.Add('Star Trek: The Next Generation')
# use custom objects for high performance adds of custom object
$choiceArray = New-Object System.Collections.Generic.List[PSCustomObject]
#------------------------------------------------------------------------------
# old method which should no longer be used IAW:
# https://docs.microsoft.com/en-us/dotnet/api/system.collections.arraylist?view=net-6.0
# adding stuff to emtpy array objects quickly
@techthoughts2
techthoughts2 / vs_code_extensions
Last active December 2, 2022 17:59
List of Visual Studio Code extensions that I am currently using. Heavy focus with PowerShell development and AWS CloudFormation.
<#
CoenraadS.bracket-pair-colorizer-2
DanielThielking.aws-cloudformation-yaml
DavidAnson.vscode-markdownlint
DotJoshJohnson.xml
PKief.material-icon-theme
SirTori.indenticator
Tyriar.shell-launcher
aaron-bond.better-comments
almenon.arepl
@techthoughts2
techthoughts2 / cdk_pwsh_runtime_bootstrap.ps1
Last active September 30, 2022 14:30
## Synopsis This helper script can be used to bootstrap a CDK project for deploying PowerShell Lambdas using the custom PowerShell Runtime via Lambda Layers. ## Description - Quickly bootstraps a CDK project for deploying lambdas using the custom
#region settings
#! Enter all required modules you want to bootstrap for use in your PowerShell lambda layers
$requiredModules = @(
@{
ModuleName = 'AWS.Tools.Common'
ModuleVersion = '4.1.175'
},
@{
ModuleName = 'PoshGram'
@techthoughts2
techthoughts2 / NewDirCheck.ps1
Last active September 26, 2022 12:02
Evaluates if a directory is present. if not found, the specified directory will be created.
if (-not(Test-Path -Path $TargetDir -ErrorAction Stop )) {
Write-Verbose -Message ('Output directory {0} not found. Creating...' -f $TargetDir)
$newItemSplat = @{
ItemType = 'Directory'
Path = $TargetDir
ErrorAction = 'Stop'
}
try {
New-Item @newItemSplat
Write-Verbose -Message 'Created.'
# AWS CDK Typescript setup on Windows
## Install Requirements
```bash
# install nodejs
winget install OpenJS.NodeJS
# if already installed upgrade
winget upgrade OpenJS.NodeJS