Skip to content

Instantly share code, notes, and snippets.

View jcmrva's full-sized avatar

Josh M jcmrva

View GitHub Profile
@Savelenko
Savelenko / Program.fs
Last active June 13, 2021 14:41
Advanced(?) domain-driven design in F#
[<EntryPoint>]
let main argv =
printfn "Should be zero (netWeight emptyPallet): %A" Stock.shouldBeZero
printfn "harvesterPartsWeight: %A" Stock.harvesterPartsWeight
printfn "grossWeight harvesterParts: %A" (Stock.grossWeight Stock.harvesterParts)
printfn "grossWeight emptyPallet: %A" (Stock.grossWeight Stock.emptyPallet)
printfn "netWeight harvesterParts: %A" (Stock.netWeight Stock.harvesterParts)
printfn "value harvesterParts: %A" (Stock.value Stock.harvesterParts)
printfn "boxLabels harvesterParts: %A" (Stock.boxLabels Stock.harvesterParts)
printfn "boxLabels emptyPallet: %A" (Stock.boxLabels Stock.emptyPallet)
@ninjarobot
ninjarobot / farmer-global-app.fsx
Last active June 18, 2021 03:37
Farmer application with multiple resource groups and traffic manager
#r "nuget: Farmer, 1.6.0"
open Farmer
open Farmer.Builders
open Farmer.Builders.ContainerGroups
open Farmer.Builders.TrafficManager
open Farmer.TrafficManager
let msi = userAssignedIdentity {
name "my-app"
@swlaschin
swlaschin / duplicate_load.md
Last active December 20, 2020 18:59
Example of duplicate #load

The duplicate #load problem and how to fix it

Symptom: A weird error such as:

error FS0001: This expression was expected to have type
    'FSI_0011.MyType'
but here has type
    'FSI_0012.MyType'
@badamczewski
badamczewski / BitSet.cs
Created December 1, 2020 13:08
BloomFilter Source Code
using System;
using System.Collections.Generic;
using System.Text;
namespace ProbabilisticDataStructures.DataStructures
{
public class BitSet
{
private ulong[] bitset;
public int Size { get; private set; }
@patriksvensson
patriksvensson / ConsoleBuffer.cs
Last active March 31, 2021 05:28
Double Buffering Console
private static int _bufferHeight;
private static int _bufferY;
public static async Task Main()
{
_bufferWidth = Console.WindowWidth;
_bufferHeight = Console.WindowHeight;
_bufferY = _bufferHeight;
Console.SetBufferSize(_bufferWidth, _bufferHeight * 2);
@AngelMunoz
AngelMunoz / suavefileexplorer.fsx
Last active December 5, 2021 19:52
A sample of the scripting capabilities of F# 5.0
#r "nuget: Suave"
// 👆🏽 this was added in F# 5.0
// if you are using the .NET 5.0 previews or RC run as follows
// dotnet fsi suavefileexplorer.fsx --langversion:preview
open System
open System.IO
open System.Threading
open System.Text
open Suave
@troyhunt
troyhunt / rick-roll-content-scraper.js
Created August 19, 2020 07:41
A Cloudflare worker to redirect image requests from dickhead content scraper's site to a Rick Roll
addEventListener('fetch', event => {
event.respondWith(fetchAndApply(event.request))
})
async function fetchAndApply(request) {
let response = await fetch(request)
let referer = request.headers.get('Referer')
let contentType = response.headers.get('Content-Type') || ''
if (referer && contentType.startsWith('image/')) {
@akhansari
akhansari / event-sourced-user.fsx
Last active December 16, 2022 00:09
F# : Event Sourcing in a nutshell
// ========= Event Sourcing in a nutshell
(*
FriendlyName: string
Aggregate friendly name.
Initial: 'State
Initial (empty) state we will start with.
Decide: 'Command -> 'State -> 'Event list
using Octokit;
using System;
using System.Threading.Tasks;
using System.Diagnostics;
namespace UpdateGitHub
{
class Program
{
@avh4
avh4 / Wireframe.elm
Created April 25, 2020 03:29
elm-ui wireframe
module Main exposing (main)
import Element exposing (..)
import Element.Background as Background
import Element.Border as Border
import Element.Font as Font
main =
layout [] <|