Skip to content

Instantly share code, notes, and snippets.

View yelouafi's full-sized avatar

Yassine Elouafi yelouafi

View GitHub Profile
@yelouafi
yelouafi / InstancedBatchedSkinnedMesh.js
Created September 27, 2024 09:23
InstancedBatchedSkinnedMesh
// from https://x.com/Cody_J_Bennett/status/1818025947565584873
// demo https://jsfiddle.net/cbenn/Las0poyu
import * as THREE from "three";
import Stats from "three/addons/libs/stats.module.js";
import { OrbitControls } from "three/addons/controls/OrbitControls.js";
import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";
import { mergeVertices } from "three/addons/utils/BufferGeometryUtils.js";
THREE.ShaderChunk.skinning_pars_vertex =

In this tutorial we're going to build a set of parser combinators.

What is a parser combinator?

We'll answer the above question in 2 steps.

  1. What is a parser?
  2. and, what is a parser combinator?

So first question: What is parser?

@yelouafi
yelouafi / algebraic-effects-series-1.md
Last active September 15, 2024 16:59
Operational Introduction to Algebraic Effects and Continuations

Algebraic Effects in JavaScript part 1 - continuations and control transfer

This is the first post of a series about Algebraic Effects and Handlers.

There are 2 ways to approach this topic:

  • Denotational: explain Algebraic Effects in terms of their meaning in mathematics/Category theory
  • Operational: explain the mechanic of Algebraic Effects by showing how they operate under a chosen runtime environment

Both approaches are valuables and give different insights on the topic. However, not everyone (including me), has the prerequisites to grasp the concepts of Category theory and Abstract Algebra. On the other hand, the operational approach is accessible to a much wider audience of programmers even if it doesn't provide the full picture.

@yelouafi
yelouafi / delimited-continuations.js
Last active June 4, 2024 04:56
delimited continuations using javascript generators
// We model the call stack using a linked list of Generators
// Each Generator has a _return field pointing back to its parent
function stepGen(gen, arg) {
const {done, value} = gen.next(arg)
if(done) {
if(gen._return) {
stepGen(gen._return, value)
}
var $jscomp = $jscomp || {};
$jscomp.scope = {};
$jscomp.arrayIteratorImpl = function (h) {
var n = 0;
return function () {
return n < h.length ? { done: false, value: h[n++] } : { done: true };
};
};
$jscomp.arrayIterator = function (h) {
return { next: $jscomp.arrayIteratorImpl(h) };
@yelouafi
yelouafi / algebraic-effects-series-4.md
Last active March 1, 2024 15:31
Implementing Algebraic Effects and Handlers

Algebraic Effects in JavaScript part 4 - Implementing Algebraic Effects and Handlers

This is the final part of a series about Algebraic Effects and Handlers.

So we've come to the core topic. The reality is that we've already covered most of it in the previous parts. Especially, in the third part, where we saw delimited continuations at work.

@yelouafi
yelouafi / algebraic-effects-series-2.md
Last active April 19, 2023 08:20
Capturing continuations with Generators

Algebraic Effects in JavaScript part 2 - Capturing continuations with Generators

This is the second part of a series about Algebraic Effects and Handlers.

Note: initially I planned a 3-part series, but since the current post on undelimited continuations ended up taking

@yelouafi
yelouafi / algebraic-effects-series-3.md
Last active April 19, 2023 06:07
Delimited Continuations
@yelouafi
yelouafi / multishot-callcc.js
Created September 21, 2018 17:05
multi shot continuations
function isGenerator(x) {
return x != null && typeof x.next === "function"
}
function isFrame(x) {
return x != null && x._type_ === 'call_frame'
}
function call(genFunc, ...args) {
/*
The MIT License (MIT)
Copyright (c) 2014
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