Skip to content

Instantly share code, notes, and snippets.

@deanebarker
deanebarker / ConversationalVariableCollection.cs
Last active June 20, 2024 23:21
A Dictionary<string, long> that can be maniuplated by a simple, user-friendly language
using Parlot.Fluent;
using static Parlot.Fluent.Parsers;
using System.Collections.Generic;
using System;
using System.Linq;
/*
This class allows you to query and manipulate a set of numbers using a simple language.
@deanebarker
deanebarker / drawer.html
Last active June 1, 2024 19:21
Sample of using the "popover" attritube to create a right-margin "drawer" UI element
<!--
This will show a UI "drawer" that pops out from the right side of the screen, with a dropshadow and overlay on the rest of the window.
The drawer will auto-focus on the first input field.
A close button will automatically be placed in the top left corner. (Also, you can close by clicking anywhere else on the page.)
-->
@deanebarker
deanebarker / PersonalizedContentAreaSerializer.cs
Last active April 2, 2024 15:29
A POC of providing personalization data with content area items in an API response
[ServiceConfiguration(typeof(IPropertyConverterProvider), Lifecycle = ServiceInstanceScope.Singleton)]
public class CustomPropertyConverterProvider : IPropertyConverterProvider
{
public int SortOrder => 200;
public IPropertyConverter Resolve(PropertyData propertyData)
{
if (propertyData is PropertyContentArea)
{
return new PersonalizedContentAreaPropertyConverter();
@deanebarker
deanebarker / Startup.cs
Created March 29, 2024 02:21
An example showing how to shut off Opti UI telemetry
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights.Extensibility.Implementation;
public class Startup
{
public void Configure(TelemetryConfiguration telemetryConfiguration)
{
telemetryConfiguration.DisableTelemetry = true;
TelemetryDebugWriter.IsTracingDisabled = true;
}
@deanebarker
deanebarker / ComponentController.cs
Created March 13, 2024 22:03
A POC showing how to create endpoints on an Optimize CMS instance that return fully-contained client-side components
using EPiServer.ServiceLocation;
using Microsoft.AspNetCore.Mvc;
using Optimizely.ContentGraph.Cms.Core.Internal;
namespace DeaneBarker.Optimizely.Cms
{
[Route("component")]
public class ComponentController : Controller
{
private const string KEY_TOKEN = "@key";
@deanebarker
deanebarker / TableOfContents.js
Last active November 21, 2023 16:39
Web Component to embed a dynamic table of contents based on heading tags
/*
<table-of-contents title="Contents" source=".article" selector="h2,h3"></table-of-contents>
* "title" will be placed in a HEADER tag as the first child
* "source" default to the BODY tag
* "selector" defaults to "h2"
OR
/*
<relative-date datetime="1971-09-03" prefix="Posted" suffix="ago"/>
Outputs:
<relative-date>Posted 52 years ago</relative-date>
*?
@deanebarker
deanebarker / Nemmet.cs
Last active April 10, 2023 01:38
An implementation of Emmet in C# using Parlot
Moved to a permanent repo here: https://github.com/deanebarker/Nemmet
@deanebarker
deanebarker / .Using the MultiSourceTemplateProvider
Last active January 10, 2023 15:27
An example of how to retrieve template files for Liquid/Fluid templating in Optimizely CMS
This file is just for naming
@deanebarker
deanebarker / dumb-parser-combinator.cs
Last active June 1, 2024 18:13
A very simple parser combinator
void Main()
{
// The text to test it on
var text = new WorkingText("Annie1aa2");
// The parser: hits on "Deane" or "Annie" following by a number, then two letters, then another number
var parser = new Sequence(
new Any(
new TextParser("Deane"),
new TextParser("Annie")