Skip to content

Instantly share code, notes, and snippets.

Working from home

Christian Findlay MelbourneDeveloper

Working from home
View GitHub Profile
MelbourneDeveloper / LogCheckExtensions.cs
Last active Apr 10, 2021
ILogger Verification with Moq
View LogCheckExtensions.cs
using Microsoft.Extensions.Logging;
using Moq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
// More detailed samples here:
MelbourneDeveloper / Observer.cs
Created Feb 21, 2021
Observer with Null Object Pattern
View Observer.cs
internal class Observer<T> : IObserver<T>
static Action<Exception> onError = ((e) => { });
static Action onCompleted = (() => { });
private readonly Action<T> _onNext;
private readonly Action<Exception> _onError;
private readonly Action _onCompleted;
public Observer(
MelbourneDeveloper / Program.cs
Last active Feb 14, 2021
Null Object Example
View Program.cs
#nullable enable
namespace NullObjectExample
class Program
static void Main()
var someService = new SomeService();
View NullGuardExample.cs
#nullable enable
using System;
namespace Sample
public class NullGuardExample
public string NotNullableProperty { get; }
public string? NullableProperty { get; }
MelbourneDeveloper / Program.cs
Created Feb 13, 2021
Nullable Reference Types Minimal Console App Sample
View Program.cs
#nullable enable
using Sample;
using System;
var testRecord = new TestRecord("Hi", null);
namespace Sample
MelbourneDeveloper / PersonController.cs
Last active Feb 7, 2021
Smallest Controller Saple
View PersonController.cs
using Microsoft.AspNetCore.Mvc;
namespace WebApplication1.Controllers
public class PersonController : ControllerBase
public string Get(string firstName, string lastName) => $"{firstName} {lastName}";
View temperature.cs
private static async Task DisplayTemperature()
//Connect to the device by product id and vendor id
var temperDevice = await new FilterDeviceDefinition(vendorId: 0x413d, productId: 0x2107, usagePage: 65280)
//Create the observable
var observable = Observable
MelbourneDeveloper / retry.cs
Created Jan 31, 2021
Perform Control Transfer With Retry
View retry.cs
public static Task<T> PerformControlTransferWithRetry<T>(
this IUsbDevice usbDevice,
Func<IUsbDevice, Task<T>> func,
int retryCount = 3,
int sleepDurationMilliseconds = 250)
var retryPolicy = Policy
View timeout.cs
var cancellationTokenSource = new CancellationTokenSource();
//Fire a timeout after 1000 milliseconds
var result = await device.WriteAndReadAsync(writeData, cancellationTokenSource.Token);
MelbourneDeveloper / ClearStatus.cs
Created Jan 31, 2021
Control Transfer Clear Status
View ClearStatus.cs
public static Task ClearStatusAsync(this IUsbDevice usbDevice)
=> usbDevice.PerformControlTransferAsync(new SetupPacket
requestType: new UsbDeviceRequestType(
length: 0