Skip to content

Instantly share code, notes, and snippets.

View folkertdev's full-sized avatar

Folkert de Vries folkertdev

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / Main.elm
Last active January 26, 2017 20:56
Keep track of the number of outstanding http requests
-- Read more about this program in the official Elm guide:
-- https://guide.elm-lang.org/architecture/effects/http.html
module Main exposing (..)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Http
@folkertdev
folkertdev / Test7.hs
Created September 25, 2016 12:39
Justitia test 7
import Data.List
original =
[ "..0...0.....1."
, "1....0....0.11"
, "...1...0......"
, "1...0........."
, "......0..1.0.0"
, "1..11..1..1..."
, "........0....."
, "1.1..1...11..."
@folkertdev
folkertdev / Main.elm
Created July 14, 2016 14:24
Handling a list of OutMsg the nice way
-- Effective code. Nice and short
let
updateModel newEditor (Model generic _) =
Model generic (EditorView { apiToken = apiToken, staticToken = staticToken, editor = newEditor })
in
Editor.State.update childMsg editor
|> mapChildCmd ChildEditorAction
|> outMsgUpdate updateModel editorOutMsg model
-- The magic that makes it possible
@folkertdev
folkertdev / predicate.py
Created May 24, 2016 18:37
Generator function as a Freestyle predicate
def pyVertexNatureUP0D(nature):
""" Generator function as predicate. about 50% slower, but it works """
while True:
print("doing work")
inter = yield
if inter is None:
continue
yield bool(inter.object.nature & nature)
it = Interface0DIterator(stroke)
@folkertdev
folkertdev / tuple.cpp
Created May 24, 2016 18:36
C++ iterator to Python tuple
// from the Blender Freestyle code
static PyObject *Stroke_viewedges_begin(BPy_Stroke *self)
{
PyObject *output = PyTuple_New(self->s->viewedges_size());
std::vector<ViewEdge*>::iterator ve_it = self->s->viewedges_begin(), ve_end = self->s->viewedges_end();
for (unsigned int i = 0; ve_it != ve_end; ++ve_it, ++i) {
PyTuple_SET_ITEM(output, i, BPy_ViewEdge_from_ViewEdge(*(*ve_it)));
}