Skip to content

Instantly share code, notes, and snippets.

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 / 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: ''}
}
@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.html
Created December 13, 2018 10:01
router
<script type="module">
import {h, render} from '//unpkg.com/dyo?module'
function handleLocation ({href} = location, {origin} = location) {
return href.replace(origin, '')
}
function handleClick (event, {href, children}, state, context) {
context.forceUpdate(history.pushState(event.preventDefault(), document.title = children, href))
}
// currentTarget is the current value i.e null/node while target is always node
function subscribe ({timeout = setTimeout(() => {}), target, currentTarget}, props, state, context) {
// when a function is returned it is used when the ref is unmounted.
return () => cleartimeout(returnValue)
}
@thysultan
thysultan / refs.js
Last active December 14, 2018 22:44
Refs
// currentTarget is the current value i.e null/node while target is always the node the ref was attached to
// or vice-versa if matching event target/currentTarget sementics is of any merit.
function subscribe ({currentTarget, target, timeout = setInterval(() => {})}) {
assert(currentTarget instanceof Node || current === null)
assert(target instanceof Node)
// when a function is returned it is used when the ref is unmounted.
return () => setInterval(timeout)
}
@thysultan
thysultan / bench-instanceof-versus-typeof-megamorphic.js
Last active January 29, 2019 08:35 — forked from bmeurer/bench-instanceof-versus-typeof-megamorphic.js
Demonstrate the performance impact of using `instanceof` vs. checking for some existing property (in the megamorphic case)
// Copyright 2013-2019 Benedikt Meurer
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// <https://www.apache.org/licenses/LICENSE-2.0>
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@thysultan
thysultan / gist:6941195937a3dcf7b123995d486ec51b
Created January 30, 2019 15:23 — forked from totherik/gist:3a4432f26eea1224ceeb
v8 --allow-natives-syntax RuntimeFunctions
Per https://code.google.com/p/v8/codesearch#v8/trunk/src/runtime.cc
%CreateSymbol
%CreatePrivateSymbol
%CreateGlobalPrivateSymbol
%NewSymbolWrapper
%SymbolDescription
%SymbolRegistry
%SymbolIsPrivate
@thysultan
thysultan / v8.md
Created January 30, 2019 15:36 — forked from kevincennis/v8.md
V8 Installation and d8 shell usage

Installing V8 on a Mac

Prerequisites

  • Install Xcode (Avaliable on the Mac App Store)
  • Install Xcode Command Line Tools (Preferences > Downloads)
  • Install depot_tools
    • git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
    • sudo nano ~/.bash_profile
  • Add export PATH=/path/to/depot_tools:"$PATH" (it's important that depot_tools comes first here)
@thysultan
thysultan / WebGL-frameworks-libraries.md
Created February 9, 2019 23:51 — forked from dmnsgn/WebGL-WebGPU-frameworks-libraries.md
A collection of WebGL frameworks and libraries

A non-exhaustive list of WebGL frameworks and libraries. It is mostly for learning purposes as some of the libraries listed are outdated/not maintained anymore.

Engines and libraries

  • three.js: JavaScript 3D library
  • stack.gl: an open software ecosystem for WebGL, built on top of browserify and npm.
  • PixiJS: Super fast HTML 5 2D rendering engine that uses webGL with canvas fallback
  • Pex: Pex is a javascript 3d library / engine allowing for seamless development between Plask and WebGL in the browser.
  • Babylon.js: a complete JavaScript framework for building 3D games with HTML 5 and WebGL
  • AwayJS: AwayJS is a graphics library for javascript written in typescript
  • SceneJS: An extensible WebGL-based engine for high-detail 3D visualisation