Skip to content

Instantly share code, notes, and snippets.

@cmf028
cmf028 / aabb_transform.comp
Last active February 21, 2024 19:13
Optimized matrix transforms of an AABB to an AABB
// The MIT License (MIT)
// Copyright (c) 2018 cmf028
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
@praeclarum
praeclarum / Ukf.fs
Created May 26, 2016 05:04
Unscented Kalman Filter (nonlinear version of the classic Kalman filter) in F#
module Drone.Control.Ukf
open System
open Drone.Control.Matrix
type IDiscreteModel =
abstract Process : Matrix -> Matrix
abstract Observe : Matrix -> Matrix
abstract InitialState : Matrix
@latkin
latkin / NativeMethods.fs
Created February 22, 2016 19:46
F# p/invoke example with structs
namespace Test
open System.Runtime.InteropServices
// F# implementation of http://pinvoke.net/default.aspx/mpr.WNetAddConnection2
module NativeMethods =
type ResourceScope =
| Connected = 0x1u
| GlobalNet = 0x2u
@cloudRoutine
cloudRoutine / fs-coreclr-build.md
Last active October 18, 2015 20:59
Build the Visual F# Compiler and Tools for .Net CoreCLR ( On Windows )

Make things easy for yourself and start by running posh as admin

If you already have dnvm installed remember to run update-self if you haven't recently

Clone and checkout the coreclr branch of Kevin Ransom's Fork of the Visual F# Compiler and Tools

Installing DNVM

You need DNVM as a starting point. DNVM enables you to acquire a (or multiple) .NET Execution Environment (DNX).

@dvdsgl
dvdsgl / Monads for a C# dev.md
Last active January 8, 2024 06:11
Monads explained (sort of) to a C# developer

A monad is a fancy word for a generic type of the form MyMonad<T> (a generic type of arity 1).

A monad is special because it adds 'special powers' to the T that it wraps. These 'special powers' won't sound very special to an imperative programmer, so you have to squint to see them but bear with me.

  • IEnumerable<T> is a monad that gives values of type T the special power of nondeterminism, or the ability to 'be' multiple values at once.
  • Nullable<T> is a monad that gives values of type T the special power of nullability, or the ability to be absent.
  • Task<T> is a monad that gives values of type T the special power of asynchronicity, or the ability to be used before they are computed.

The trick with monads comes when you want to play with the T values, because they are inside another type. C# introduced language changes to make dealing with values inside these monads easier:

type Bridge = { RunwayLength: int; GapSize: int; LandingSize: int }
type BikeState = { Speed: int; Position: int }
// Get current position
let (|OnTheRunway|JustBeforeGap|InFlight|AfterGap|) bikeState =
if bikeState.Position >= bridge.RunwayLength + bridge.GapSize then AfterGap
elif bikeState.Position > (bridge.RunwayLength - bikeState.Speed) then JustBeforeGap
elif bikeState.Position < bridge.RunwayLength then OnTheRunway
else InFlight
@TheSeamau5
TheSeamau5 / hackyECS.elm
Last active October 7, 2015 15:53
Entity Component Systems in Elm using hacks à-la elm-webgl
type Entity entity = Entity
type Component = Component
get : String -> Entity -> Maybe Component
get = ECS.Native.get
update : String -> a -> Entity -> Entity
update = ECS.Native.update
@TheSeamau5
TheSeamau5 / QuasiFullECS.elm
Last active August 3, 2017 23:09
Quasi-Full expression of Entity Component System in Elm
import Color (Color, rgb)
import Graphics.Collage (..)
import Graphics.Element (Element)
import List ((::), map)
import Signal (Signal, foldp, (<~), sampleOn)
import Keyboard (arrows)
import Time (millisecond, every)
--------------------------
@TheSeamau5
TheSeamau5 / EntityComponentSystemExploration.md
Created December 29, 2014 23:16
An exploration of the Entity Component System in Elm

#Exploring Entity Component Systems in Elm

Entity-Component-System (or ECS) is a pattern for designing programs that is prevalent in the games industry. This pattern consists of three simple parts:

  • Entity : A uniquely identifiable object that may contain any number of components
  • Component : A property usually representing the raw data of one aspect of the object. (Position is a component, Velocity is a component, Strength is a component, etc...)
  • System : A continuous process performing actions on every entity that possesses a component of the same aspect as that system

To understand this, let us try to make a simple example: Boxes that move in space:

@praeclarum
praeclarum / AutoLayout.fs
Last active April 27, 2020 11:07
AutoLayout wrapper to make creating constraints in F# easier
module Praeclarum.AutoLayout
open System
#if __IOS__
open Foundation
open UIKit
type NativeView = UIView
#else
open Foundation