Skip to content

Instantly share code, notes, and snippets.

View bmeck's full-sized avatar

Bradley Farias bmeck

View GitHub Profile
@bmeck
bmeck / esnextbin.md
Created February 19, 2016 17:50
esnextbin sketch
@bmeck
bmeck / out.log
Created January 19, 2016 18:28
using flow@0.2.3 from npm,
LMDV-BRADLEY:flowdoc bfarias$ flow check
lib/index.js:4
4: import {parse} from 'babylon';
^^^^^^^^^ babylon. Required module not found
node_modules/babylon/index.js:77
77: function getOptions(opts /*:: ?: Object*/) /*: Object*/ {
^ Type annotations are not allowed in untyped mode
// what does
yield: ({*yield(){yield yield;}}.yield((yield) => yield));
// mean?
// the key is that in sloppy mode "yield" is not a reserved word
// this is shown in the spec with [~yield] on grammar rules
yield:
// make a labelled statement (the statement that follows gets this label)
// completely useless unless the next statement is an iteration statement (loop)
@bmeck
bmeck / globals.js
Created December 18, 2015 00:29
finding globals in an ES6 world
#!/usr/bin/env node
// usage: node globals.js $FILE_TO_FIND_GLOBALS
var fs = require('fs');
var src = fs.readFileSync(process.argv[2]).toString();
//src = 'function foo() {foo()}'
var esprima = require('esprima');
var globals = new Set();
@bmeck
bmeck / SplitSnapshotProvider.js
Created November 7, 2015 07:42
an abomination while reducing mem usage during node knockout
import fs from "fs";
import path from "path";
const readFileRange = (file, start, stop) => {
const fd = fs.openSync(file, 'r');
let length = stop - start;
let read = 0;
const buf = new Buffer(length);
while (read !== length) {
read += fs.readSync(fd, buf, read, length - read, start + read);
"use strict";
//
// node find-retained_size.js ./path/to/snapshot.json
//
import {HeapSnapshot,JSONSnapshotProvider} from '../';
import {resolve} from 'path';
const file = resolve(process.argv[2]);
@bmeck
bmeck / single-bin.log
Created September 3, 2015 17:08
Making a purely JS single binary in node 3.3.0+
[0] 12:06 PM bradleymeck node $ cat ../my-app/package.json
{
"name": "my-app",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"build": "browserify --bare --standalone my-app server.js -o _third_party_main.js",
"start": "node server.js"
},
#! iojs --expose-gc $mode
// creates 10e3 maps with 10 elements each
// runs 10e3 gc() after
// modes: ["m", "w"]
// m: use a normal map
// w: use a weak map
var maps;
function create_maps(c, n) {
maps = [];
for (var m = 0; m < c; m++) {
function toTrees(log, heapsnapshot) {
var nodes = Object.create(null);
var node_fields = heapsnapshot.snapshot.meta.node_fields;
var node_types = heapsnapshot.snapshot.meta.node_types;
var edge_fields = heapsnapshot.snapshot.meta.edge_fields;
var edge_types = heapsnapshot.snapshot.meta.edge_types;
var nodes_arr = [];
var edges = [];
for (var i = 0; i < heapsnapshot.nodes.length; i+= node_fields.length) {
var _node = Object.create(null);
function f() {
// put const here to make sure no teammate accidentally changes the ref
const needs_to_stay_same_ref = {};
// something like a setInterval to check on the status of an object
persistently_cached_arg_fn(needs_to_stay_same_ref);
// expose something the outside world could change
return needs_to_stay_same_ref;
}