Skip to content

Instantly share code, notes, and snippets.

@jnm2
jnm2 / WeakEventSource2.cs
Last active September 20, 2023 11:34
Replaces a multicast delegate as an event's backing store. Duplicate behavior, except it is thread safe and holds weak references. (Same as WeakEventSource.cs, but uses WeakDelegate instead of ConditionalWeakTable.)
// MIT license, copyright 2015 Joseph N. Musser II
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
namespace jnm2
{
public struct WeakDelegate<TDelegate> : IEquatable<WeakDelegate<TDelegate>> where TDelegate : class
@UweKeim
UweKeim / convert-wildcards-to-regex.cs
Last active January 28, 2024 21:32
Convert wildcards to Regular Expressions.
private static string convertWildcardToRegex(string pattern)
{
// http://stackoverflow.com/a/6907849/107625
// http://www.codeproject.com/Articles/11556/Converting-Wildcards-to-Regexes
return "^" + Regex.Escape(pattern).
Replace("\\*", ".*").
Replace("\\?", ".") + "$";
}
@UweKeim
UweKeim / ColorConverting.cs
Last active October 9, 2024 14:25
HSL color, HSB color and RGB color types, as well as conversion methods between them in C# and .NET
namespace ZetaColorEditor.Colors;
using System;
using System.Drawing;
/// <summary>
/// Provides color conversion functionality.
/// </summary>
/// <remarks>
/// http://en.wikipedia.org/wiki/HSV_color_space
@andyraddatz
andyraddatz / ASCIIStringExtensions.cs
Last active May 27, 2025 07:35
C# String extension method to fold diacritics to ASCII characters
// IMPORTANT
using System.Text;
// This gist was created thanks to this comment from Alexander on StackOverflow:
// https://stackoverflow.com/questions/249087/how-do-i-remove-diacritics-accents-from-a-string-in-net#comment86833005_34272324
// This is a derivative work. The logic of this function comes from a switch statement found inside the
// Lucene.Net library. The documentation of the conversion of characters is quite impressive
// (thank you @NightOwl888 and @synhershko !!!):
// https://github.com/apache/lucenenet/blob/master/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/ASCIIFoldingFilter.cs
@UweKeim
UweKeim / ZetaFolderXCopy.cs
Last active January 28, 2024 21:32
XCOPY-like functionality to copy files and folders in C#, ideal for batch scripts
//css_nuget -force:3600 -ng:"-Source https://nuget.org/api/v2/" ZetaLongPaths
using ZetaLongPaths;
namespace Zeta
{
/*
===========================
Zeta XCOPY.
namespace ZetaProducer.RuntimeGui.ExtendedWebBrowser
{
using JetBrains.Annotations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Zeta.VoyagerLibrary.Common.IO;
@UweKeim
UweKeim / BlazorTimer.cs
Last active January 28, 2024 21:30
Timer in Blazor 3.1
namespace ZetaHelpdesk.MainBlazor.Code.Components
{
using System;
using System.Timers;
// https://wellsb.com/csharp/aspnet/blazor-timer-navigate-programmatically/
public sealed class BlazorTimer
{
private Timer _timer;
@ZacharyPatten
ZacharyPatten / Omnitree.md
Last active September 29, 2022 11:25
[July 8, 2014] Blog Post discussing a generic N-D SPT data structure

Omnitree

Date: July 8, 2014

Introduction

In this article, I would like to introduce and explain a data structure I have written in C#. This structure has the ability to store items sorted along "N" dimensions. It is similar in concept to a k-d tree (see Wikipedia), but it is NOT implemented as a binary tree. It branches relative to the number of dimensions its items are being sorted upon.

I developed the structure entirely on my own accord, and since I could not find another implementation like it, I am taking the liberty in giving it a name. I have called the structure an "Omni-Tree".

Background

@UweKeim
UweKeim / FileSize.cs
Created October 27, 2020 07:45
Automatically formatting an integer for human-readable file size
namespace Extensions
{
using System;
using System.Globalization;
using System.Threading;
public static class FileSizeExtensions
{
public static string FormatFileSize(
this long fileSize,
@joelonsql
joelonsql / PostgreSQL-EXTENSIONs.md
Last active June 5, 2025 13:56
1000+ PostgreSQL EXTENSIONs

🗺🐘 1000+ PostgreSQL EXTENSIONs

This is a list of URLs to PostgreSQL EXTENSION repos, listed in alphabetical order of parent repo, with active forks listed under each parent.

⭐️ >= 10 stars
⭐️⭐️ >= 100 stars
⭐️⭐️⭐️ >= 1000 stars
Numbers of stars might not be up-to-date.