Skip to content

Instantly share code, notes, and snippets.

View ascjones's full-sized avatar

Andrew Jones ascjones

View GitHub Profile
[<AutoOpen>]
module JsonExtensions =
open System
open Fleece
open Fleece.Operators
open FSharpPlus
open System.Globalization
type FromJSONClass with
Verifying that +ascjones is my Bitcoin username. You can send me #bitcoin here: https://onename.io/ascjones
@ascjones
ascjones / Bowling
Created November 25, 2014 16:50
Super Strongly Typed Bowling Kata
open System
// THE MODEL represents only allowed states
// ========================================
type Game =
{ F1 : Frame; F2 : Frame; F3 : Frame; F4 : Frame; F5 : Frame; F6 : Frame; F7 : Frame; F8 : Frame; F9 : Frame; F10 : FinalFrame } // todo: add extra frames, and FinalFrame type?
and Frame =
| Strike
| Spare of PinCount
@ascjones
ascjones / EventStoreHelpers.fs
Created January 9, 2015 16:15
Connect to EventStore Cluster
module EventStoreHelpers =
open System
open System.Net
open EventStore.ClientAPI
let inline private (!>) (x:^a) : ^b = ((^a or ^b) : (static member op_Implicit : ^a -> ^b) x)
let private dnsLookup (host : string) =
let hostEntry = Dns.GetHostEntry(host)
@ascjones
ascjones / $profile
Created January 16, 2015 14:42
Powershell Prompt
function prompt {
# Admin ?
if( (
New-Object Security.Principal.WindowsPrincipal (
[Security.Principal.WindowsIdentity]::GetCurrent())
).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
{
# Admin-mark in WindowTitle
$Host.UI.RawUI.WindowTitle = "[Admin] " + $Host.UI.RawUI.WindowTitle
@ascjones
ascjones / FiniteSets
Created January 16, 2015 16:12
C# Finite Sets
interface IFin
{
int Ordinal { get; }
}
class Fin3 { }
class Fin2 : Fin3 { }
class Fin1 : Fin2 { }
class Fin0 : Fin1 { }
class Foo
@ascjones
ascjones / YesOrNo.cs
Last active August 29, 2015 14:13
Yes Or No
class YesOrNo<TState>
{
private readonly TState state;
private readonly bool keepGoing;
public bool Success { get { return keepGoing; } }
public YesOrNo(TState state = default (TState), bool keepGoing = true)
{
this.state = state;
@ascjones
ascjones / trailingzeros.fs
Created January 21, 2015 11:21
Stripping trailing 0s from decimal
let stripZeros d = d / 1.000000000000000000000000000000000M
// > stripZeros 1.5000M;;
// val it : decimal = 1.5M
@ascjones
ascjones / ConsoleProgressBar.cs
Last active August 29, 2015 14:14
ConsoleProgressBar
class ProgressBar
{
private const char Start = '[';
private const char End = ']';
private const char InProgress = '>';
private const char Done = '-';
private readonly int totalSize;
private readonly int progressLength;
private readonly int chunkSize;
@ascjones
ascjones / EventStoreHelpers.cs
Created February 12, 2015 12:45
Some helpers for recursively reading all events from a stream
public static class EventStoreHelpers
{
public static IEnumerable<T> ReadAllStreamEventsForward<T>(this IEventStoreConnection conn, string streamName, Func<RecordedEvent, T> createEvent, int pageSize)
{
StreamEventsSlice currentSlice;
var nextSliceStart = StreamPosition.Start;
do
{
var task = conn.ReadStreamEventsForwardAsync(streamName, nextSliceStart, pageSize, true); task.Wait();
currentSlice = task.Result;