Skip to content

Instantly share code, notes, and snippets.

@chandlerprall
chandlerprall / gist:0667ec5bbbdc0d3a615ffe50f8a10ab1
Last active Feb 11, 2021
writing a remark 13 variable plugin
View gist:0667ec5bbbdc0d3a615ffe50f8a10ab1
// reference plugin:
// https://github.com/remarkjs/remark-gfm/blob/main/index.js
// which wraps:
// https://github.com/micromark/micromark-extension-gfm-strikethrough/blob/56aef3a974c1b9baee72279e93f9c1fe7205a9af/index.js#L23
const remark = require('remark');
const Compiler = (tree) => {
return tree;
};
View propagate.test.ts
import Propagate from './propagate';
describe('Propagate', () => {
describe('value storage & looking', () => {
it('stores a single value for lookup', () => {
const propagate = new Propagate();
propagate.set('mykey', 'myvalue');
expect(propagate.get('mykey')).toBe('myvalue');
});
View highentropy_vs_lowentropy
function doSomething(config) {
var result = {};
if (config.enableA) {
... 10 lines of code ...
result.A = {};
}
if (config.enableB) {
... 15 lines of code ...
result.B = {};
View promise-example.js
// myFunc will be executed asynchronously after the initial promise resolved
somePromise.then(myFunc)
// event if the originating promise doesn't do anything asynchronously
function quickPromise() {
// this function returns a promise that immediately resolves with "hello world"
return new Promise(resolve => {
resolve('hello world');
});
}
View immutable_benchmark.js
var Immutable = require('immutable');
Immutable.Map.Empty = new Immutable.Map();
var map = new Immutable.Map({test: 'ing'});
var start = Date.now();
for (var i = 0; i < 10000000; i++) {
var thing = map.get('test');
}
var end = Date.now();
console.log('baseline', end - start);
View gist:b92605dec99a45fd4c13
var foo = new THREE.Object3D();
foo.quaternion.set( 0, 1, 0, 1 ).normalize();
var direction = new THREE.Vector3( 1, 0, 0 );
direction.applyQuaternion( foo.quaternion );
console.log( direction.x + ',' + direction.x + ',' + direction.z ); //0,0,-0.9999999999999998
View d8 --harmony_collections --trace_gc --expose_gc
wm = new WeakMap();
gc(); // Mark-sweep 2.6 (40.3) -> 2.2 (40.3) MB
// Starting memory usage is 40.3 MB
keys = [];
for ( i = 0; i < 1000000; i++ ) {
var key = {};
keys.push( key );
wm.set( key, true );
View gist:5311808
(function() {
'use strict';
var FLOAT_VIEW = new Float32Array( 1 ),
INT_VIEW = new Uint32Array( FLOAT_VIEW.buffer ),
rsqrt = function( number ) {
var x2 = 0.5 * number;
FLOAT_VIEW[0] = number;
INT_VIEW[0] = 0x5f3759df - ( INT_VIEW[0] >>> 1 );
View gist:3383018
terrain_shader = new TerraFrame.TerrainShader({
uniforms: [
{ name: 'sunlight_dir', type: 'v3', value: new THREE.Vector3( -.5, .8, .7 ) }
],
textures: [
{ name: 'grass', asset: 'terrain.grass', repeat: new THREE.Vector2( 2, 2 ) },
{ name: 'rock', asset: 'terrain.rock', repeat: new THREE.Vector2( 3, 3 ) },
{ name: 'sand', asset: 'terrain.sand', repeat: new THREE.Vector2( 2, 2 ) }
],
pieces: [