Skip to content

Instantly share code, notes, and snippets.

@sniffdk
sniffdk / umbracoPage.Init
Last active December 21, 2015 00:59
Register a script oninit in /editcontent.aspx to allow for tab switching.
public class MyApplication : Umbraco.Web.UmbracoApplication
{
protected override void OnApplicationStarted(object sender, EventArgs e)
{
umbracoPage.Init += (p, args) =>
{
var page = p as umbracoPage;
if (page == null)
return;
var request = page.Page.Request;
public class SearchTable : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
base.ApplicationStarted(umbracoApplication, applicationContext);
Umbraco.Core.Services.ContentService.Published += (sender, args) =>
{
foreach (var content in args.PublishedEntities)
{
@sniffdk
sniffdk / gist:7412809
Created November 11, 2013 12:57
Demo code using InGroupsOf from Umbraco.Core.EnumerableExtensions
@using Umbraco.Core
@using uComponents.DataTypes.UrlPicker.Dto
@{
//var items = Model.resourceLinks.Items as List<UrlPickerState>;
var items = new List<UrlPickerState>
{
new UrlPickerState { Title = "Link1" },
new UrlPickerState { Title = "Link2" },
new UrlPickerState { Title = "Link3" },
new UrlPickerState { Title = "Link4" },
@sniffdk
sniffdk / ContextHelpers.cs
Last active February 28, 2022 10:03
Fake an UmbracoContext for use when doing published scheduling or other scenarios where UmbracoContext is normally null.
public class ContextHelpers
{
public static UmbracoContext EnsureUmbracoContext() {
if (UmbracoContext.Current != null)
{
return UmbracoContext.Current;
}
var httpContext = new HttpContextWrapper(HttpContext.Current ?? new HttpContext(new SimpleWorkerRequest("temp.aspx", "", new StringWriter())));
@sniffdk
sniffdk / PageNotFoundContentFinder.cs
Created February 10, 2014 12:07
PageNotFoundContentFinder
public bool TryFindContent(PublishedContentRequest contentRequest)
{
if (contentRequest.Is404)
{
var site = SiteHelpers.GetSite();
var page404 = site.Get404Page();
if (page404 != null)
{
contentRequest.PublishedContent = contentRequest.RoutingContext.UmbracoContext.ContentCache.GetById(page404.Id);
@sniffdk
sniffdk / Indexing.cs
Last active April 1, 2021 10:32
Small snippet for reindexing an entity in Examine
public void ReIndexEntity(IContentBase entity)
{
if (entity is IContent)
{
ExamineManager.Instance.ReIndexNode((entity as IContent).ToXml(), "content");
}
else if (entity is IMedia)
{
ExamineManager.Instance.ReIndexNode((entity as IMedia).ToXml(), "media");
}
@sniffdk
sniffdk / UmbracoHooks.cs
Last active August 29, 2015 13:58
Fix re-publish of already published descendants in Umbraco
public class UmbracoHooks : IApplicationEventHandler
{
private static readonly List<int> PublishFixes = new List<int>();
public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
ContentService.Publishing += (sender, args) =>
{
foreach (var contentItem in args.PublishedEntities)
{
@sniffdk
sniffdk / GetContent.cs
Created April 2, 2014 13:46
Get IContent based on a property value
var contentService = ApplicationContext.Current.Services.ContentService;
var roots = contentService.GetRootContent();
IContent nodeItem = null;
foreach (var root in roots)
{
nodeItem = contentService.GetDescendants(root).FirstOrDefault(x => x.Properties.FirstOrDefault(y => y.Alias == "somePropertyAlias").Value.ToString() == "SomeValue");
if (nodeItem != null)
break;
}
@sniffdk
sniffdk / checksize
Last active February 22, 2018 08:19 — forked from anonymous/gist:1391040
declare @RowCount int, @tablename varchar(100)
declare @Tables table (
PK int IDENTITY(1,1),
tablename varchar(100),
processed bit
)
INSERT into @Tables (tablename)
SELECT TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_TYPE = 'BASE TABLE' and TABLE_NAME not like 'dt%' order by TABLE_NAME asc
declare @Space table (
name varchar(100), rows nvarchar(100), reserved varchar(100), data varchar(100), index_size varchar(100), unused varchar(100)
@sniffdk
sniffdk / responsive.js
Created August 12, 2014 23:36
Small utility functions for handling responsive changes to javascript stuff.
var breakpoints = {
xs: 480,
sm: 768,
md: 992,
lg: 1200
},
currentWidth = 0,
currentBreakpoint = "",
breakpointMethods = []; // array of methods to be run whenever a breakpoint change is registered