Skip to content

Instantly share code, notes, and snippets.

View baronfel's full-sized avatar

Chet Husk baronfel

View GitHub Profile
@baronfel
baronfel / reduce.fsx
Created December 14, 2017 16:11
Seq.reduce example
open System.Linq
let words = [ "I"; "am"; "a"; "dog"]
let aggSentence = words.Aggregate(fun sentence word -> word + " " + sentence)
let reduceSentence = words |> Seq.reduce (fun sentence word -> word + " " + sentence)
aggSentence = reduceSentence
@baronfel
baronfel / hash.fsx
Last active January 2, 2018 22:56
hash comparisons for F# collection types
// different hashes because different Seq object instances
> hash ([|1;2;3|] |> Seq.ofArray);;
val it : int = 851672095
> hash ([|1;2;3|] |> Seq.ofArray);;
val it : int = -1641179064
// same hash because Seq.ofList is just returning the list cast to IEnumerable<'t>
> hash ([1;2;3] |> Seq.ofList);;
val it : int = 1956583134
@baronfel
baronfel / Program.fs
Last active January 23, 2018 16:25
netcoreapp2.0/net471 show SRTP example
open System
type Show = class
static member _resolve = Unchecked.defaultof<Show>
static member show (x : int) = sprintf "%d" x
static member show (x : uint32) = sprintf "%du" x
static member inline invoke x =
let inline call (_ : ^a, x : ^b) =
@baronfel
baronfel / fsharpi
Created April 8, 2018 19:42
modified fsharpi that handles piped inputs nicer (Thanks John Wostenberg!)
#!/bin/sh
EXEC="exec "
FSHARPI_OPTIONS=""
if test x"$1" = x--debug; then
DEBUG=--debug
shift
fi
if test x"$1" = x--gdb; then
@baronfel
baronfel / console.js
Last active April 19, 2018 05:03
try to repeat messages
let text = document.getElementsByTagName('input')[1];
let button = document.getElementsByTagName('button')[0];
setInterval(function () {
text.value = "hi frank.";
text.dispatchEvent(new Event('change', {bubbles: true}));
button.click()
}, 10000);
@baronfel
baronfel / fake
Created May 21, 2018 18:28
FAKE 5 netcore zsh completions
#source this from your .zshrc somehow
_fake() {
local cur
cur="${COMP_WORDS[COMP_CWORD]}"
RESULTS=$(fake -s build --list 2>/dev/null | tail -n +2 | awk '{$1=$1};1')
COMPREPLY=($(compgen -W "$RESULTS" -- "$cur"))
}
complete -F _fake fake
compdef fake
@baronfel
baronfel / Program.fs
Last active July 10, 2018 02:38
Marten DU support using hierarchical schema support
module dutest
open Marten
open Npgsql
open System
open System.Reflection
open Marten
type Case1 = { id: Guid; thing: int; status: bool }
type Case2 = { id: Guid; butts: string; ``where``: DateTime }
@baronfel
baronfel / recipe
Last active March 28, 2021 22:14
kebabs
2lb top Sirloin
2/3 C vegetable oil
1/4 C soy sauce
3T honey
2T vinegar
1-1/2 tsp ginger
1 clove garlic, crushed
8oz mushrooms
Cube steak
@baronfel
baronfel / Types.fs
Last active December 9, 2018 19:26
Snippets for my F# Advent 2018 blogpost
module Types =
type BrowserCtx =
{ /// the actual unit of work
page : Page
dispose : unit -> unit
compareTimeout : System.TimeSpan
navigateTimeout : System.TimeSpan }
member x.CurrentUrl = x.page.Url
interface IDisposable with
member x.Dispose() = x.dispose()
@baronfel
baronfel / greed.fsx
Created May 15, 2019 14:05
Greed Kata
(*
Greed is a press-your-luck dice rolling game. In the game, the player rolls the dice and tries to earn as many points as possible from the result.
For the purposes of this kata, we will just be scoring a single roll of five dice (but see Extra Credit below).
Write a scoring method that calculates the best score based on a given roll using the following set of scoring rules.
Each die can only be scored once (so single die scores cannot be combined with triple die scores for the same individual die, but for instance four 5s could count as 1 Triple (500) and 1 Single (50) for a total of 550.
A single one (100 points)
A single five (50 points)
Triple ones [1,1,1] (1000 points)
Triple twos [2,2,2] (200 points)