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
| 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
| 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
| 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
| # '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
| # 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
| 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
| 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
| # addtag.sh | |
| ########### | |
| #!/bin/sh | |
| git tag -a v$1 -m "Version $1" && git push origin --follow-tags | |
| # rmtag.sh | |
| ########## | |
| #!/bin/sh | |
| git tag -d v$1 && git push origin -d v$1 |
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
| // Based on: https://docs.microsoft.com/en-gb/archive/blogs/jaredpar/switching-on-types | |
| // Example: | |
| // TypeSwitch.Do(propertyInfo.PropertyType, | |
| // TypeSwitch.Case<bool>(() => value = property.Value.GetBoolean()), | |
| // TypeSwitch.Case<int>(() => value = property.Value.GetInt32()), | |
| // TypeSwitch.Case<long>(() => value = property.Value.GetInt64()), | |
| // TypeSwitch.Case<double>(() => value = property.Value.GetDouble()), | |
| // TypeSwitch.Case<string>(() => value = property.Value.GetString()), | |
| // TypeSwitch.Default(() => throw new InvalidOperationException("Type is not supported."))); |