Skip to content

Instantly share code, notes, and snippets.

View tcmorris's full-sized avatar
👋

Thomas Morris tcmorris

👋
View GitHub Profile
@tcmorris
tcmorris / umbraco8-cleanup.sql
Created January 20, 2022 14:25
Remove previous versions that are no longer published from the umbraco database
SELECT cv.id
INTO #toDelete
FROM umbracoDocumentVersion dv
INNER JOIN umbracoContentVersion cv ON dv.id = cv.id
WHERE cv.[current] != 1 AND dv.published != 1 AND cv.VersionDate < '2021-01-01'
DELETE FROM umbracoPropertyData WHERE versionId IN (select id from #toDelete)
DELETE FROM umbracoDocumentVersion WHERE id IN (select id from #toDelete)
DELETE FROM umbracoContentVersionCultureVariation WHERE versionId IN (select id from #toDelete)
DELETE FROM umbracoContentVersion WHERE id IN (select id from #toDelete)
@tcmorris
tcmorris / github-action-nodejs.yml
Created August 20, 2020 16:00
Example GitHub Action for building with node.js
name: Build node.js
on: [push]
env:
NODE_VERSION: '10.x'
jobs:
build-assets:
runs-on: ubuntu-latest
@tcmorris
tcmorris / github-action-dotnet.yml
Created August 20, 2020 15:58
Example GitHub Action for building and deploying a .NET Core app to Azure.
name: Build and deploy to Azure
on: [push]
env:
PROJECT_DIR: yourapp/path
AZURE_WEBAPP_NAME: yourapp-name
DOTNET_VERSION: '2.2.402'
jobs:
@tcmorris
tcmorris / CustomMigrationEventHandler
Created October 1, 2018 08:08
Umbraco Migrations example
public class CustomMigrationEventHandler : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
// check target version
var rawTargetVersion = ConfigurationManager.AppSettings["app:MigrationVersion"] ?? "1.0.0";
var targetVersion = SemVersion.Parse(rawTargetVersion);
if (targetVersion != null)
{
HandleMigrations(targetVersion);
@tcmorris
tcmorris / archive.html
Last active July 2, 2017 13:29
Example events listing in Jekyll
{% include events.html previous=true year="2017" %}
@tcmorris
tcmorris / MediaEventHandler.cs
Last active June 15, 2017 10:02
Event Handler for checking media uploads in Umbraco
/// <summary>
/// MediaEventHandler
/// Will hook into the MediaService saving event and apply some custom logic to ensure we have a valid media file.
/// </summary>
public class MediaEventHandler : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
MediaService.Saving += MediaService_Saving;
}
@tcmorris
tcmorris / RegexPatterns.cs
Created December 2, 2016 10:37
Regex Patterns
public static class RegexPatterns
{
public const string Postcode = "^(GIR 0AA|gir 0aa|[A-PR-UWYZa-pr-uwyz]([0-9]{1,2}|([A-HK-Ya-hk-y][0-9]|[A-HK-Ya-hk-y][0-9]([0-9]|[ABEHMNPRV-Yabehmnprv-y]))|[0-9][A-HJKPS-UWa-hjkps-uw]) {0,1}[0-9][ABD-HJLNP-UW-Zabd-hjlnp-uw-z]{2})$";
public const string EmailAddress = "^[a-zA-Z0-9._%+-]+@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z0-9-]{2,63}$";
}
@tcmorris
tcmorris / deploy.targets
Last active August 29, 2015 14:24
MSBuild targets for config transforms. Will pick up any *.config in root or config folder per environment and also allows for machine specific transforms.
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="TransformXml" AssemblyFile=".\Deploy\Microsoft.Web.Publishing.Tasks.dll" />
<ItemGroup>
<ConfigFiles Include=".\*.$(Environment).config;.\config\*.$(Environment).config">
<OriginalPath>%(ConfigFiles.RootDir)%(ConfigFiles.Directory)$([System.String]::Copy('%(ConfigFiles.Filename)').Replace('.$(Environment)',''))%(ConfigFiles.Extension)</OriginalPath>
</ConfigFiles>
<ConfigFiles Include=".\*.$(COMPUTERNAME).config;.\config\*.$(COMPUTERNAME).config">
@tcmorris
tcmorris / redirect
Last active August 29, 2015 14:17
Using a custom domain for accessing umbraco
<!-- Restrict access to Umbraco -->
<rule name="Restrict access" stopProcessing="true">
<match url="umbraco(?!/Surface/)" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="false">
<add input="{HTTP_HOST}" matchType="Pattern" pattern="admin.example.com"
ignoreCase="true" negate="true" />
</conditions>
<action type="Redirect" url="/not-found" appendQueryString="false" />
</rule>
@tcmorris
tcmorris / X-Robots-Tag
Last active August 29, 2015 14:13
Pages should not show in search results, links should not be followed and images should not be indexed.
<!--
Avoid search engines (Google, Yahoo, etc) indexing website's content
This method is preferred to using robots.txt, which may still cause your site to
show in search engine result pages even if you have set to disallow.
http://yoast.com/prevent-site-being-indexed/
http://code.google.com/web/controlcrawlindex/docs/robots_meta_tag.html
http://www.youtube.com/watch?v=KBdEwpRQRD0
-->