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 / FastFactorial.cs
Created December 22, 2020 12:48
A fast factorial implementation using the divide and conquer method.
public static class FastFactorial
{
public static BigInteger Factorial(BigInteger n)
{
return MultiplyRange(2, n);
}
private static BigInteger MultiplyRange(BigInteger from, BigInteger to)
{
var diff = to - from;
@AdamWhiteHat
AdamWhiteHat / PasswordHashing.cs
Created December 22, 2020 13:17
Don't use SHA256 to hash your passwords! Hash passwords the correct way, using BCrypt.
/// <summary>
/// Requires the BCrypt nuget package. Available here: https://www.nuget.org/packages/BCrypt.Net-Next
/// </summary>
public static class PasswordHashing
{
public static string HashPassword(string password, int workFactor)
{
return BCrypt.Net.BCrypt.HashPassword(password, workFactor);
}
@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>>();
@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;