Skip to content

Instantly share code, notes, and snippets.

@deanebarker
deanebarker / FileSystemSyncManager.cs
Last active September 28, 2024 12:00
C# code to do a one-way file sync between a source and a target directory
// Doc here: https://deanebarker.net/tech/code/directory-sync/
public class FileSystemSyncManager
{
public List<LogEntry> Log { get; private set; } = new();
public FileRefCollection SourceFiles { get; set; }
public FileRefCollection TargetFiles { get; set; }
// Return false from any of these to cancel the operation
@deanebarker
deanebarker / JsonataValue.cs
Last active August 26, 2024 11:21
A Fluid value that allows extraction of data from JSON using JSONata.
// Information on JSONdata: https://jsonata.org/
// Requires this class also: https://gist.github.com/deanebarker/d9983155603d1adf26197787a9c74ae4
// in C#
var json = GetABunchOfJson();
var context = new TemplateContext();
context.SetValue("json", new JsonataValue(json));
@deanebarker
deanebarker / Tag.cs
Last active September 4, 2024 18:45
Handy C# class for easily and cleanly building HTML tags
// Doc here: https://deanebarker.net/tech/code/tag-builder/
public class Tag
{
private readonly string[] selfClosing = new[] { "img", "br", "hr", "input", "link", "meta" };
public List<Tag> Children = new();
public Tag(string input, string content, params Tag[] children)
{
@deanebarker
deanebarker / JsonataDoc.cs
Last active September 6, 2024 14:45
A combined search and deserialization library using JSONata syntax
// Requires Nuget package Jsonata.Net.Native
// Doc here: https://deanebarker.net/tech/code/jsonata-doc/
public class JsonataDoc
{
// This is public so you can change the options if you want
public JsonSerializerOptions DeserializerOptions = new();
private string json;
@deanebarker
deanebarker / _readme.md
Last active October 18, 2024 23:18
Simple code to enable mouseover tooltips

This is the simplest form of a mouseover "tooltip" UI that I could come up with.

You can see it used on local hyperlinks at https://deanebarker.net/.

Note: this is NOT a "library." This is starter code. There are no settings or configuration (meaning: everything is hard-coded) nor has it been designed to be extensible -- you are expected copy this code and change it. It's essentially just an example.

To use

  1. Somehow form an array of elements to which you want to have tips attached
  2. Implement a function to return the HTML of a tip. It will be passed the entire element that triggered the tip. Do whatever you want (read from an attribute, do a lookup on the HREF, whatever). Return the HTML content for the tip.
@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 / 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