Skip to content

Instantly share code, notes, and snippets.

View jermdavis's full-sized avatar
🐱

Jeremy Davis jermdavis

🐱
View GitHub Profile
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Sitecore.FiftyOneDegrees.CloudDeviceDetection.Services;
using Sitecore.FiftyOneDegrees.CloudDeviceDetection.Settings;
using Sitecore.FiftyOneDegrees.CloudDeviceDetection.System.Wrappers;
using System;
using System.Collections.Generic;
using System.IO;
using System.Web;
@jermdavis
jermdavis / LoggingExample.cs
Last active May 29, 2017 13:15
Pipelines with a shared logging mechanism
using System;
namespace StronglyTypedPipelines
{
public interface ILoggingPipeline
{
void RaiseMessage(IPipelineStep sender, string message, object data);
}
public abstract class LoggingPipelineStep<INPUT, OUTPUT> : IPipelineStep<INPUT, OUTPUT>
param(
[Parameter(Mandatory=$true)]
[string]$configFolder,
[Parameter(Mandatory=$true)]
[string]$configPattern,
[Parameter(Mandatory=$true)]
[string]$currentRoles
)
function Update-ConfigFile
@jermdavis
jermdavis / FunctionScheduler.cs
Last active May 12, 2018 20:28
Simple scheduler class
using System;
using System.Threading;
public class FunctionScheduler
{
private int _runEveryMs;
private Action _actionToRun;
private Timer _timer = null;
private object _lock = new object();
@jermdavis
jermdavis / keybase.md
Created May 29, 2019 16:33
Verifying myself for Keybase

Keybase proof

I hereby claim:

  • I am jermdavis on github.
  • I am jermdavis (https://keybase.io/jermdavis) on keybase.
  • I have a public key ASBCmmvpawRgYxXAmGg-piQyK4YuE-VmHghwBDPTQGRWuAo

To claim this, I am signing this object:

@jermdavis
jermdavis / Either.cs
Created February 17, 2019 15:54
An attempt at an error-friendly pipeline
public struct Either<SUCCESS, FAILURE>
{
private readonly bool _isSuccess;
private readonly SUCCESS _success;
private readonly FAILURE _failure;
public bool IsSuccess => _isSuccess;
public bool IsFailure => !IsSuccess;
public SUCCESS SuccessValue => _success;
@jermdavis
jermdavis / BasicPipeline.cs
Created February 15, 2019 14:38
An alternative example of a generic pipeline which includes logging behaviour
using System;
namespace LoggingPipeline
{
public interface IPipelineStep<INPUT, OUTPUT>
{
OUTPUT Process(INPUT input);
}
using System;
namespace StronglyTypedPipelines
{
public abstract class BasePipelineStep<INPUT, OUTPUT> : IPipelineStep<INPUT, OUTPUT>
{
public event Action<INPUT> OnInput;
public event Action<OUTPUT> OnOutput;
// note need for descendant types to implement this, not Process()
@jermdavis
jermdavis / BasePipelineTypes.cs
Last active June 11, 2021 07:48
Extending the code-first strongly typed pipelines to show how they might be loaded from config
using System;
namespace StronglyTypedPipelines
{
/// <summary>
/// A base interface required so that reflection code can create a Step from its type name,
/// without needing to understand its generic parameters first.
/// </summary>
public interface IPipelineStep
@jermdavis
jermdavis / AsyncPipelineExample-v2.cs
Last active November 23, 2021 13:28
An improved example for asynchronous pipeline code. See blog post for more info: https://blog.jermdavis.dev/posts/2021/a-second-pass-at-async-pipelines
async Task Main()
{
var pipeline = new ExampleAsyncPipeline();
var uri = new Uri("https://news.bbc.co.uk/");
var tempFile = await pipeline.ProcessAsync(uri);
Console.WriteLine($"{uri} saved to {tempFile}");
}