Skip to content

Instantly share code, notes, and snippets.

View deanebarker's full-sized avatar

Deane Barker deanebarker

View GitHub Profile
deanebarker / TableOfContents.js
Last active November 21, 2023 16:39
Web Component to embed a dynamic table of contents based on heading tags
View TableOfContents.js
<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"
View RelativeDate.js
<relative-date datetime="1971-09-03" prefix="Posted" suffix="ago"/>
<relative-date>Posted 52 years ago</relative-date>
deanebarker / Nemmet.cs
Last active April 10, 2023 01:38
An implementation of Emmet in C# using Parlot
View Nemmet.cs
Moved to a permanent repo here:
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
deanebarker / HideVisualViewUIDescriptor.cs
Created November 14, 2022 20:28
Code to hide preview and on-page edit views for content that has no visual component
View HideVisualViewUIDescriptor.cs
public class HideVisualViewUIDescriptor : UIDescriptor<[Page Type or interface>
public HideVisualViewUIDescriptor() : base()
DefaultView = CmsViewNames.AllPropertiesView;
EnableStickyView = false;
DisabledViews = new[] { CmsViewNames.PreviewView, CmsViewNames.OnPageEditView };
deanebarker / BookRankings.cs
Last active October 13, 2022 22:34
Code to process the NY Times Bestseller List
View BookRankings.cs
void Main()
// This code depends on the FlatFiles Nuget package:
// Download the dataset from here:
var pathToFile = @"[path to file]";
var mapper = DelimitedTypeMapper.Define<BookRanking>();
mapper.Property(c => c.Year).ColumnName("year");
mapper.Property(c => c.Week).ColumnName("week").InputFormat("yyyy-MM-dd");
deanebarker / ExtractTextFromWord.cs
Last active August 19, 2022 13:30
A quick and dirty way to extract text from Word document via C#
View ExtractTextFromWord.cs
// This is some rough/stub code for extracting raw text from a Word document
// A modern Word document (.docx) is just a zip file. Extract it.
// Find a file called word/document.xml. That contains the text of the document.
// Paragraphs are in "w:p" tags, and text is in "w:t".
// Iterate the "p" tags, then concatenate all the "t" tags inside them
void Main()
var doc = XDocument.Parse(File.ReadAllText(" [path to word/document.xml] "));
XNamespace nsW = "";
deanebarker / Startup.cs
Created May 3, 2022 21:47
The simplest webhook system for Optimizely Content Cloud
View Startup.cs
public void Configuration(IAppBuilder app)
// This is the URL template to call
// The placeholders are optional -- they will be replaced with data specific to the content that is published
var webhookUrl = "{id}&type={type}&version={version}";
// Here is an example URL that would be called for this example:
var events = ServiceLocator.Current.GetInstance<IContentEvents>();
deanebarker / ExtractFragmentMiddleware.cs
Last active April 1, 2022 11:30
Replace the body of a response with HTML extracted from that same body
View ExtractFragmentMiddleware.cs
using AngleSharp.Html.Parser;
using Microsoft.AspNetCore.Http;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace DeaneBarker.Optimizely.Middleware
public class ExtractFragmentMiddleware
deanebarker / Editor.js
Last active February 16, 2022 14:16
The world's simplest code editor for Optimizely Content Cloud
View Editor.js
This is specifically designed to do as little as possible and have no dependencies.
1. It's styled sort of like a code editor (?)
2. Spellchecking is turned off (no red squiggly lines -- I hate those!)
3. The TAB key will insert 2 spaces, instead of moving focus
4. When you press enter, it will add leading spaces to match the leading spaces on the prior line
...and that's all it does.