This file contains 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
// Requires: https://github.com/gsscoder/csharpx | |
using System; | |
using System.Linq; | |
using CSharpx; | |
static class RandomString | |
{ | |
const string _alphanumeric = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
const string _chars = "abcdefghijklmnopqrstuvwxyz0123456789!\"#$%&'()*@[\\]^_`{|}~ABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
This file contains 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.Collections.Generic; | |
using System.Threading.Tasks; | |
using Microsoft.Azure.Cosmos; | |
public static class FeedIteratorExtensions | |
{ | |
public static async Task<IEnumerable<T>> ReadAllAsync<T>(this FeedIterator<T> iterator) | |
{ | |
var result = new List<T>(); | |
while (iterator.HasMoreResults) { |
This file contains 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.Collections.Generic; | |
public static class DictionaryExtensions | |
{ | |
public static IDictionary<T, U> Merge<T, U>(this IDictionary<T, U> target, IDictionary<T, U> source) | |
{ | |
var result = new Dictionary<T, U>(target); | |
foreach (var pair in target) { | |
if (source.ContainsKey(pair.Key)) { | |
result[pair.Key] = source[pair.Key]; |
This file contains 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.Collections.Generic; | |
public static class ObjectExtensions { | |
public static IDictionary<string, string> ToDictionary(this object obj) => | |
ToDictionary<string>(obj); | |
public static IDictionary<string, T> ToDictionary<T>(this object obj) | |
{ | |
var properties = obj.GetType().GetProperties(); |
This file contains 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
$token = '*************YOUR****TOKEN******HERE******************************************************' | |
$workspaceId = 'ws-bbaGwqP1yANww4va' | |
$response = Invoke-WebRequest -Uri "https://app.terraform.io/api/v2/workspaces/$workspaceId/runs" ` | |
-Method Get ` | |
-ContentType 'application/vnd.api+json' ` | |
-Headers @{ | |
Authorization = "Bearer $token" | |
} ` | |
-UseBasicParsing |
This file contains 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
export class DateHelper { | |
public static getWeekDay(locale: string, day: number, format: string = 'long') { | |
if (day <=0 || day > 7) throw new Error('Invalid day number. Expected to be in range of 1-7.'); | |
let baseDate = new Date(Date.UTC(2000, 0, 3)); // Monday | |
baseDate.setDate(baseDate.getDate() + day - 1); | |
return baseDate.toLocaleDateString(locale, { weekday: format }); | |
} | |
public static getMonth(locale: string, month: number, format: string = 'long') { | |
if (month <=0 || month > 12) throw new Error('Invalid month number. Expected to be in range of 1-12.'); |
This file contains 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 Test-Url([Parameter(ValueFromPipeline)] [string] $url) { | |
$url -cmatch '^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)$' | |
} | |
function Test-Guid([Parameter(ValueFromPipeline)] [string] $guid) { | |
try { [System.Guid]::Parse($guid) | Out-Null; $true } catch { $false } | |
} | |
function Test-IPAddress([Parameter(ValueFromPipeline)] [string] $ip, [switch] $cidr) { | |
if ($cidr) { $ip -match '^(?:\d{1,3}\.){3}\d{1,3}/\d\d$' } |
This file contains 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."))); |
This file contains 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 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 |