Skip to content

Instantly share code, notes, and snippets.

View ohlawdie's full-sized avatar
😟

Ohlawdie ohlawdie

😟
  • Michigan
View GitHub Profile
@ohlawdie
ohlawdie / ActivePatternDecomposition
Last active February 11, 2020 22:40
Active Pattern Decomp #F
open System.Drawing
let (|RGB|) (col : System.Drawing.Color) =
( col.R, col.G, col.B )
let (|HSB|) (col : System.Drawing.Color) =
( col.GetHue(), col.GetSaturation(), col.GetBrightness() )
let printRGB (col: System.Drawing.Color) =
match col with
@ohlawdie
ohlawdie / stuffgunk.fs
Last active February 11, 2020 22:40
C8 Indices and Ranges #cs2fs
namespace global
open System
open System.Linq
namespace ExploreCsharpEight
type IndicesAndRanges() =
member val private words = [|"The"; "quick"; "brown"; "fox"; "jumped"; "over"; "the"; "lazy"; "dog"|] with get, set
member this.Syntax_LastIndex() =
Console.WriteLine (sprintf "The last word is %O" this.words.[(int (* ERROR UnknownPrefixOperator "^" *))])
0
member this.Syntax_Range() =
@ohlawdie
ohlawdie / uncheckedcs2fs.fs
Last active February 11, 2020 22:40
Unchecked #cs2fs
namespace global
namespace ConsumerVehicleRegistration
type Car() =
member val Passengers = Unchecked.defaultof<int> with get, set
namespace CommercialRegistration
type DeliveryTruck() =
member val GrossWeightClass = Unchecked.defaultof<int> with get, set
namespace LiveryRegistration
type Taxi() =
@ohlawdie
ohlawdie / asyncstream.fs
Created February 11, 2020 22:41
C8 Async Streams #F
namespace global
open System
open System.Collections.Generic
open System.Threading.Tasks
namespace ExploreCsharpEight
type AsyncStreams() =
member this.GenerateSequence() =
do
let mutable (i : int) = 0
while (i < 20) do
@ohlawdie
ohlawdie / FSharpEncoder.fs
Created February 11, 2020 22:44
F# char encoder? #F
namespace global
open System
open System.Collections.Generic
open System.Linq
open System.Text
open System.Threading.Tasks
open System.IO
open System.Diagnostics
namespace File_Encoder
type Encoder() =
@ohlawdie
ohlawdie / morefencoder.fs
Created February 11, 2020 22:45
More of the F# encoder #F
namespace global
open System
open System.Collections.Generic
open System.Linq
open System.Text
open System.Threading.Tasks
open System.IO
open System.Diagnostics
namespace File_Encoder
type Program() =
@ohlawdie
ohlawdie / SingletonWrappedWithAttribute
Created February 18, 2020 01:14
#singleton F# #Fsharp #F#
type ConstructionAttribute(singleInstance : bool) =
inherit System.Attribute()
member this.IsSingleton = singleInstance
let singletons = new System.Collections.Generic.Dictionary<System.Type,obj>()
let make() : 'a =
let newInstance() = System.Activator.CreateInstance<'a>()
let attributes = typeof<'a>.GetCustomAttributes(typeof<ConstructionAttribute>, true)
let singleInstance =
if attributes.Length > 0 then
type DealResult = {
Card : Card option
Deck : Deck
}
let dealACard deck =
match deck with
| [] -> { Card = None; Deck = deck }
| card::restOfDeck -> { Card = Some card; Deck = restOfDeck }
#r "System.Data.Linq"
open System
open System.Reflection
open System.ComponentModel
open System.Linq.Expressions
open Microsoft.FSharp.Reflection
open Microsoft.FSharp.Quotations
module FSharpType =
@ohlawdie
ohlawdie / OneSuchCacheFunc.fs
Created February 18, 2020 23:49
#FS #Cache
let Cache (reader: 'key -> 'value) max =
let cache = new Dictionary<'key,LinkedListNode<'key * 'value>>()
let keys = new LinkedList<'key * 'value>()
fun (key : 'key) -> (
let found, value = cache.TryGetValue key
match found with
|true ->
keys.Remove value
keys.AddFirst value |> ignore