Skip to content

Instantly share code, notes, and snippets.

View jermdavis's full-sized avatar
🐱

Jeremy Davis jermdavis

🐱
View GitHub Profile
@jermdavis
jermdavis / ExpiringLinkConfigurator.cs
Last active April 22, 2024 07:14
Example code for expiring outdated links in Statiq. Example code for a blog post: https://blog.jermdavis.dev/posts/2024/expiring-outdated-blog-links - More info there.
using Statiq.App;
using Statiq.Common;
using StatiqGenerator.Customisations.ReadingTime;
namespace StatiqGenerator.Customisations.DisappearingLinks
{
public class ExpiringLinkConfigurator : IConfigurator<Bootstrapper>
{
public void Configure(Bootstrapper configurable)
@jermdavis
jermdavis / 1_install-docker.ps1
Last active April 6, 2023 21:50
A first pass at a script for installing Docker without using Docker Desktop
#Requires -RunAsAdministrator
param(
[string]$dockerEnginePath = "C:\",
[string]$dockerInstallPath = "C:\Docker",
[string]$dockerEngineUrl = "https://download.docker.com/win/static/stable/x86_64/docker-20.10.8.zip",
[string]$dockerZip = "docker.zip",
[string]$serviceName = "docker",
[string]$composeEngineUrl = "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-Windows-x86_64.exe",
@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}");
}
@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 / 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 / ClipboardFileTransfer.psm1
Last active August 4, 2024 02:37
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 / 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 / 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 / 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);
}