Skip to content

Instantly share code, notes, and snippets.

View goswinr's full-sized avatar

Goswin Rothenthal goswinr

View GitHub Profile
@swlaschin
swlaschin / effective-fsharp.md
Last active March 8, 2024 03:10
Effective F#, tips and tricks

Architecture

  • Use Onion architecture

    • Dependencies go inwards. That is, the Core domain doesn't know about outside layers
  • Use pipeline model to implement workflows/use-cases/stories

    • Business logic makes decisions
    • IO does storage with minimal logic
    • Keep Business logic and IO separate
  • Keep IO at edges

@jdh30
jdh30 / JsonParser.fs
Last active January 30, 2024 14:06
Simple JSON parser written in F# using active patterns
type Json =
| Null
| Bool of bool
| Number of float
| String of string
| Array of Json list
| Object of (string * Json) list
type Bracket = Open | Close
@OnurGumus
OnurGumus / Dat.fs
Last active November 21, 2023 20:21
three.js fable
module rec Dat
open Browser.Types
open Fable.Core
open System
[<ImportAll("dat.gui")>]
let exports: IExports = jsNative
[<AllowNullLiteral>]
@rflechner
rflechner / Huffman.fs
Last active September 29, 2023 07:30
A FSharp implementation of Huffman compression algorithm
module Huffman
open System
open System.IO
type bit = bool
type path = bit list
type BinaryTreeNode =
| Leaf of byte * frequency:int
@teocomi
teocomi / Win32Api.cs
Last active April 24, 2023 07:09
Run Revit commands using Win32 API
/// <summary>
/// Run Revit commands using Win32 API
/// </summary>
public class Win32Api
{
[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
static extern bool SetFocus(IntPtr hWnd);

Fsharp goodies (Vol 1)

After the 'F# Compiler Community Session' I read the first 1K lines of SyntaxTree.fs. That's what I learned about the language.

  1. There is a byte string

    let a = "abc"B
    val a : byte [] = [|97uy; 98uy; 99uy|]
@alfonsogarciacaro
alfonsogarciacaro / Deploy.md
Last active March 3, 2023 09:50
Deploying an F# ASP.NET Core app (Giraffe) to Azure

Deploying an F# ASP.NET Core app to Azure

Last week I spent a lot of time trying to deploy an F# ASP.NET Core app (a Giraffe app, specifically) to Azure because the information to complete all the steps was scattered in several places. So I'm writing this hopefully it will save the pain to others :)

Preparation

The following steps are mostly taken from this guide and it's only necessary to do them once:

  1. Create an account in Azure (or use an existing one)
  2. Create a resource group (or use an existing one)
@imAliAsad
imAliAsad / ExtractFamilyParameterData.cs
Created January 21, 2018 08:01
Extract or read Revit family parameter data and convert its internal ( Imperial ) unit into the metrics unit
/// <summary>
/// Extract all family type properties data
/// </summary>
/// <param name="app"></param>
private MultiValueDictionary<string, Tuple<string, string>> ExtractFamilyParameterInfo(Application app)
{
//Open Revit Family File in a separate document
var doc = app.OpenDocumentFile(FamilyPath);
@Horusiath
Horusiath / RTree.fs
Last active October 26, 2022 13:55
RTree implementation for 2D spatial data
(*
An immutable R-Tree implementation in F#.
Based on: https://github.com/swimos/swim-rust/tree/main/swim_utilities/swim_rtree (licensed on Apache 2.0)
Author: Bartosz Sypytkowski <b.sypytkowski at gmail.com>
*)
namespace Demos.RTree
@deviousasti
deviousasti / Rpc.fs
Last active August 23, 2022 15:04
Fast inter-process RPC using shared memory
open SharedMemory
open MBrace.FsPickler
module Rpc =
type RpcContext<'command, 'message> =
{ name: string; buffer: RpcBuffer; post: 'command -> Async<'message>} with
interface IDisposable with
member this.Dispose() = this.buffer.Dispose()
let createHost name (handler : 'command -> Async<'message>) =