Skip to content

Instantly share code, notes, and snippets.

View JefClaes's full-sized avatar

Jef Claes JefClaes

View GitHub Profile
@JefClaes
JefClaes / gist:9418765
Created March 7, 2014 19:58
A generic self-contained self-refreshing knockout.js model for binding to a dashboard widget.
var ajaxWidgetModel = function (options) {
var self = this;
self.data = ko.observable();
self.tick = function () {
$.get(options.url, function (data) {
self.data(ko.mapping.fromJS(data));
});
};
@JefClaes
JefClaes / gist:9818345
Created March 27, 2014 20:49
Reactive polling
var ticks = Observable.Interval(TimeSpan.FromSeconds(_settings.IntervalInSeconds));
var pollResults = Observable.Create<PollResult>(observer =>
{
var results = // do request
foreach (var result in results)
observer.OnNext(new PollResult(result));
return Disposable.Empty;
@JefClaes
JefClaes / gist:496388c579dc9ce86b56
Created July 19, 2014 19:32
Is this functional C#?
class Program
{
static void Main(string[] args)
{
var item = InventoryItemPure.Register(new InventoryItemName("Domain Driven Design"));
item = InventoryItemPure.CheckIn(item, new InventoryItemCount(4));
item = InventoryItemPure.CheckOut(item, new InventoryItemCount(3));
item = InventoryItemPure.Deactivate(item);
Console.ReadLine();
module Program
open Inventory
open System
[<EntryPoint>]
let main argv =
let item = Inventory.Register (Inventory.InventoryItemName.Make "Domain Driven Design")
let itemAfterCheckingIn = Inventory.CheckIn (InventoryItemCount.Make 3) item
let itemAfterCheckingOut = Inventory.CheckOut (InventoryItemCount.Make 1) itemAfterCheckingIn
let deactivatedItem = Inventory.Deactivate itemAfterCheckingOut
@JefClaes
JefClaes / gist:2c0063514c829181fde5
Last active August 29, 2015 14:07
Code snippet for reading Event Store stream in slices using F#
let rec read stream startFrom (conn : IEventStoreConnection) =
seq {
let size = 10000
let slice = conn.ReadStreamEventsForwardAsync(stream, startFrom, size, true).Result
if (slice.IsEndOfStream) then
yield slice
else
yield slice
yield! read stream (startFrom + size) conn
@JefClaes
JefClaes / gist:0cfed3f0ad26a75eda1e
Created October 5, 2014 13:05
Event Store PackageFramingException: Package size is out of bounds
[07,09:57:30.489,ERROR] TcpPackageConnection: [127.0.0.1:1113, L127.0.0.1:55697, {d9265236-f72b-4418-a470-780ab7ef2af9}]. Invalid TCP frame received.
EXCEPTION(S) OCCURRED:
EventStore.ClientAPI.Transport.Tcp.PackageFramingException: Package size is out of bounds: 186992564 (max: 67108864).
at EventStore.ClientAPI.Transport.Tcp.LengthPrefixMessageFramer.Parse(ArraySegment`1 bytes)
at EventStore.ClientAPI.Transport.Tcp.LengthPrefixMessageFramer.UnFrameData(IEnumerable`1 data)
at EventStore.ClientAPI.Transport.Tcp.TcpPackageConnection.OnRawDataReceived(ITcpConnection connection, IEnumerable`1 data)
@JefClaes
JefClaes / gist:e9137dcd4bb8a8636c95
Created October 19, 2014 11:03
Recursion in C#
static void Main()
{
Recursive(0);
}
static void Recursive(int i)
{
Console.WriteLine(i);
Recursive(i + 1);
}
@JefClaes
JefClaes / gist:5a195fe10cc106e88d1b
Created October 19, 2014 11:06
Result of Recursion in C#
...
171424
171425
171426
171427
Process is terminated due to StackOverflowException.
@JefClaes
JefClaes / gist:9a646cea31c05984683b
Last active August 29, 2015 14:07
Recursion in F#
let rec recursiveFun i =
Console.WriteLine(i.ToString())
recursiveFun (i + 1)
recursiveFun 0
@JefClaes
JefClaes / gist:1f77003ed10ac92006d9
Last active August 29, 2015 14:07
Recursion in F# avoiding tail recursion
let rec recursiveFun i =
Console.WriteLine(i.ToString())
recursiveFun (i + 1)
Console.WriteLine("Make another call so the compiler doesn't detect tail recursion.")
recursiveFun 0