Skip to content

Instantly share code, notes, and snippets.

View kerslake's full-sized avatar

Richard Kerslake kerslake

View GitHub Profile
[EventSource(Name="Company-EventLog")]
public sealed class MyEventSource : EventSource
{
public static MyEventSource Log = new MyEventSource();
[Event(1, Message="Request submitted: {0}", Channel = EventChannel.Operational)]
public void RequestSubmitted(string requestId)
{
this.WriteEvent(1, requestId);
}
MyEventSource.Log.RequestSubmitted("12345");
wevtutil.exe im C:\temp\mynamespace.Company-EventLog.etwManifest.man /rf:"C:\temp\mynamespace.Company-EventLog.etwManifest.dll" /mf:"C:\temp\mynamespace.Company-EventLog.etwManifest.dll"
wevtutil um C:\temp\mynamespace.Company-EventLog.etwManifest.man
logman.exe create trace my-trace-session -p Company-EventLog
logman.exe start my-trace-session
logman.exe stop my-trace-session
logman.exe delete my-trace-session
var streamOverTime = Observable.Interval(TimeSpan.FromSeconds(1));
var squaredStreamOverTime = streamOverTime.Select(value => Math.Pow(value, 2));
squaredStreamOverTime.Subscribe(Console.WriteLine);
function Retry-Command
{
param (
[Parameter(Mandatory=$true)][string]$command,
[Parameter(Mandatory=$true)][hashtable]$args,
[Parameter(Mandatory=$false)][int]$retries = 5,
[Parameter(Mandatory=$false)][int]$secondsDelay = 2
)
# Setting ErrorAction to Stop is important. This ensures any errors that occur in the command are
Retry-Command -Command 'Get-Process' -Args @{ Id = "8156" } -Verbose
VERBOSE: Command [Get-Process] failed. Retrying in 2 seconds.
VERBOSE: Command [Get-Process] failed. Retrying in 2 seconds.
VERBOSE: Command [Get-Process] failed. Retrying in 2 seconds.
VERBOSE: Command [Get-Process] failed. Retrying in 2 seconds.
VERBOSE: Command [Get-Process] failed. Retrying in 2 seconds.
VERBOSE: Command [Get-Process] failed the maximum number of 5 times.
Cannot find a process with the process identifier 8156999.
At C:\Retry-Command-usage.ps1:line:19 char:13
+ & <<<< $command @args
Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
------- ------ ----- ----- ----- ------ -- -----------
4197 559 1103124 1238548 2052 426.22 8156 devenv
VERBOSE: Command [Get-Process] succeeded.
public class WelcomeController : TwilioApiController
{
public HttpResponseMessage Post(VoiceRequest request)
{
var response = new TwilioResponse();
response.Say("Welcome to this Twilio demo app. Please enter your 3 digit pin code.");
response.Gather(new { numDigits = 3, action = string.Format("/api/Authenticate") });
return this.TwiMLResponse(response);
}