This file contains hidden or 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 Install { | |
[OutputType([void])] | |
param ( | |
[Parameter(Mandatory, ValueFromPipeline)] [string] $Module, | |
[Parameter(Mandatory)] [ValidatePattern("^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,9}$")] [string] $Version | |
) | |
"Testing module '$Module' presence." | Write-Verbose | |
$moduleInfo = Get-InstalledModule $Module -ErrorAction SilentlyContinue -Verbose:$false | |
if (-not $moduleInfo) { | |
"Module '$Module' not present. Attempting installation." | Write-Verbose |
This file contains hidden or 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
Set-StrictMode -Version Latest | |
function Test-Property([Parameter(ValueFromPipeline)] $object, [string] $name) { | |
try { $name -cin $object.PSObject.Properties.Name } | |
catch { $false } | |
} | |
$path = '/Users/someone/temp/file.json' | |
$json = $path | Get-Content -Raw | ConvertFrom-Json | |
[bool] $exists = $json.someKey | Test-Property -name 'someOtherKey' |
This file contains hidden or 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
# This code actually doesn't work. | |
$secret = 'B=EBh3glTf523Xj@uLGO]o@kSteLoC@O' | |
$group = 'INTRANETAI-Europe-DEV' | |
$service = 'intranetai-europe-test-dev' | |
$context = New-AzApiManagementContext -ResourceGroupName $group -ServiceName $service | |
$versionSet = New-AzApiManagementApiVersionSet -Context $context -Name 'news' ` | |
-Scheme Header -HeaderName 'x-api-version' ` |
This file contains hidden or 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
# 'hello-wonderful-world' | ConvertTo-PascalCase | |
# outcome: HelloWonderfulWorld | |
function ConvertTo-PascalCase([Parameter(ValueFromPipeline)] [string] $text) { | |
($text -split '-' | ForEach-Object { | |
"$($_.ToCharArray()[0].ToString().ToUpper())$($_.Substring(1))" }) -join '' | |
} |
This file contains hidden or 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
trigger: | |
- none | |
pool: | |
vmImage: 'windows-latest' | |
steps: | |
- powershell: | | |
$value = Select-String -Path 'azure-pipelines.yml' -Pattern "(?<=vmImage:\s').*(?='$)" | |
if ($value -like '*windows*') { |
This file contains hidden or 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; | |
using System.Collections.Immutable; | |
using System.Linq; | |
using ExpressionEngine; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var context = new Context(); |
This file contains hidden or 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 yieldNumbers() : IterableIterator<number> { | |
return generator() | |
function *generator(): IterableIterator<number> { | |
yield 0 | |
yield 1 | |
yield 2 | |
yield 3 | |
} | |
} |
This file contains hidden or 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
// $ tsc factorial.ts && node factorial.js | |
// 3628800 | |
function factorial(num: number) : number { | |
if (num == 0) return 1 | |
else return num * factorial(num - 1) | |
} | |
console.log(factorial(10)) |
This file contains hidden or 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
#!/bin/sh | |
sudo rm -rf /private/var/log/asl/*.asl |
This file contains hidden or 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; | |
using System.Linq; | |
using System.Runtime.CompilerServices; | |
static class Guard | |
{ | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
public static void AgainstNull(string argumentName, object value) | |
{ | |
if (value == null) throw new ArgumentNullException(argumentName, $"{argumentName} cannot be null."); |