Skip to content

Instantly share code, notes, and snippets.

View abjerner's full-sized avatar

Anders Bjerner abjerner

View GitHub Profile
using System;
using System.Collections.Generic;
using Skybrud.Essentials.Security;
using Skybrud.Umbraco.GridData.Models;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core;
namespace code.Features.BlockList.Models {
/// <summary>

By using my Skybrud.Umbraco.GridData package (which introduces a strongly typed model for the Grid), indexing the new Grid in Umbraco 7.2 is quite easy.

At Skybrud.dk we typically create a class named ExamineIndexer that takes care of the Examine related events. This class should be initalized during Umbraco startup like this:

using Umbraco.Core;

namespace FanoeTest {

 public class Startup : ApplicationEventHandler {
@abjerner
abjerner / ExaminePublishedContent.cs
Created October 11, 2016 21:17
Convert SearchResult into IPublishedContent
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Examine;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
namespace Skybrud.ExamineDevStuff {
@abjerner
abjerner / Examine.cshtml
Created December 15, 2015 08:38
Index a single content node in Examine
@using System.Xml.Linq
@using umbraco.cms.businesslogic.web
@using UmbracoExamine
@inherits UmbracoViewPage
@{
// Generate an instance of XElement to be indexed
XElement node = new Document(Model.Id).ToXDocument(false).Root;
using System;
using System.IO;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace MyWebsite {
public partial class Utils {
@abjerner
abjerner / LinkedInOAuth2.cshtml
Created February 24, 2017 20:33
Example on how to handle authenticating with LinkedIn using OAuth 2.0, and how to obtain the name and email address of the authenticated user.
@using Skybrud.Social.LinkedIn
@using Skybrud.Social.LinkedIn.ExtensionMethods
@using Skybrud.Social.LinkedIn.OAuth2
@using Skybrud.Social.LinkedIn.Responses.Users
@{
<h2>LinkedIn: OAuth</h2>
string baseUrl = "http://social-legacy.abjerner/linkedin/oauth2/";
@abjerner
abjerner / ContentPickerDemo.html
Created August 26, 2016 19:33
Example on an Umbraco property editor with a content picker (both single and multi)
<div ng-controller="ContentPickerDemo.Controller">
<div>
<a href="#" prevent-default ng-click="addSingle()" class="btn btn-default">Add single</a>
<a href="#" prevent-default ng-click="addMultiple()" class="btn btn-default">Add multiple</a>
</div>
<div ng-show="model.value.items.length > 0" style="margin-top: 10px;">
<div ng-repeat="item in model.value.items">
<i class="icon {{item.icon}}"></i> {{item.name}}
@abjerner
abjerner / TwitterEntities.cs
Last active August 15, 2016 18:03
Formatting entities in a Twitter status message (tweet)
private string FormatStatusMessageText(TwitterStatusMessage tweet) {
// Normally we should be able to call tweet.Entities.GetAllReversed() but that method
// will throw an exception if the array of media entities is NULL (which it is if there
// are no media attached to the tweet).
List<TwitterBaseEntity> entities = new List<TwitterBaseEntity>();
entities.AddRange(tweet.Entities.HashTags);
entities.AddRange(tweet.Entities.Urls);
entities.AddRange(tweet.Entities.Mentions);
if (tweet.Entities.Media != null) entities.AddRange(tweet.Entities.Media);
using System;
using System.Web;
public class StringWrapper {
public string Value { get; set; }
public HtmlString ValueAsHtml {
get { return new HtmlString(Value ?? ""); }
}
@abjerner
abjerner / WcagHelpers.cs
Last active February 7, 2016 16:46
Calculates the WCAG 2.0 contrast ratio between two colors
using System;
using System.Drawing;
public class WcagHelpers {
/// <summary>
/// Calculates the relative luminance of a given <code>color</code> as specified by the WCAG 2.0 specification.
/// </summary>
/// <param name="color">The color.</param>
/// <returns>Returns the relative luminance.</returns>