Skip to content

Instantly share code, notes, and snippets.

View tryfinally-6.ps1
function Invoke-WithStorageAccount {
Param(
[ValidateNotNullOrEmpty()]
[scriptblock]$ScriptBlock
)
$name = ("s$(New-Guid)" -replace "-").Substring(24)
$storageAccount = New-AzStorageAccount `
-ResourceGroupName "ephemeral-storages" `
-Name $name`
View tryfinally-5.ps1
Invoke-InDirectory $RepoRoot {
Invoke-InContext "Build ReactJS App" {
Invoke-InContext "Validate" {
Invoke-InContext "Lint" { yarn lint }
Invoke-InContext "Test" { yarn test }
}
Invoke-InContext "Transpile" { yarn build:ts }
Invoke-InContext "Bundle" { yarn webpack }
}
Invoke-InContext "Build Container" { docker build . }
View tryfinally-4.ps1
# ContextLogger.psm1
$ContextStack = [System.Collections.Stack]::new()
function Invoke-InContext {
Param(
[ValidateNotNullOrEmpty()]
[string] $Name,
[ValidateNotNullOrEmpty()]
[scriptblock] $ScriptBlock
View tryfinally-3.ps1
# invoke in repo root
Invoke-InDirectory "$PSScriptRoot/.." {
Invoke-InDirectory "./components" {
npm install
npm build
}
Invoke-InDirectory "./server" {
npm install
npm build
}
View tryfinally-2.ps1
function Invoke-InDirectory {
Param(
[ValidateScript( { Test-Path $_ -PathType Container } )]
[string] $Path,
[ValidateNotNullOrEmpty()]
[scriptblock] $ScriptBlock
)
try {
Push-Location $Path
View tryfinally-1.ps1
$ErrorActionPreference = "Stop"
Push-Location "./path/I/need/to/be/in"
try {
# do something here
} finally {
Pop-Location
}
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-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