Skip to content

Instantly share code, notes, and snippets.

View janderit's full-sized avatar
🙃

Philip Jander janderit

🙃
View GitHub Profile
@janderit
janderit / DatabaseObserver.cs
Last active April 11, 2024 13:02
C# class to observe SQL Server databases via Service Broker / SqlDependency
public sealed class DatabaseObserver : IDisposable
{
private readonly string _connectionstring;
private readonly string _sqlcommand;
private readonly Action<Observation> _onChange;
private readonly Action<Exception> _onError;
private readonly Action<string> _onWarning;
private SqlConnection _connection;
private SqlCommand _cmd;
private SqlDependency _dependency;
@janderit
janderit / ZmqPollPool.cs
Created September 10, 2012 15:48
ZeroMQ 3.2 Single threaded container
/// <summary>
/// Encapsulates a zeroMQ context and a worker thread.
/// Use the ZmqPollPool to server multiple 0mq sockets with single-threaded semantics.
///
/// Use MarshalAndWait or MarshalAsync to marshal 0mq context access to the working thread.
/// Call Dispose to close all registered sockets and terminate the context and thread.
/// </summary>
public class ZmqPollPool : IDisposable
{
private TimeSpan _pollTimeout;
@janderit
janderit / functionalBowling.fs
Created December 3, 2019 16:59
Functional solution to the Bowling Kata
//
// Functional Bowling Kata solution in F#
//
// uses recursive determination of the score starting with a certain frame number
// and lookahead for the bonus roll scores
//
let private frames_in_game = 10
type FrameType = Strike | Spare | Normal
@janderit
janderit / eventSourcedBowling.fs
Created December 3, 2019 16:46
Bowling kata solution using event sourcing
// Event-sourced solution to the Bowling Kata
// This is obviously neither a 'simple' solution for the Kata, nor an infrastructure focussed event sourcing demo,
// but rather intended to demonstrate event sourcing *principles* in a minimalistic domain.
// Philip Jander, 2019
// (thanks to Ralf Westphal (@ralfw) for posing the challenge)
// ATTN: functional code, read from the end of the file :)
/// Computation Expression Builder for functional event sourcing
module EventSourced =
@janderit
janderit / Sandbox.cs
Created October 15, 2016 09:32
Devopenspace: Demo Code aus der C# Session 10:30
using System;
using System.Collections.Generic;
namespace Sandbox
{
class Program
{
public Program()
{
Readonly_mit_Field = 5;
@janderit
janderit / rakefile
Last active December 18, 2015 21:48
sample rakefile for generating NuGet nupkgs from VS solutions
##########################################################################
# RAKE BUILD SCRIPT #
# (c) Philip Jander 2012, 2013 #
# Jander.IT #
##########################################################################
RAKEFILE_REVISION = "2.3"
#
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
@janderit
janderit / zmqexample.cs
Created April 11, 2013 15:56
ZeroMQ 3.1 Router/Dealer example
public sealed class Host
{
private readonly string _zmqEndpoint;
private readonly Action<Action> _dispatcher;
private static ZmqSocket _server;
private static readonly ConcurrentQueue<Action> WaitToSend = new ConcurrentQueue<Action>();
public Host(string zmqEndpoint, Action<Action> dispatcher)
{
_zmqEndpoint = zmqEndpoint;
@janderit
janderit / gist:4564158
Last active December 11, 2015 07:08
My favourite collection extenders...
public static class CollectionExtender
{
public static IEnumerable<string> NonBlank(this IEnumerable<string> list)
{
return list.Where(_ => !String.IsNullOrWhiteSpace(_));
}
public static IEnumerable<T> NonNull<T>(this IEnumerable<T> list) where T:class
{
return list.Where(_ => null != (object) _);
(*
The goal in this exercise is to create a model to predict
how many bicycles will be used in a day, given the
available information.
Data source: UC Irvine Machine Learning dataset, "bike sharing":
https://archive.ics.uci.edu/ml/datasets/Bike+Sharing+Dataset
We will first explore the data, using the CSV type provider
and fsharp.Charting to visualize it.
@janderit
janderit / Union.cs
Created October 25, 2015 08:19
C# discriminated union type
// adapted from : http://stackoverflow.com/questions/3151702/discriminated-union-in-c-sharp by Juliet
public abstract class Union<TA, TB, TC>
{
public static Case1 Create(TA x) { return new Case1(x);}
public static Case2 Create(TB x) { return new Case2(x);}
public static Case3 Create(TC x) { return new Case3(x);}
public abstract T Match<T>(Func<TA, T> f, Func<TB, T> g, Func<TC, T> h);
private Union() { }