Skip to content

Instantly share code, notes, and snippets.

@ahancock1
ahancock1 / ViewportControl.cs
Last active August 14, 2018 18:12
ViewportControl in WPF
// -----------------------------------------------------------------------
// Copyright (C) 2017 Adam Hancock
//
// Viewer.cs can not be copied and/or distributed without the express
// permission of Adam Hancock
// -----------------------------------------------------------------------
namespace Controls
{
using System;
@ahancock1
ahancock1 / MonotoneCubicInterpolation.cs
Created March 26, 2019 09:44
MonotoneCubicInterpolation
public class MonotoneCubicSpline
{
private readonly double[] _x;
private readonly double[] _y;
private readonly int _n;
private readonly double[] _m;
public MonotoneCubicSpline(IList<Point> points)
{
_x = points.OrderBy(p => p.X).Select(p => p.X).ToArray();
@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;
@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 / 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 / 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 / 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 / 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 / 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 / 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):