Skip to content

Instantly share code, notes, and snippets.

@alexr
alexr / GrammarEnumeration.fs
Created October 25, 2014 22:13
This is an F# implementation of the Omega monad as it appears, more or less, on http://hackage.haskell.org/package/control-monad-omega. Type annotations are for reading convenience.
(**
And of cause translation of the context free grammar enumeration example
from [Luke Palmer's post](http://lukepalmer.wordpress.com/2008/05/02/enumerating-a-context-free-language/)
which was my original inpiration to use Omega.
Notice the explicit addition of laziness to allow recursive use of
`symbol` literals in a list. Alternatively one can define, say:
```
type 'a symbol =
| Terminal of 'a
@alexr
alexr / MultiGroupReplaySubject.cs
Created December 2, 2013 01:19
[Rx] MultiGroupReplaySubject - similar to `ReplaySubject`, but requires observable type to be `KeyValuePair<TKey, TValue>` and maintains replay buffer per group. On subscribe it replays all the buffers for all groups. Note that there is no way to delete a group, so for the case new groups will keep appearing in the input it will eventually run o…
namespace System.Reactive.Subjects
{
using System;
using System.Collections.Generic;
/// <summary>
/// Specialized version of ReplaySubject which process keyed events and replays last
/// count values from each group. Each notification is broadcasted to all subscribed
/// and future observers.
/// </summary>
@alexr
alexr / README.md
Created October 12, 2013 19:30
Dynamic computation chart sample

Simple example to show dynamically computed chart based on the data in another chart. TODO: add better computation than a slice of 10 original elements :)

@alexr
alexr / BinarySearch.cs
Created July 1, 2013 01:50
Extending familiar binary search with unknown upper limit. I.e. instead of binary_search(lo, hi, predicate) we have binary_search(lo, predicate). [LinqPad]
void Main()
{
// Trivial test...
Enumerable.Range(-2, 100)
.Select(n => new { n, res = binary_search(4, x => x >= n) }.ToString())
.Dump();
}
public static uint binary_search(uint low, Func<uint, bool> f)
{
@alexr
alexr / DirTree.cs
Last active December 15, 2015 16:38
Simple directory tree enumeration with LINQ. [LinqPad]
void Main()
{
var root = @"c:\";
DirTree(root, true)
// ==> ugly-print :)
// .Select(path => { var xs = path.Split('\\'); return string.Join("| ", Enumerable.Repeat("", xs.Length-1)) + xs.Last(); })
.Dump();
}
// Enumerable version of traversal