Skip to content

Instantly share code, notes, and snippets.

View MartinMiles's full-sized avatar

Martin Miles MartinMiles

View GitHub Profile

Kubectl plugin

This plugin adds completion for the Kubernetes cluster manager, as well as some aliases for common kubectl commands.

To use it, add kubectl to the plugins array in your zshrc file:

plugins=(... kubectl)
@MartinMiles
MartinMiles / z.ExternalDatabase.config
Last active May 28, 2025 02:21
XM Cloud config to plug external database via SQL containers
<?xml version="1.0" encoding="UTF-8"?>
<configuration
xmlns:patch="www.sitecore.net/.../">
<sitecore>
<eventing defaultProvider="sitecore">
<eventQueueProvider>
<eventQueue name="rrh" patch:after="evertQueue[@name='web']" type="Sitecore.Data.Eventing.$(database)EventQueue, Sitecore.Kernel">
<param ref="dataApis/dataApi[@name='$(database)']" param1="$(name)" />
<param ref="PropertyStoreProvider/store[@name='$(name)']" />
</eventQueue>
# Define the folder path
$folderPath = "master:/sitecore/media library"
# Get all child media items recursively
$mediaItems = Get-ChildItem -Path $folderPath -Recurse -Language * -ErrorAction SilentlyContinue
# Calculate total size (in bytes) using the "Size" field
$totalSizeInBytes = 0
foreach ($item in $mediaItems) {
@MartinMiles
MartinMiles / Responsive-Nav.html
Created January 27, 2025 07:26
Just a responsive navigation bar for desktop and mobile layout
<!DOCTYPE html>
<html>
<head>
<style>
.navbar {
overflow: hidden;
background-color: #333;
}
.navbar a {
@MartinMiles
MartinMiles / Sitemap.aspx
Last active May 3, 2025 16:21
Admin folder tool for XM Cloud to regenerate the sitemap media library item in a development environment + sitemap generation at Next.js
<%@ Page language="c#" %>
<%@ Import Namespace="Microsoft.Extensions.DependencyInjection" %>
<%@ Import Namespace="Sitecore.Abstractions" %>
<%@ Import Namespace="Sitecore.Configuration" %>
<%@ Import Namespace="Sitecore.Data" %>
<%@ Import Namespace="Sitecore.Data.Items" %>
<%@ Import Namespace="Sitecore.DependencyInjection" %>
<%@ Import Namespace="Sitecore.Events" %>
<%@ Import Namespace="Sitecore.Globalization" %>
<%@ Import Namespace="Sitecore.Pipelines" %>
@MartinMiles
MartinMiles / Get-AllRenderingDefinitions-WITH-SITE-SPECIFIC-DATASOURCES.sql
Last active June 15, 2025 11:38
Gets the layout for the entire non-SXA website (tested on an example of Habitat with Sitecore 9.2)
--- PAY ATTENTION TO THE BELOW LINE !!!
use [Sitecore.Old]
GO
--------------------------------------------------------------------------------
-- 0) Identify layout‐field IDs
--------------------------------------------------------------------------------
DECLARE
@SharedLayoutFieldId UNIQUEIDENTIFIER,
@MartinMiles
MartinMiles / SPE.Remoting.Permissions.config
Last active June 18, 2025 10:01
Three configs to enable SPE & Remoting on XM Cloud (requires `SPE_REMOTING_SECRET` set in the .env file). Put these three files under `App_Config/Include/zzz` folder
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<httpRequestBegin>
<!--
We replace the existing RequireAuthentication processor (to preserve all its attributes)
and add our IgnoreRules list underneath.
-->
<processor
# Moves page items in bulk preserving the IDs (here's one level up, but could be anything, but did not work between databases):
param(
[string]$SourceDatabase = "master",
[string]$SourcePath = "sitecore/content/Zont/Habitat/Home/Home",
[string]$DestinationDatabase = "master",
[string]$DestinationPath = "sitecore/content/Zont/Habitat/Home"
)
# 1. Ensure both PS drives exist
-- We attach two legacy databases into a locally-run XM Cloud instance: "CoreOld" and "Old" (which is master)
EXEC sys.sp_configure N'contained database authentication', N'1'
go
exec ('RECONFIGURE WITH OVERRIDE')
go
CREATE DATABASE [Sitecore.Old]
ON (FILENAME = 'C:\data\Sitecore.Old_Primary.mdf'),
(FILENAME = 'C:\data\Sitecore.Old_Primary.ldf')
# Creates rendering definition item under a specified ID, in this case it is: {781C6B36-4B02-46EA-8ADC-B92A11877F10}
# 1. Define the full path for the rendering
$FullPath = "/sitecore/layout/Renderings/Feature/Zont/Teasers/Content Teaser with Summary"
# 2. Mount the master: PSDrive if it’s not already mounted
if (-not (Get-PSDrive -Name master -ErrorAction SilentlyContinue)) {
New-PSDrive -Name master -PSProvider Sitecore -Root "/" -Database "master" -ErrorAction Stop | Out-Null
}