Skip to content

Instantly share code, notes, and snippets.

View jamiepollock's full-sized avatar

Jamie Pollock jamiepollock

View GitHub Profile
@jamiepollock
jamiepollock / CreateOnlyDictionaryHandler.cs
Last active July 29, 2020 08:24
A uSync custom DictionaryHandler which only imports items if they're missing. It will not overwrite any existing authored translations.
using Jumoo.uSync.BackOffice;
using Jumoo.uSync.BackOffice.Handlers;
using Jumoo.uSync.BackOffice.Helpers;
using Jumoo.uSync.Core;
using Jumoo.uSync.Core.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Linq;
@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 / 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 / DirectiveController.js
Created January 11, 2016 09:16
simpledatepicker - basic angularjs datetime picker for custom Umbraco backoffces. It's a little hacky :/
angular.module("umbraco.directives")
.directive('simpledatepicker', function ($parse, $filter, assetsService) {
return {
restrict: 'E',
scope: {
field: '='
},
controller: function ($scope, $element) {
assetsService.loadCss('/umbraco/lib/datetimepicker/bootstrap-datetimepicker.min.css').then(function () {
var filesToLoad = ["/umbraco/lib/moment/moment-with-locales.js",
@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 / 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
@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 / 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 / package.manifest
Created September 19, 2014 16:32
A custom umbraco directive which allows the user to bing an umb-editor to a property whilst providing a custom config.
{
javascript: [
'~/App_Plugins/YourPackage/your.controller.js',
'~/App_Plugins/YourPackage/umbraco-editor-with-config.js',
]
}