Skip to content

Instantly share code, notes, and snippets.

View ascjones's full-sized avatar

Andrew Jones ascjones

View GitHub Profile

Keybase proof

I hereby claim:

  • I am ascjones on github.
  • I am ascjones (https://keybase.io/ascjones) on keybase.
  • I have a public key ASBTq9RVfmKxJwI8qnHwlnEq2P7FItUz0kuPzITwwCBJBwo

To claim this, I am signing this object:

@ascjones
ascjones / FindConflictingReferences.fsx
Last active January 12, 2016 12:50
Script to find conflicting .NET assembly references
// translated to F# Script from https://gist.github.com/brianlow/1553265
open System.IO
open System.Reflection
type Reference = {
Assembly : AssemblyName
ReferencedAssembly : AssemblyName
}
@ascjones
ascjones / OptionLists.fsx
Created September 17, 2015 12:12
list of options to option list
let optionList l =
let rec bindList xs acc =
match xs with
| [] -> Some acc
| h::t -> h |> Option.bind (fun x -> bindList t (x::acc))
bindList l []
module Option =
let map2 f a b =
a |> Option.bind (fun a' -> b |> Option.map (fun b' -> f a' b'))
@ascjones
ascjones / Blob.fsx
Created June 22, 2015 09:21
Count the blobs in a grid
module Blob
type Cell =
| Black
| White
type Grid = Cell [,]
Array2D.init 4 4 (fun x y -> x + y) |> Array2D.mapi (fun x y _ -> (x,y))
@ascjones
ascjones / MemoryCacheExtensions
Created March 11, 2015 10:52
Lazy MemoryCache Extensions
public static class MemoryCacheExtensions
{
public static T AddOrGetExistingLazy<T>(this MemoryCache cache, string key, Func<T> valueFactory, CacheItemPolicy cacheItemPolicy)
{
var newValue = new Lazy<T>(valueFactory);
var value = (Lazy<T>)cache.AddOrGetExisting(key, newValue, cacheItemPolicy);
return (value ?? newValue).Value; // Lazy<T> handles the locking itself
}
public static void SetLazy<T>(this MemoryCache cache, string key, T value, CacheItemPolicy cacheItemPolicy)
@ascjones
ascjones / ConEmu.xml
Created February 19, 2015 17:30
ConEmu Settings
<?xml version="1.0" encoding="utf-8"?>
<key name="Software">
<key name="ConEmu">
<key name=".Vanilla" modified="2015-02-19 17:28:16" build="140505">
<value name="ColorTable00" type="dword" data="00000000"/>
<value name="ColorTable01" type="dword" data="00800000"/>
<value name="ColorTable02" type="dword" data="00008000"/>
<value name="ColorTable03" type="dword" data="00808000"/>
<value name="ColorTable04" type="dword" data="00000080"/>
<value name="ColorTable05" type="dword" data="00800080"/>
@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;
@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 / 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 / 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;