Skip to content

Instantly share code, notes, and snippets.

@deanebarker
deanebarker / WebServer.cs
Created April 5, 2025 12:26
A very simple web server for C#, suitable for testing
// Doc here: https://deanebarker.net/tech/code/webserver/
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace DeaneBarker.Utils
@deanebarker
deanebarker / markdig-post-parse.cs
Last active February 14, 2025 13:48
How to iterate and manipulate a parsed Markdig document
var markdown = @"
This is some text.
This is a [link](http://deanebarker.net/)
";
var builder = new MarkdownPipelineBuilder();
var pipeline = builder.Build();
@deanebarker
deanebarker / FixWrongIdentifier.cs
Last active February 11, 2025 21:46
Demostrates using a visitor to modify a Fluid template post-parse
void Main()
{
var source = "Hi {{ this_is_the_wrong_identifier }}!";
var template = new FluidParser().Parse(source);
// This replaces "this_is_the_wrong_identifier" with "name"
var visitor = new FixWrongIdentifier();
template = visitor.VisitTemplate(template);
var context = new TemplateContext();
@deanebarker
deanebarker / LiquidScriptData.cs
Last active December 10, 2024 14:21
A hacked up way of writing script-ish code in Liquid/Fluid
// Example usage
var data = new LiquidScriptData()
{
["first_name"] = "Annie",
["last_name"] = "Barker"
};
var keysThatChanged = data.Evaluate(@"
if first_name == 'Annie'
assign first_name = 'Deane'
@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.