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 / 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 / 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-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 / 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 / LoopStep.cs
Created October 26, 2016 11:17
A possible looped pipeline step for processing IEnumerable<> inputs
using System.Collections.Generic;
namespace StronglyTypedPipelines
{
public class LoopStep<INPUT,OUTPUT> : IPipelineStep<IEnumerable<INPUT>, IEnumerable<OUTPUT>>
{
private IPipelineStep<INPUT, OUTPUT> _internalStep;
public LoopStep(IPipelineStep<INPUT, OUTPUT> internalStep)
@jermdavis
jermdavis / BasePipelineTypes.cs
Last active December 20, 2021 16:08
An example of strongly typed data pipelines, with some trivial examples
using System;
namespace StronglyTypedPipelines
{
/// <summary>
/// Base type for individual pipeline steps.
/// Descendants of this type map an input value to an output value.
/// The input and output types can differ.
/// </summary>
@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 / DownloadFromSitecore.ps1
Last active November 23, 2021 13:30
Download files from dev.sitecore.net from the commandline - see https://blog.jermdavis.dev/posts/2017/downloading-stuff-from-dev-sitecore-net for info
param(
[Parameter(Mandatory=$true)]
[string]$url,
[Parameter(Mandatory=$true)]
[string]$target
)
function Fetch-WebsiteCredentials
{
$file = "dev.creds.xml"
@jermdavis
jermdavis / Install-Solr.ps1
Last active November 23, 2021 13:30
A PowerShell script to help installing Solr as a service - See https://blog.jermdavis.dev/posts/2017/low-effort-solr-installs for details
Param(
$solrVersion = "6.6.2",
$installFolder = "c:\solr",
$solrPort = "8983",
$solrHost = "solr",
$solrSSL = $true,
$nssmVersion = "2.24",
$JREVersion = "1.8.0_151"
)