Skip to content

Instantly share code, notes, and snippets.

View jermdavis's full-sized avatar
🐱

Jeremy Davis jermdavis

🐱
View GitHub Profile
@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 / AdvancedCache.aspx
Last active October 3, 2022 19:56
A fix to make https://briancaos.wordpress.com/2017/05/01/sitecore-caching-clear-caches-individually/ work on Sitecore 10, plus a quick hack to view the contents of each cache (for data that can be easily displayed)
<%@ page language="c#" enableeventvalidation="false" autoeventwireup="true" enableviewstate="false" %>
<%@ import namespace="System.Security.Permissions" %>
<%@ import namespace="System.Collections.Generic" %>
<%@ import namespace="System.Threading" %>
<%@ import namespace="System.Security.Principal" %>
<%@ import namespace="Newtonsoft.Json" %>
<%@ import namespace="Sitecore.Data.Items" %>
<script runat="server">
@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);
}
@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 / SolrInstall-SIF-Extension.psm1
Last active November 23, 2021 13:29
Installing Solr for Sitecore v9.1 using SIF's createcert.json - Blog post explaining this at: https://blog.jermdavis.dev/posts/2019/a-second-attempt-at-installing-solr-with-sif
##
## private functions
##
#
# If necessary, download a file and unzip it to the specified location
#
function downloadAndUnzipIfRequired
{
Param(
@jermdavis
jermdavis / Extract-TarGz.ps1
Created May 9, 2019 14:14
A PowerShell script that can extract .tar.gz files on Windows - with minimal dependencies to make it easy to use on servers.
[cmdletbinding(SupportsShouldProcess=$True)]
param(
# What .tar.gz file should be extracted? Must exist.
[Parameter(Mandatory=$True)]
[string]$FileToExtract,
# What folder should the files be extracted into? Does not need to exist
[Parameter(Mandatory=$True)]
[string]$TargetFolder,
@jermdavis
jermdavis / ClipboardFileTransfer.psm1
Last active November 23, 2021 13:31
A helpful PowerShell module that lets you move (smallish) files over the clipboard - useful when you have RDP access to a machine but are not allowed to share drives. See https://blog.jermdavis.dev/posts/2019/a-little-powershell-hack-for-sending-files-to-a-remote-machine for info.
function Write-EmbeddedFile
{
param
(
[string]$base64,
[string]$targetFile
)
process
{
$Content = [System.Convert]::FromBase64String($base64)
@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 / AsyncPipelineExample-v1.cs
Last active February 15, 2023 11:33
An initial (not great) example for asynchronous pipeline code. See blog post for more info: https://blog.jermdavis.dev/posts/2021/pipelines-and-async BUT you probably want this gist instead, because it's the (hopefully better) v2: https://gist.github.com/jermdavis/49ecd692a16b10899eb2ee2b50770499
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}");
}
@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}");
}