Skip to content

Instantly share code, notes, and snippets.

View bradphelan's full-sized avatar

Brad Phelan bradphelan

View GitHub Profile
@bradphelan
bradphelan / Maybe.cs
Created December 11, 2012 11:19
Maybe<T> Implementation in C#
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reactive.Linq;
namespace FunctionalExtensions
{
@bradphelan
bradphelan / Exceptional.cs
Last active November 30, 2018 13:45
Exceptional Monad in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reactive.Linq;
namespace ReactiveUI.Utils
{
// From http://stackoverflow.com/questions/10772727/exception-or-either-monad-in-c-sharp
@bradphelan
bradphelan / 1.WPFObservable.tt
Last active August 30, 2018 22:37
F# events for the C# guy This generates extension methods for all events on FrameworkElement (WPF) and it's decendants. The extension methods allow you to subscribe to events as observables. At the moment only non generic events are handles. Just drop it in your project and it will generate the source for you.
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="PresentationCore" #>
<#@ assembly name="PresentationFramework" #>
<#@ assembly name="System.Xaml" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Diagnostics"#>
<#@ import namespace="System.IO"#>
<#@ import namespace="System.Linq"#>
[2018-02-26 13:36:16,380] INFO - jetbrains.buildServer.STARTUP - Server shutdown event received
[2018-02-26 13:36:16,382] INFO - jetbrains.buildServer.STARTUP - Current stage: TeamCity server is shutting down
[2018-02-26 13:36:16,382] INFO - jetbrains.buildServer.STARTUP - Stopping the main application
[2018-02-26 13:36:16,483] INFO - jetbrains.buildServer.STARTUP - Destroying the main servlet
[2018-02-26 13:36:16,483] INFO - MainTeamCityApplicationContext - Closing WebApplicationContext for namespace 'buildServer-servlet': startup date [Mon Feb 26 12:47:07 CET 2018]; parent: jetbrains.buildServer.maintenance.WebDispatcherApplicationContext@1dc816b
public class TwoWayBindingWithConversionDemo
{
public class Model : ReactiveObject
{
/// <summary>
/// The model length will be in units meters
/// </summary>
[Reactive] public double LengthInMeters { get; set;}
}
using Microsoft.Azure;
using Microsoft.WindowsAzure;
using Owin;
using Weingartner.Distribution.Website.Accounts;
using Weingartner.Distribution.Website.Storage;
using Weingartner.Distribution.Website.Storage.Azure;
namespace Weingartner.Distribution.Website.Hosting.Azure
{
public class AzureStartup
/// <summary>
/// Faster version of intersect than the eyeshot code.
/// </summary>
/// <param name="this"></param>
/// <param name="other"></param>
/// <param name="intersection"></param>
/// <returns>Returns true if there is an intersection. Returns false if it is colinear.</returns>
public static bool Intersect(this Segment2D @this, Segment2D other, out Point2D intersection)
{
intersection = null;
False : Evil time is 668
True : Good time is 261
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using devDept.Geometry;
using Xunit;
using Xunit.Abstractions;
Vector3D Normal(Solid3D.Face face, Point3D p)
{
return face
.Parametric
.SelectMany
(s => s.PointInversion( p, 1e-3, out var coord2D )
? Some((p: s.PointAt(coord2D), n: s.Normal(coord2D)))
: None )
.MaxBy(q => p.DistanceTo(q.p))
[0].n;