Skip to content

Instantly share code, notes, and snippets.

@thysultan
thysultan / prng.js
Created November 13, 2018 12:26
prng
const prng = ((seed, size, value = seed % size) => () => ((value = value * 16807 % size - 1) - 1) / size)(4022871197, 2147483647)
@thysultan
thysultan / index.js
Created September 16, 2018 01:18
array-index elements.
'use strict'
var h1 = function (tag, props, children) {
return {tag: tag, props: props, children: children}
}
var h2 = function (tag, props, children) {
return {tag: tag, props: props, children: children, 9: ''}
}
const N = 10000;
const FOO = 'foo';
function test(fn) {
var result;
for (var i = 0; i < N; ++i) result = fn();
return result;
}
test(x => x);
@thysultan
thysultan / worker.html
Last active December 14, 2017 16:25
DIO running in a web worker.
<script id="worker" type="worker">
importScripts('https://unpkg.com/dio.js')
const shared = {memory: {}, address: 0}
const allocateMemory = (object) => {
shared.memory[shared.address] = object
return shared.address++
}
function Stack () {
this.next = this
this.prev = this
this.length = 0
}
Stack.prototype = {
/**
* @param {Object} node
* @param {Object} before
@thysultan
thysultan / interface.ts
Last active August 27, 2017 01:41
virtual node interface
interface Virtual {
merge(Virtual)
}
interface VirtualStyle extends Virtual {
merge(VirtualStyle)
}
interface VirtualProperties extends Virtual {
style: VirtualStyle

A Journey Into Building a Fast Text Editor With JS & Canvas!

Text editors have a way of looking simple but managing and painting text is no small task, this talk will give us a look into what bits(literaly) and pieces go into making a fast text editor with Javascript & Canvas. We'll look into what format the text you type is stored in, how it's mutated and highlighted, and how all of this is translated onto a canvas in less than the time it takes you to blink. As a by product we'll get to see how a regular expression engine is implementated and why games use draw distance to save precious hardware resources.

var length = 1024*100; // enough to store 100kb of instrutions at any time
var action = new Uint8Array(length);
var memory = new Array(length);
// action carry instructions with pointers to memory for where to find the nodes to act on
// memory carries nodes that exist in memory
// for example
function frameScheduler (fps) {
var highPriWork = [];
var lowPriWork = [];
var highPriWorkLen = 0;
var lowPriWorkLen = 0;
var frameBudget = 1000 / fps;
var lastTime = 0;
var asyncCallback;
var Promise = window.Promise;
@thysultan
thysultan / flatten.js
Last active September 22, 2016 06:29
flatten array
/**
* flattens a nested array
* 1. takes an array and optional destination array
* 2. iterates through the array
* 3. if an item in the array is an array
* run through flatten with the second argument
* as the destination array
* this will add every item within the passed array
* into the destination array