Skip to content

Instantly share code, notes, and snippets.

using System;
using System.Diagnostics;
using Ninject;
namespace ScratchPad
{
public class Foo : IBoo, IBaz
{
}
@iSynaptic
iSynaptic / Example.cs
Created July 11, 2011 19:10
Exodata example for Jason Bock
// Create a declaration
public static class Declarations
{
public static readonly ExodataDeclaration<bool> IsValidator = new ExodataDeclaration<bool>(default: false);
}
// code to define
Bind(Declarations.IsValidator)
.Given<string>()
.For<Type>()
@iSynaptic
iSynaptic / gist:2323837
Created April 6, 2012 23:09
Windows to Olson TimeZone Conversion via NodaTime
foreach (var windowsTimeZone in TimeZoneInfo.GetSystemTimeZones())
{
var olsonTimeZoneProvider = new TzdbTimeZoneProvider("NodaTime.TimeZones.Tzdb");
var olsonTimeZone = olsonTimeZoneProvider.MapTimeZoneId(windowsTimeZone);
Console.WriteLine(olsonTimeZone ?? string.Format("{{{0}}}", windowsTimeZone.Id));
}
public static class Validator
{
public static Outcome<string> ValidatePassword(IDssPrincipal principal, string password)
{
Outcome<string> result = Outcome.Success();
Maybe<string> email = principal.ToMaybe()
.Select(x => x.Identity)
.Select(x => x.EmailAddress);
// Password cannot be empty
public static class Validator
{
public static Outcome<string> ValidatePassword(IDssPrincipal principal, string password)
{
const int minimumLength = 8;
const int maximumLength = 20;
return Outcome.Success()
// Password cannot be empty
Outcome.Success()
.FailIf(true, "failed")
.Let(x =>
{
if(x.WasSuccessful)
{
return x & Outcome.FailIf(true, "this is the expensive check");
}
return x;
@iSynaptic
iSynaptic / gist:5406562
Created April 17, 2013 18:26
Two way bi-direction reference between immutable objects...
using System;
namespace Example
{
class Program
{
static void Main(string[] args)
{
var theA = new A(a => new B(a));
var theB = theA.TheB;
@iSynaptic
iSynaptic / InterleaveSample.cs
Created July 29, 2013 12:52
Sprache Interleaving Sample
using System;
using System.Collections.Generic;
namespace SpracheTestbed
{
class Program
{
static void Main(string[] args)
{
var parser = from greeting in Parse.String("Hello")
@iSynaptic
iSynaptic / gist:7758940
Created December 2, 2013 21:04
Convert from Xml to JSON
private static JToken ConvertFromXml(XElement element)
{
if (!element.HasAttributes && !element.HasElements)
return new JValue(element.Value);
var attributes = element.Attributes()
.Select(x => new JProperty(NormalizeName(x.Name.LocalName), x.Value));
var elements = element.Elements()
.GroupBy(x => x.Name.LocalName)
@iSynaptic
iSynaptic / gist:0d681605ed360c667b53
Created July 1, 2014 21:57
Castle.Zmq with embedded libzmq
static Context()
{
IntPtr libPtr = Native.LoadLibrary("libzmq");
if (libPtr == IntPtr.Zero)
{
LoadEmbeddedLibary();
}
}
private static void LoadEmbeddedLibary()