Skip to content

Instantly share code, notes, and snippets.

@ahancock1
ahancock1 / mapper.py
Created November 20, 2022 21:48
Simple dataclass Automapper for python 3.10
from typing import Protocol, TypeVar, Callable
from dataclasses import is_dataclass, fields
from dataclasses import MISSING
S = TypeVar("S")
T = TypeVar("T")
class IProfile(Protocol):
@ahancock1
ahancock1 / services.py
Created November 8, 2022 22:10
inversion of control dependency injection service container
from __future__ import annotations
from typing import Callable, Generic, Protocol, TypeVar
from typing import overload
from typing import get_type_hints, get_args, get_origin
T = TypeVar("T")
class IServiceProvider(Protocol):
@ahancock1
ahancock1 / License
Last active July 23, 2022 10:04
python reactive rx sqlite nosql json document database with filter
MIT License
Copyright (c) 2022 Adam Hancock
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@ahancock1
ahancock1 / RateLimiter.cs
Created February 22, 2021 22:14
Reactive Rate Gate using observables to limit access to resources async
using System;
using System.Collections.Concurrent;
using System.Reactive;
using System.Reactive.Concurrency;
using System.Reactive.Linq;
using System.Threading;
using System.Threading.Tasks;
public class RateLimiter
{
@ahancock1
ahancock1 / Classifier.cs
Created October 10, 2020 14:05
Half Space Trees HST classifier .Net C# implemetation
public class ClassifierSettings
{
public int WindowSize { get; set; } = 250;
public int Estimators { get; set; } = 25;
public int MaxDepth { get; set; } = 15;
public int Features { get; set; } = 0;
@ahancock1
ahancock1 / Series.cs
Created September 27, 2020 11:12
Observable extensible generic trading indicator series
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public interface ISeries
{
void Attach(ISeries series);
@ahancock1
ahancock1 / Disposable.cs
Created May 4, 2020 14:53
Singleton disposable factory wrapper C# - Maintains reference count and disposes of singleton instance on last reference dispose or instance disposed invoked
namespace DisposableInstance
{
using System;
using System.Threading;
// Usage
internal class Program
{
private static void TestDisposeInstance()
{
@ahancock1
ahancock1 / Socket.cs
Last active May 1, 2020 20:41
Simple ClientWebSocket implementation C#
public interface ISocket : IDisposable
{
event Action<Exception> OnError;
event Action<dynamic> OnData;
event Action OnDisconnected;
event Action OnConnected;
@ahancock1
ahancock1 / FluentValidator.cs
Created April 13, 2020 21:21
Simple Blazor Fluent Validation Validator Component
public class FluentValidator : ComponentBase
{
private readonly IDictionary<Type, IValidator> _validators =
new Dictionary<Type, IValidator>();
[CascadingParameter]
public EditContext EditContext { get; set; }
[Inject]
@ahancock1
ahancock1 / RateLimiter.cs
Created June 15, 2019 23:45
A weighted and timed rate limiter for c# that limits access to resources
public abstract class Disposable : IDisposable
{
private bool _disposed;
public void Dispose()
{
if (_disposed)
{
return;