Skip to content

Instantly share code, notes, and snippets.

@StefanoChiodino
StefanoChiodino / nginx.conf
Last active August 5, 2016 10:33
Nginx pagespeed modules
pagespeed EnableFilters responsive_images;
pagespeed EnableFilters outline_css;
pagespeed EnableFilters outline_javascript;
pagespeed EnableFilters move_css_above_scripts;
pagespeed EnableFilters move_css_to_head;
pagespeed EnableFilters rewrite_style_attributes;
pagespeed EnableFilters prioritize_critical_css;
pagespeed EnableFilters make_google_analytics_async;
pagespeed EnableFilters canonicalize_javascript_libraries;
pagespeed EnableFilters inline_google_font_css;
@StefanoChiodino
StefanoChiodino / UmbracoDisableClientOnFrontEnd.cs
Last active November 22, 2016 10:29
Umbraco: disable front end for client
var userTicket = new System.Web.HttpContextWrapper(System.Web.HttpContext.Current).GetUmbracoAuthTicket();
if (!Request.Url.Host.Equals("localhost", StringComparison.OrdinalIgnoreCase))
{
var user = userTicket?.Name
.IfNotNullThen(()=>ApplicationContext?.Services?.UserService?.GetByUsername(userTicket.Name));
if (user == null)
{
Response.Redirect("/umbraco", true);
}
@StefanoChiodino
StefanoChiodino / UmbracoCachedGetController.cs
Created November 22, 2016 12:44
A controller that caches only get requests
public class CachedGetController : ControllerBase
{
[HttpGet]
[OutputCache(Duration = 600)]
public override ActionResult Index(RenderModel model)
{
return base.Index(model);
}
[HttpPost]
@StefanoChiodino
StefanoChiodino / SitemapXml.cshtml
Last active March 5, 2017 10:06
Sitemap for Umbraco with SEO metadata package installed
@using Page = Website.Core.Models.UmbracoPage
@inherits UmbracoTemplatePage
@{
Layout = null;
// Forces the doc type declaration on the first line.
Response.Write(@"<?xml version=""1.0"" encoding=""UTF-8"" ?>");
Response.ContentType = "text/xml";
var root = Model.Content.Ancestor<Page>();
private static string GetSingleNode(string modelTypeAlias)
{
var node = UmbracoContext.Current.ContentCache
.GetSingleByXPath($"//{modelTypeAlias}[@isDoc]");
var url = node
?.Url;
return url;
}
@StefanoChiodino
StefanoChiodino / 1994 and back
Created September 4, 2017 08:06
Bring your website back in time
var transitionSeconds = 5;
$('<style>').html('* { transition: all ' + transitionSeconds + 's; }').appendTo(document.body)
$(document.body).find('*').each((index, element) => {
$(element).data('id', $(element).attr('id'));
$(element).data('class', $(element).attr('class'));
$(element).removeAttr('class id');
});
@StefanoChiodino
StefanoChiodino / Umbraco.ExportVortoValue.cs
Created September 4, 2017 12:47
A quick script to export all vorto values
var allNodes = UmbracoContext.ContentCache
.GetByXPath("//*[@isDoc]");
var nodesVortoValuePairs = allNodes
.SelectMany(n => n.Properties
.Where(p => p.Value is Our.Umbraco.Vorto.Models.VortoValue)
.Select(p => new { Node = n, Property = p }));
var vortoValuesExport = nodesVortoValuePairs
.Select(a =>
{
var vortoValue =
private UmbracoContext GetUmbracoContext()
{
var httpContextbaseMock = new Mock<HttpContextBase>();
var applicationContext = GetAppicationContext();
var webSecurity = new WebSecurity(httpContextbaseMock.Object, applicationContext);
var umbracoSettingsSectionMock = new Mock<IUmbracoSettingsSection>();
var umbracoContext = UmbracoContext.EnsureContext(httpContextbaseMock.Object,
applicationContext, webSecurity, umbracoSettingsSectionMock.Object,
@StefanoChiodino
StefanoChiodino / umbraco-ui-automation.js
Last active July 19, 2018 09:49
Some small scripts to automate boring tasks safely through the Umbraco backend
$(".icon-wrong")
.each(function(index, element){
setTimeout(function(){
$(element).trigger('contextmenu');
setTimeout(function(){
$(".icon-axis-rotation-2:eq(0)").click();
setTimeout(function(){
$('iframe.auto-expand').contents().find("#body_PropertyMappingRepeater_DestinationProperty_12:eq(0) option:eq(0)").prop('selected', true);
@StefanoChiodino
StefanoChiodino / UmbracoCustomOwinStartup.cs
Created December 20, 2018 14:55
Umbraco - set strong password policy
using Microsoft.Owin;
using Owin;
using Umbraco.Core;
using Umbraco.Core.Security;
using Umbraco.Web.Security.Identity;
using Umbraco.Core.Models.Identity;
using Website.Web;
using Umbraco.Web;
//To use this startup class, change the appSetting value in the web.config called