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 Create-AesManagedObject($key, $IV) { | |
$aesManaged = New-Object "System.Security.Cryptography.AesManaged" | |
$aesManaged.Mode = [System.Security.Cryptography.CipherMode]::CBC | |
$aesManaged.Padding = [System.Security.Cryptography.PaddingMode]::Zeros | |
$aesManaged.BlockSize = 128 | |
$aesManaged.KeySize = 256 | |
if ($IV) { | |
if ($IV.getType().Name -eq "String") { | |
$aesManaged.IV = [System.Convert]::FromBase64String($IV) | |
} |
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 Start-Sleep($seconds) { | |
$doneDT = (Get-Date).AddSeconds($seconds) | |
while($doneDT -gt (Get-Date)) { | |
$secondsLeft = $doneDT.Subtract((Get-Date)).TotalSeconds | |
$percent = ($seconds - $secondsLeft) / $seconds * 100 | |
Write-Progress -Activity "Sleeping" -Status "Sleeping..." -SecondsRemaining $secondsLeft -PercentComplete $percent | |
[System.Threading.Thread]::Sleep(500) | |
} | |
Write-Progress -Activity "Sleeping" -Status "Sleeping..." -SecondsRemaining 0 -Completed | |
} |
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 Compare-XmlDocs($actual, $expected) { | |
if ($actual.Name -ne $expected.Name) { | |
throw "Actual name not same as expected: actual=" + $actual.Name | |
} | |
##attributes... | |
if ($actual.Attributes.Count -ne $expected.Attributes.Count) { | |
throw "attribute mismatch for actual=" + $actual.Name | |
} | |
for ($i=0;$i -lt $expected.Attributes.Count; $i =$i+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
## This code released under the MIT open source license. | |
## See here for details: https://opensource.org/licenses/MIT | |
## This code is provided with NO SUPPORT and NO WARRANTY and NO GUARANTEE. Use at your own risk. | |
[string] $ApiKey = "" | |
[string] $ApiSecret = "" | |
## only populate $indirectAccountNumber if you want a list from one specific account, otherwise leave blank. | |
[string] $indirectAccountNumber = "" | |
[string] $path = "AllMailboxes.csv" |
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 Send-MailgunEmail($from, $to, $subject, $body, $emaildomain, $apikey) { | |
$idpass = "api:$($apikey)" | |
$basicauth = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($idpass)) | |
$headers = @{ | |
Authorization = "Basic $basicauth" | |
} | |
$url = "https://api.mailgun.net/v2/$($emaildomain)/messages" | |
$body = @{ | |
from = $from; |
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 Get-XapiSignature($userAgent, $apiKey, $apiSecret) { | |
$dateTime = [DateTime]::UtcNow.ToString("yyyyMMddHHmmss"); | |
$dataToSign = [String]::Format("{0}{1}{2}{3}", $apikey, $userAgent, $dateTime, $apiSecret); | |
$sha1 = [System.Security.Cryptography.SHA1]::Create(); | |
$signedBytes = $sha1.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($dataToSign)); | |
$signature = [System.Convert]::ToBase64String($signedBytes); | |
$sha1.Dispose() | |
[String]::Format("{0}:{1}:{2}", $apikey, $dateTime, $signature); | |
} |
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; | |
using NUnit.Framework; | |
namespace RackspaceSoapTest | |
{ | |
[TestFixture] | |
public class Class1 | |
{ | |
[Test] | |
public void Test1() |
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; | |
using System.IO; | |
using System.Net; | |
using System.Text; | |
namespace TcpListener | |
{ | |
class Program | |
{ | |
static void Main(string[] args) |
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
public interface IGenericCache<T> | |
{ | |
TimeSpan CacheTtl { get; set; } | |
Func<T> LoadCache { get; set; } | |
T ReturnCache(); | |
T ForceRefresh(); | |
} | |
public class GenericCache<T> : IGenericCache<T> | |
{ |
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
public static class ParallelTaskRunnerExtension | |
{ | |
public static void RunTasks(this IEnumerable<Task> tasks, int maxConcurrency, Action<Task> taskComplete = null) | |
{ | |
if (maxConcurrency <= 0) throw new ArgumentException("maxConcurrency must be more than 0."); | |
int taskCount = 0; | |
int nextIndex = 0; | |
var currentTasks = new Task[maxConcurrency]; | |
foreach (var task in tasks) |
NewerOlder