Skip to content

Instantly share code, notes, and snippets.

@sniffdk
sniffdk / styles.less
Last active August 29, 2015 14:21
Change any svg attribute eg. stroke and fill in css by embedding them as data uris
// Inspiration taken from http://zslabs.com/articles/svg-background-fill/
// Note that this will replace all provided attributes in all elements in the svg, currently limited to two parameters
.icon-color(@src, @color, @attr) {
@escape-color: escape("@{color}");
@data-uri: data-uri('image/svg+xml;charset=UTF-8', "@{src}");
@attr1: extract(@attr, 1);
@attr2: extract(@attr, 2);
@val1: replace("@{data-uri}", "@{attr1}%3D%22(.*?)%22", "@{attr1}%3D%22@{escape-color}%22", "gi");
@val2: replace("@{val1}", "@{attr2}%3D%22(.*?)%22", "@{attr2}%3D%22@{escape-color}%22", "gi");
background-image: e(@val2);
@sniffdk
sniffdk / CustomRenderControllerFactory.cs
Created October 8, 2015 07:07
Snippet to demo how to intercept the Umbraco route hijacking before a suitable controller is found
using System;
using System.Web.Routing;
using Umbraco.Web.Mvc;
public class CustomRenderControllerFactory : RenderControllerFactory
{
// Attempt to resolve an alternative controller
// This methods is called for all controllers in the request pipeline including surface controllers and possibly third party controllers.
// We need to make sure we only hijack the actual Umbraco page request.
public override Type GetControllerType(RequestContext requestContext, string controllerName)
@sniffdk
sniffdk / RazorHelpers.cs
Last active August 28, 2018 12:23
Snippets showing how to render razor files with WebPages and MCV
public class RazorHelpers
{
// This approach is using WebPages, where there is no concept of a Controller
public static string RenderTemplate(string template, object model)
{
var page = WebPageBase.CreateInstanceFromVirtualPath("~/templates/" + template + ".cshtml");
var context = new WebPageContext(new HttpContextWrapper(HttpContext.Current), page, null);
var htmlWriter = new StringWriter();
// Access your model through PageData["Model"] in the view
context.PageData["Model"] = model;
@sniffdk
sniffdk / overlay-expander.js
Last active November 16, 2018 17:31
Fork of the Umbraco Dialog Expander code which uses mutation observers instead of mutation events
(function ($) {
var expander = function (node) {
var overlay = $(node);
// The toggle is already added, don't do anything
if (overlay.find(".overlay-expander--toggle").length > 0) {
return;
}
var toggle = $("<a href class='btn overlay-expander--toggle'><i class='icon icon-navigation-left'></i></a>");
@sniffdk
sniffdk / 1 poc.txt
Last active September 28, 2017 18:09
TagHelpers and ViewComponents poc
The basic idea is, that I want to avoid writing html in the tag helper class.
This poc, if it worked, would simply pass the ModelExpression down to a view component, where the actual html lives.
From there we would then render various tag helpers based on the ModelExpression.
Unfortunately, it seems that tag helpers in the view component simply creates a ModelExpression of the passed in ModelExpression, inception?
So, to make it work, I guess I would need to "trick" tag helpers into accepting an existing ModelExpression? Doable?
0451e06107fce07bfdf8128a88173cf75575dc07c8949bb28f53c76e2481ae80fe7ac196389a4626c5e12abddf45986b875b6c9f2f39beab372a16bc295a97b2b2
@sniffdk
sniffdk / replace.sql
Last active November 16, 2018 17:31
Replace ntext sql
-- https://stackoverflow.com/a/4341677/701242
UPDATE [table]
SET [column] = CAST(REPLACE(CAST([column] as NVarchar(MAX)),'find','replace') AS NText)
WHERE [column] LIKE '%find%'
@sniffdk
sniffdk / 1. ost.cs
Last active April 19, 2018 10:44
OST poc create user request
private static string baseUrl = "https://playgroundapi.ost.com";
private static string key = "xxx";
var name = "apiuser";
var timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString();
var request = $"/users/create?api_key={key}&name={name}&request_timestamp={timestamp}";
var signature = Sign(request);
var values = new Dictionary<string, string>
@sniffdk
sniffdk / editor.controller.js
Created May 17, 2018 11:22
Simple custom Umbraco dropdown plugin
angular.module("umbraco").controller("SimpleDropDown",
function ($scope) {
});
@sniffdk
sniffdk / PdfModule.cs
Created June 6, 2018 09:40
Snippet to demo how an http module can be used to check pdf requests
public class PdfModule : IHttpModule
{
public void Init(HttpApplication context)
{
context.PostAuthorizeRequest += PostAuthorizeRequest;
}
void PostAuthorizeRequest(object sender, EventArgs e)
{
var context = HttpContext.Current;