This is a very basic version of a Discrete Fourier Transformation.
Not suitable for real-time analysis
Notes:
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Security.Cryptography; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace MonteCarloPi | |
{ | |
class Program |
This is a simple implementation of a function chainer in C#, using AutoResetEvent and TaskFactory to control execution flow.
The code is meant for demonstration and educational purposes. I wrote it as an experiment while studying monads. The Task Parallel Library combined with the new async/await functionality can probably give you a better way to write async code.
Evaluating deeply nested properties can be tedious if you want your code to be safe from the dreaded NullReferenceException. Although sometimes considered a bad habit, occasionally you just have to dive into an object hierarchy to fish out that one value you're interested in.
In these cases, you must check every object in the hierarchy, usually falling back to a default value in case the value you're looking for isn't there. Even so, you often end up with null references in places you never thought to anticipate.
Using these simple extension methods can make it a lot easier (and prettier) to access deeply nested values. It also lets you set an explicit default value in case your expression fails.
A word of caution
/// <summary> | |
/// Cache/Memoizer class that stores output values based on input. | |
/// Can also expire elements and has a fixed lower and upper limit to the number of cached elements | |
/// </summary> | |
/// <typeparam name="TInput"></typeparam> | |
/// <typeparam name="TOutput"></typeparam> | |
public class Memoize<TInput, TOutput> | |
{ | |
private Dictionary<TInput, Tuple<TOutput, DateTime>> Values; | |
private int Min; |
This is an example of a non-nullable wrapper for C#.
You can think of it like the complete opposite of Nullable<T>:
Trying to assign null to a Required<T> variable, or passing null into a method that defines the input as Required<T> will cause an exception. This is good because the sooner we catch errors, the better. Code that fails early is much easier to debug and maintain than code that fails five calls deeper.
struct ZeroDelay2Lp | |
{ | |
double z1_state; | |
float g; | |
// directory from page 48 | |
// https://www.native-instruments.com/fileadmin/ni_media/downloads/pdf/VAFilterDesign_1.1.1.pdf | |
inline float Process(float x) | |
{ | |
// perform one sample tick of the lowpass filter |
class AnonList | |
{ | |
/// <summary> | |
/// Creates a list of type T using a prototype object. Prototype can be any object, including an anonymous type. | |
/// </summary> | |
/// <typeparam name="T"></typeparam> | |
/// <param name="prototype">The prototype object, of which a List of the same type is returned</param> | |
/// <returns>A new empty List of the same type as prototype</returns> | |
public static List<T> CreateAnonList<T>(T prototype) |