Skip to content

Instantly share code, notes, and snippets.

View folkertdev's full-sized avatar

Folkert de Vries folkertdev

View GitHub Profile
@folkertdev
folkertdev / DiagonalAppend.elm
Created January 27, 2017 10:54
An elm function to calculate some appending function over the diagonals of a matrix (represented as a List (List a)))
module Main exposing (..)
import Html exposing (text)
import Math.Vector2 as Vec2 exposing (Vec2, vec2)
type alias Point =
{ location : Vec2, velocity : Vec2 }
@folkertdev
folkertdev / RecursiveFuzzer.elm
Created February 9, 2017 21:23
Experiment to create an elm fuzzer for an Abstract Syntax Tree
module ExpressionFuzzer exposing (..)
import Char
import Fuzz exposing (Fuzzer, frequencyOrCrash, intRange, constant)
import Lazy as L
-- origionally by slack user stil4m
type ExprPart
= Literal String
@folkertdev
folkertdev / Array.hs
Created February 17, 2017 19:18
Using ST to modify arrays in Haskell
import Control.Monad (replicateM, forM_)
import Data.Ord (comparing)
import qualified Data.Array as Array
import qualified Data.Array.ST as Array.ST
import Control.Monad.ST
import Data.STRef
bsort :: (Ord a, Enum a, Bounded a) => Int -> (e -> a) -> [e] -> [e]
bsort numBuckets toKey items = List.concatMap (List.sortBy (comparing toKey)) $ Array.elems array
@folkertdev
folkertdev / GLAD.md
Last active March 4, 2017 16:15
Installation notes on the GLAD repository.

Installation notes on the GLAD repository.

These examples are *nix-based. Hopefully windows will not give too much extra trouble. If you run into anything, please post a comment on this gist with

  • your operating system
  • the command you ran
  • the output of the command (trim for readability if needed)
@folkertdev
folkertdev / Main.elm
Last active March 6, 2017 20:26
AI frontend mockup
module Main exposing (main)
import Html exposing (..)
import Html.Attributes exposing (style, class, defaultValue, classList, attribute, name, type_, href)
import Html.Events exposing (onClick, onInput, onWithOptions, defaultOptions)
import Http
import Json.Decode as Decode exposing (string, bool, int, float)
import Json.Decode.Pipeline as Decode exposing (..)
import Json.Encode as Encode
import Bootstrap.Navbar as Navbar
@folkertdev
folkertdev / MatrixProduct.hs
Last active March 17, 2017 21:50
Use a flat array to calculate the optimal order for a series of matrix multiplications with STUArray and the ST Monad
import Control.Monad.ST
import Data.Array.IArray as Array
import Data.STRef
import Data.Array.ST as Array.ST
import Data.Array.MArray as MArray
import Data.Array.Unboxed
solve :: Int -> List Int -> Word32
solve _ [] = 0
@folkertdev
folkertdev / PathParser.elm
Last active June 12, 2017 21:39
Elm SVG/Graphics notes
module Svg.PathParser exposing (..)
{-| Module for parsing SVG path syntax, using [elm-tools/parser](http://package.elm-lang.org/packages/elm-tools/parser/latest)
The data structure and parser is modeled according to [this W3C grammar](https://www.w3.org/TR/SVG/paths.html#PathDataBNF)
### data
The building blocks are
@folkertdev
folkertdev / SubPath.elm
Created August 5, 2017 15:11
A proposal to allow easier composition of SubPaths
module SubPath exposing (..)
import Path exposing (DrawTo(..), MoveTo(..), lineTo, closePath, moveTo)
import Deque exposing (Deque)
import Vector2 as Vec2 exposing (Vec2)
import List.Extra as List
type SubPath
= SubPath { moveto : MoveTo, drawtos : Deque DrawTo }
@folkertdev
folkertdev / ExtentWith.elm
Last active August 16, 2017 15:26
extentWith
extentWith : (a -> a -> Order) -> List a -> Maybe ( a, a )
extentWith toOrder list =
let
max a b =
case toOrder a b of
GT ->
a
_ ->
b
@folkertdev
folkertdev / Split.elm
Created September 6, 2017 18:57
a polymorphic splitting function that splits until the increase of accuracy of splitting again is below some threshold
module Geometry.Split exposing (..)
type alias Config a =
{ length : a -> Float
, split : Float -> a -> ( a, a )
, percentageError : Float
}