Skip to content

Instantly share code, notes, and snippets.

View DavidBrower's full-sized avatar

David Brower DavidBrower

  • Civica MDM
  • Glasgow, Scotland
View GitHub Profile
@DavidBrower
DavidBrower / ValueObject.cs
Created September 1, 2015 16:24
ValueObject Base Class
public abstract class ValueObject<T> : IEquatable<T> where T : ValueObject<T>
{
private List<PropertyInfo> Properties { get; }
protected ValueObject()
{
Properties = new List<PropertyInfo>();
}
public override Boolean Equals(object obj)
@DavidBrower
DavidBrower / Entity.cs
Created September 1, 2015 16:25
Entity Base Class
public abstract class Entity<TId> : IEquatable<Entity<TId>>
{
private readonly TId _id;
protected Entity(TId id)
{
if (object.Equals(id, default(TId)))
{
throw new ArgumentException("The ID cannot be the default value.", nameof(id));
}
@DavidBrower
DavidBrower / .gitconfig
Last active March 10, 2018 15:24
Git Config
[user]
name = david.brower
email = *********
[core]
autocrlf = true
excludesfile = #file path
preloadindex = true
fscache = true
[push]
default = simple
@DavidBrower
DavidBrower / ICircuitBreaker.cs
Last active February 23, 2016 22:49
Polly Circuitbreaker
public interface ICircuitBreaker
{
TResult Execute(Func action);
void Execute(Action action);
}
@DavidBrower
DavidBrower / Euler1.fs
Last active March 12, 2016 13:44
Sum of Multiples
//Find the sum of all the multiples of 3 or 5 below 1000.
[1..999]
|> List.filter (fun x -> x % 3 = 0 || x % 5 = 0)
|> List.sum
//Almost identical to http://theburningmonk.com/2010/09/project-euler-problem-1-solution/
@DavidBrower
DavidBrower / Euler2.fs
Last active March 12, 2016 13:46
Even Fibonacci Numbers
//Find the sum of all the even-valued terms in the Fibonacci sequence which do not exceed four million.
let fibonacciSequence = Seq.unfold(fun (a, b) -> Some(a + b, (b, a + b))) (0L, 1L)
fibonacciSequence
|> Seq.takeWhile (fun x -> x < 4000000L)
|> Seq.filter (fun x -> x % 2L = 0L)
|> Seq.sum
@DavidBrower
DavidBrower / Euler3.fs
Last active March 12, 2016 21:54
Largest Prime Factor
open System
let isPrime (n : int64) =
let upperBound = n |> float |> sqrt |> int64
seq {2L .. upperBound}
|> Seq.forall (fun x -> n % x <> 0L)
let getAllFactors (n : int64) =
let upperBound = n / 2L
seq {2L .. upperBound}
@DavidBrower
DavidBrower / Euler4.fs
Last active March 19, 2016 12:38
Finding a Palindrome Based on Jake Harry's Algorithm
//Based on Jake Harry's article on generating palindromes http://www.p196.org/papers10.html
open System
let getDistanceFromNextHundred n =
100 - (n % 100)
let getTensForAddition n =
Math.Ceiling(float n/ 10.) * 10.
|> int
@DavidBrower
DavidBrower / Euler4.fs
Created March 19, 2016 12:20
Palindrome Numbers
// A palindromic number reads the same both ways.
//The largest palindrome made from the product of two
//2-digit numbers is 9009 = 91 × 99.
//Find the largest palindrome made from the product of
//two 3-digit numbers.
open System
let noOfDigits = 3
@DavidBrower
DavidBrower / ReactiveServiceStack.cs
Created March 21, 2016 17:08 — forked from bamboo/ReactiveServiceStack.cs
Using ServiceStack* together with Reactive Extensions** to reduce the latency before the client can start processing the elements of an array response. The service sends elements to the client as soon as they become available through the magic of AsyncServiceBase, IStreamWriter, IObservable<T>.ToEnumerable() and careful use of WriteLine() and Fl…
using System;
using System.Collections.Generic;
using System.Disposables;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using Funq;
using ServiceStack.Common.Web;
using ServiceStack.Service;