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
| public class Periodic : IDisposable | |
| { | |
| private static readonly object lockObject = new object(); | |
| private readonly List<PeriodicEvent> history = new List<PeriodicEvent>(); | |
| private readonly Action action; | |
| private readonly Timer timer; | |
| private long id = 0; | |
| public PeriodicEvent LatestEvent { get; private set; } |
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 Get-ResponseCode($url) { | |
| try { | |
| $response = Invoke-WebRequest $url | |
| $response.StatusCode | |
| } | |
| catch { | |
| $_.Exception.Response.StatusCode.Value__ | |
| } | |
| } |
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
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| ManualResetEventSlim manualResetEvent = null; | |
| Console.CancelKeyPress += (sender, eventArgs) => | |
| { | |
| Console.WriteLine("cancel!"); | |
| manualResetEvent?.Set(); |
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 Stop-ServiceAndWaitForItToDie { | |
| [cmdletbinding()] | |
| Param( | |
| [Parameter(Mandatory=$True,ValueFromPipeline=$True)] | |
| [object] $Service, | |
| [Parameter(Mandatory=$False,ValueFromPipeline=$False)] | |
| [int] $TimeoutInSeconds = 30, | |
| [Parameter(Mandatory=$False,ValueFromPipeline=$False)] | |
| [Switch] $KillAfterTimeout, | |
| [Parameter(Mandatory=$False,ValueFromPipeline=$False)] |
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
| $baseUrl = "https://blah.com" | |
| $servicePoint = [System.Net.ServicePointManager]::FindServicePoint($baseUrl) | |
| $url = "$baseUrl/blah/blah/blah" | |
| Invoke-RestMethod -Uri $url -Method Delete -ErrorAction Stop | |
| ##without this cleanup, the above line will stop working after two calls | |
| $ServicePoint.CloseConnectionGroup("") |
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
| **Encryption doesn't have to be difficult!** | |
| In this pragmatic talk we'll be discussing how to use cryptography in your application. | |
| As an example, we'll walk through how to use various cryptographic technologies to design an end-to-end encrypted chat application. | |
| What kind of encryption do you use? | |
| What are the most common and secure configurations? | |
| And most importantly how do you integrate it into your software? | |
| We'll address all these questions and walk through code samples in c#. | |
| We'll cover symmetrical (AES) and public-key cryptographic algorithms, along with multiple types of hashing, | |
| and various use-cases for each. | |
| Cryptography configuration can sometimes be tricky, but we'll look at the most secure and versatile configurations for each methodology. |
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 Send-SlackNotification($message) { | |
| $url = "https://slack.com/api/chat.postMessage" | |
| $headers = @{"Content-Type"="application/x-www-form-urlencoded";"User-Agent"="SlackBot"} | |
| $body = @{ token="PUT_YOUR_BOT_KEY_HERE"; channel="PUT_CHANNEL_HERE"; text=$message; as_user="true"; } | |
| ##If you are using powershell v5 you can change this to Invoke-RestMethod. | |
| ##The UsePasicParsing option is not supported in v4 for Invoke-RestMethod, and you really want that option. | |
| $result = Invoke-WebRequest -Uri $url -Body $body -Headers $headers -Method Post -ErrorAction SilentlyContinue -UseBasicParsing | |
| $result.Content | ConvertFrom-Json | |
| } |
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
| public static void SetInt64(this ISession session, string key, long lng) | |
| { | |
| var bytes = BitConverter.GetBytes(lng); | |
| session.Set(key, bytes); | |
| } | |
| public static long GetInt64(this ISession session, string key, long defaultIfNull) | |
| { | |
| var bytes = session.Get(key); | |
| if (bytes == null || bytes.Length == 0) |
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 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 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 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 | |
| } |