Skip to content

Instantly share code, notes, and snippets.

View DanDiplo's full-sized avatar

Dan Booth DanDiplo

View GitHub Profile
@DanDiplo
DanDiplo / 0_reuse_code.js
Created February 13, 2014 20:49
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@DanDiplo
DanDiplo / AngularRepeatLast
Created September 24, 2014 19:47
AngularJS Directive to trigger on last item in ng-repeat
// app directive
.directive('onLastRepeat', function () {
return function (scope, element, attrs) {
if (scope.$last) setTimeout(function () {
scope.$emit('onRepeatLast', element, attrs);
}, 1);
};
})
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Umbraco.Web.Routing;
namespace Diplo.Core
{
/// <summary>
@DanDiplo
DanDiplo / QueryStringHelper.cs
Last active February 7, 2019 16:38
QueryString Helper
// Code examples of using my QueryStringHelper c# class for parsing query string values
// See https://github.com/DanDiplo/QueryString-Helper
QueryStringHelper qs1 = new QueryStringHelper(Request.QueryString); // initialise from Request.QueryString
string query = "?page=5&username=dan&year=2010&enabled=true&email=dan@example.com&option=apple&option=banana&option=melon&date=2015/07/06";
QueryStringHelper qs = new QueryStringHelper(query); // intialise from string
@DanDiplo
DanDiplo / umbraco_extensions.cs
Last active April 17, 2023 20:13
A few useful extension methods for Umbraco IPublishedContent.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Web;
/// <summary>
/// A few useful extension methods for Umbraco IpublishedContent
@DanDiplo
DanDiplo / BlockListCreatorService.cs
Last active January 25, 2024 10:08
Create Blocklist JSON programmatically in Umbraco
/// <summary>
/// Helper service for creating JSON necessary for creating block list items programatically using Umbraco <see cref="ContentService"/>
/// </summary>
/// <remarks>
/// Based of this: https://github.com/umbraco/UmbracoDocs/blob/e64ec0e5b28b4e5a37b7865691621e45dd82701f/Getting-Started/Backoffice/Property-Editors/Built-in-Property-Editors/Block-List-Editor/index.md
/// It's intended for simple content
/// </remarks>
public class BlockListCreatorService
{
/// <summary>
@DanDiplo
DanDiplo / JS-LINQ.js
Last active April 23, 2024 11:03
JavaScript equivalents of some common C# LINQ methods. To help me remember!
// JS array equivalents to C# LINQ methods - by Dan B.
// First: This version using older JavaScript notation for universal browser support (scroll down for ES6 version):
// Here's a simple array of "person" objects
var people = [
{ name: "John", age: 20 },
{ name: "Mary", age: 35 },
{ name: "Arthur", age: 78 },
{ name: "Mike", age: 27 },