Skip to content

Instantly share code, notes, and snippets.

View jamiepollock's full-sized avatar

Jamie Pollock jamiepollock

View GitHub Profile
@jamiepollock
jamiepollock / ProtectConfiguredError404PagesComponent.cs
Last active February 7, 2020 07:37
An Umbraco 8 component/composer for protecting pages that are configured as 404 pages in umbracoSettings.config.
namespace MyApplication.Components
{
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core.Composing;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.Events;
using Umbraco.Core.Models.Entities;
using Umbraco.Core.Services.Implement;
@jamiepollock
jamiepollock / PreRequestScript.js
Created September 5, 2018 15:16
Postman JS Pre-request script for dynamic dates.
var moment = require('moment');
// Allows dates to be offset in the past rather than right now. offset format "hh:mm:ss".
// "24:00:00" would be 24hrs in the past.
var offsetValue = pm.globals.get("offset");
var offset = moment.duration(offsetValue);
// Determines the duration between start & end dates format "hh:mm:ss"
// "00:30:00" would be a 30 minute delay.
var durationValue = pm.globals.get("duration");
@jamiepollock
jamiepollock / eu_cookie_banner.js
Created March 19, 2018 19:56 — forked from bavington/eu_cookie_banner.js
Simple EU Cookie Law Banner JavaScript
@jamiepollock
jamiepollock / CustomMigrationBase.cs
Last active January 22, 2018 16:49
A layer on top of Umbraco's MigrationBase for checking a table has Indexes, Constraints & Columns
using System.Linq;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence.Migrations;
using Umbraco.Core.Persistence.SqlSyntax;
namespace My.Website.Migrations
{
public abstract class CustomMigrationBase : MigrationBase
{
public CustomMigrationBase(ISqlSyntaxProvider sqlSyntax, ILogger logger) : base(sqlSyntax, logger)
@jamiepollock
jamiepollock / Bootstrap3.cshtml
Created April 16, 2017 00:35
Example of Umbraco GridSettings using the Bootstrap3.cshtml with Umbraco v7.5.4+
@inherits UmbracoViewPage<dynamic>
@using Umbraco.Web.Templates;
@using Newtonsoft.Json.Linq;
@using Our.Umbraco.GridSettings.Web;
@using Our.Umbraco.GridSettings.Services;
@using Our.Umbraco.GridSettings.Resolvers;
@{
var attributesResolver = new GroupByPrefixTokenGridSettingsAttributesResolver("_");
var attributesService = new GridSettingsAttributesService(attributesResolver);
}
@jamiepollock
jamiepollock / MyController.cs
Last active October 8, 2019 15:27
Umbraco XPath query with tokens
using System.Web.Mvc;
using Umbraco.Web.Models;
using Umbraco.Web;
using Umbraco.Core.Xml;
using Umbraco.Web.Mvc;
namespace MyWebsite.Controllers
{
public class MyController : RenderMvcController
{
@jamiepollock
jamiepollock / DecimalTests.cs
Created February 1, 2017 04:03
Tests for Decimal conversion in Umbraco Ditto
using NUnit.Framework;
using Our.Umbraco.Ditto.Tests.Mocks;
namespace Our.Umbraco.Ditto.Tests
{
[TestFixture]
[Category("Processors")]
public class DecimalTests
{
public class MyModel
@jamiepollock
jamiepollock / FormHtmlApiController.cs
Created January 26, 2017 19:12
In Theory (TM)! How to return an Umbraco Form HTML from an ApiController
using System.Web;
using Umbraco.Web.WebApi;
namespace My.Website.Controllers.Api
{
public class FormHtmlApiController : UmbracoApiController
{
public IHtmlString Get(string id)
{
return Umbraco.RenderMacro("FormsRenderForm", new { FormGuid = id });
@jamiepollock
jamiepollock / LocalizedEditorModelEventManagerEventHandler.cs
Created October 21, 2016 16:30
Working with EditorModelEventManager to localise an EditorContentModel powered by /config/lang/*.user.xml files
using System.Collections.Generic;
using System.Globalization;
using Umbraco.Core;
using Umbraco.Core.Services;
using Umbraco.Web;
using Umbraco.Web.Editors;
using Umbraco.Web.Models.ContentEditing;
namespace MyWebsite
{
@jamiepollock
jamiepollock / AddCustomPropertyToBeAddedLaterToMyPocoTable.cs
Last active May 15, 2018 23:57
Code to represent using custom Umbraco Migrations with Umbraco v7.3.0
using System;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.Migrations;
using Umbraco.Core.Persistence.SqlSyntax;
namespace MyApp.Migrations
{
[Migration("1.1.0", 1, MyCustomSectionMigrationConstants.ProductName)]
public class AddCustomPropertyToBeAddedLaterToMyPocoTable : MigrationBase