Skip to content

Instantly share code, notes, and snippets.

View SimonMeskens's full-sized avatar

Simon Meskens SimonMeskens

View GitHub Profile
@SimonMeskens
SimonMeskens / adt-examples.js
Last active February 5, 2025 01:12
ADTs in JavaScript
// Copyright 2019 Simon Meskens
// Licensed under the MIT License
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided this license is
// preserved. This software is offered as-is, without any warranty.
import { adt } from "./adt.js";
const double = x => x * 2;

Creating a Game Experience

Creating an experience is all about sculpting it with good design sense. You want to offer the player tightly designed gameplay, but also allow for lots of meaningful choices, we call this agency. Most of the examples here are geared towards open world games, with a survival element, but most of it is applicable to other games too.

Expansive Gameplay

Expansive gameplay is wide gameplay. It's all about creating varied gameplay through varied circumstances. There should be a wide range of mechanics to interest the player. We shouldn't force the player to do all of them, rather, it's about giving them the choice. We can accomplish this by dividing the gameplay into three layers.

@SimonMeskens
SimonMeskens / LISP.js
Last active February 5, 2025 01:12
Tiny LISP parser and interpreter
// Copyright 2021 Simon Meskens
// Licensed under the MIT License
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided this license is
// preserved. This software is offered as-is, without any warranty.
// Parser
const string = /"(?:\\(?:["\\\/bfnrt]|u[a-fA-F0-9]{4})|[^"\\\0-\x1F\x7F]+)*"/;
const number = /-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?/;
@SimonMeskens
SimonMeskens / Lambda.ts
Last active February 5, 2025 01:10
Lambda calculus in the TS type system
// Copyright 2021 Simon Meskens
// Licensed under the MIT License
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided this license is
// preserved. This software is offered as-is, without any warranty.
type Test1 = λ<Not, [True]>; // False
type Test2 = λ<And, [True, False]>; // False
type Test3 = λ<And, [True, True]>; // True
@SimonMeskens
SimonMeskens / HKTs.ts
Last active February 5, 2025 01:10
Higher Kinded Types in TypeScript
// Copyright 2021 Simon Meskens
// Licensed under the MIT License
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided this license is
// preserved. This software is offered as-is, without any warranty.
// Functor
interface StaticFunctor<G> {
map<F extends Generic<G>, U>(

Design challenge: design or share a regular expression DSL

Design a syntax for an alternative to classic regex. You can also share interesting existing solutions. An example of a regular expression to try implementing is the JSON number spec:

n = /-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/

All the examples here are licensed CC0. If you would like to share a solution for addition to this gist (and later a repository), send it to me and mention that you license it under CC0. If you would like to be attributed, mention under what name.

Existing solutions

@SimonMeskens
SimonMeskens / parser.js
Last active April 29, 2022 00:43
Tiny Parser Combinator Library
/*
Copyright 2022 Simon Meskens
Permission to use, copy, modify, and/or distribute this software for any purpose with
or without fee is hereby granted, provided this license is preserved. This software is
offered as-is, without any warranty.
Generate your own tiny license:
https://simonmeskens.github.io/SimpleLicenseCollection/
*/
@SimonMeskens
SimonMeskens / lexer.js
Last active February 5, 2025 01:09
JavaScript climbing parser
// Copyright 2023 Simon Meskens
// Licensed under the MIT License
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided this license is
// preserved. This software is offered as-is, without any warranty.
const types = [
[null, /[^\P{Pattern_White_Space}\n]+/msuy],
["break", /\n/msuy],
@SimonMeskens
SimonMeskens / 00Pattern.purs
Last active February 5, 2025 01:07
Brzozowski derivatives in PureScript - MIT License
module Patterns
( Pattern(..)
, unite
, concat
, repeat
, complement
, derivative
) where
import Data.Boolean (otherwise)
@SimonMeskens
SimonMeskens / UTF-8
Last active February 4, 2025 06:01
UTF-8 Explained using one diagram
UTF-8 Code point: a bb bb cc cc dd dd ee ee ff ff
0 e ee ff ff
10 ------- ----------- ---- ERROR -----------
110 d dd ee 10 ee ff ff
1110 cc cc 10 dd dd ee 10 ee ff ff
11110 a bb 10 bb cc cc 10 dd dd ee 10 ee ff ff
111110 ------- ----------- ---- ERROR -----------