Skip to content

Instantly share code, notes, and snippets.

View AdamWhiteHat's full-sized avatar
🏠
Working from home

Adam White AdamWhiteHat

🏠
Working from home
View GitHub Profile
@AdamWhiteHat
AdamWhiteHat / StableDiffusion_ControlNet_Gradio.ipynb
Created September 27, 2023 12:24
Stable Diffusion ControlNet Google Colab
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@AdamWhiteHat
AdamWhiteHat / ObservableDictionary.cs
Last active September 14, 2023 23:50
ObservableDictionary - Like an ObservableCollection, but its a Dictionary. Fires events for: Add, Remove, Replace, and Clear.
using System;
using System.Linq;
using System.Collections;
using System.ComponentModel;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Collections.ObjectModel;
using System.Runtime.CompilerServices;
@AdamWhiteHat
AdamWhiteHat / IntervalArithmetic.cs
Created June 28, 2023 17:45
Interval arithmetic type class
/// <summary>
/// Interval arithmetic type class
/// </summary>
public class Interval : IEquatable<Interval>, IComparable<Interval>, IComparable
{
#region Properties
public static Interval Zero;
public static Interval One;
@AdamWhiteHat
AdamWhiteHat / AI Voice Cloning with Tortoise TTS.ipynb
Last active June 28, 2023 17:42
AI Voice Cloning with Tortoise TTS.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@AdamWhiteHat
AdamWhiteHat / Vector<T>.cs
Created January 25, 2023 17:57
Generic Vector<T> Class
/// <summary>
/// A generic Vector class.
/// Uses/Requires the GenericArithmeticFactory class:
/// https://gist.github.com/AdamWhiteHat/71d548ebfb2ee67fcbd78a39a9751423
/// </summary>
public class Vector<T>
{
/// <summary>The dimension of the vector, i.e. the number of elements or its length.</summary>
public int Dimensions { get { return Elements == null ? 0 : Elements.Length; } }
@AdamWhiteHat
AdamWhiteHat / SandPile.cs
Last active January 7, 2023 03:00
Abelian Sandpile Group Class Arithmetic
/// <summary>Abelian Sandpile Class</summary>
public class SandPile : IEquatable<SandPile>
{
#region static Sandpile Values
public static SandPile Zero = new SandPile(new int[,] { { 2, 1, 2 }, { 1, 0, 1 }, { 2, 1, 2 } }, 4);
public static SandPile One = new SandPile(new int[,] { { 3, 2, 3 }, { 2, 1, 2 }, { 3, 2, 3 } }, 4);
public static SandPile NegativeOne = new SandPile(new int[,] { { 1, 3, 1 }, { 3, 3, 3 }, { 1, 3, 1 } }, 4);
// These can all be constructed from the above three sandpiles.
@AdamWhiteHat
AdamWhiteHat / BestStringEqualityComparer.cs
Last active October 10, 2022 00:14
Enables adding hundreds of millions of string keys to a Dictionary without slow-down. Provides a GetHashCode implementation that provides the mathematically best, even distribution of hash values accross the entire 32 bit integer range of possible values. Allows a Dictionary, HashSet, SortedSet, or anything that needs a hash, to hash hundreds of…
/// <summary>
/// A IEqualityComparer<string> that provides the mathematically best GetHashCode
/// possible for adding millions of strings to Dictionaries, HashTables, HashMaps and more.
/// It works by interpreting an array of bytes (your string) as a number in base 256,
/// and then returning the unit of that number in the multiplicative group of integers modulo a prime p,
/// where p is the largest prime less than 2^32.
/// </summary>
public class BestStringEqualityComparer : IEqualityComparer<string>
{
public int GetHashCode(string obj)
@AdamWhiteHat
AdamWhiteHat / INotifyPropertyChangedEx.cs
Created March 20, 2022 01:00
INotifyPropertyChangedEx
namespace ComponentModelEx
{
public delegate void PropertyChangedExEventHandler(object sender, PropertyChangedExEventArgs e);
public interface INotifyPropertyChangedEx
{
event PropertyChangedExEventHandler PropertyChangedEx;
}
}
@AdamWhiteHat
AdamWhiteHat / IsValidIPv6Address.cs
Last active January 31, 2021 05:37
IsValidIPv6Address
public static bool IPv6Check(string input)
{
if (string.IsNullOrWhiteSpace(input))
{
return false;
}
if (input.IndexOf("::") != input.LastIndexOf("::")) // 'The "::" can only appear once in an address.'
{
return false;
@AdamWhiteHat
AdamWhiteHat / GenericArithmeticFactory.cs
Last active January 25, 2023 17:56
Generic arithmetic operations with an example
public static class GenericArithmeticFactory<T>
{
private static Dictionary<ExpressionType, Func<T, T, T>> _binaryOperationDictionary;
private static Dictionary<ExpressionType, Func<T, T, bool>> _comparisonOperationDictionary;
private static Func<T, T> _sqrtOperation = null;
static GenericArithmeticFactory()
{
_binaryOperationDictionary = new Dictionary<ExpressionType, Func<T, T, T>>();
_comparisonOperationDictionary = new Dictionary<ExpressionType, Func<T, T, bool>>();