Skip to content

Instantly share code, notes, and snippets.

View brycebaril's full-sized avatar

Bryce Baril brycebaril

View GitHub Profile
@brycebaril
brycebaril / index.js
Created March 14, 2014 22:19
requirebin sketch
// try requiring some modules from NPM and then hit Run
var s = require('stats-lite')
console.log(s.mean([0, 9, 100, 3, 51, 33, Math.random() * 20]))
@brycebaril
brycebaril / index.js
Created March 14, 2014 22:19
requirebin sketch
// try requiring some modules from NPM and then hit Run
var s = require('stats-lite')
console.log(s.mean([0, 9, 100, 3, 51, 33, Math.random() * 20]))
@brycebaril
brycebaril / index.js
Created March 14, 2014 22:19 — forked from max-mapper/index.js
requirebin sketch
var observer = require('continuous-observer')
var cave = require('cave-automata-2d')
var fill = require('ndarray-fill')
var zero = require('zeros')
var raf = require('raf')
var canvas = document.createElement('canvas')
var ctx = canvas.getContext('2d')
// Set up the controls, so that we can control
@brycebaril
brycebaril / index.js
Created March 15, 2014 20:45
requirebin sketch
/*
Browserify Live Demos!
How to make your own:
1. Clone this RequireBin
2. Adjust the REQUIRES section
3. Create a gist with demo snippets that can be run
4. Put the id for that gist into the demoGist variable
*/
/* REQUIRES: Put modules you need in your demo in this Array */
var levelup = require("levelup")
var leveljs = require("level-js")
var db = levelup("./demo", {db: leveljs})
db.put("wow", "mom", function (err, reply) {
if (err) return console.log(err)
db.get("wow", function (err, reply) {
if (err) return console.log(err)
console.log("Got: '%s'", reply)
})
var stats = require("stats-lite")
var dice = require("droll")
var rolls = []
for (var i = 0; i < 3000; i++) {
rolls.push(dice.roll("2d6").total)
}
console.log("sum: %s", stats.sum(rolls))
console.log("mean: %s", stats.mean(rolls))
@brycebaril
brycebaril / index.js
Created March 16, 2014 23:20
requirebin sketch
/*
Browserify Live Demos!
How to make your own:
1. Clone this RequireBin
2. Adjust the REQUIRES section
3. Create a gist with demo snippets that can be run
4. Put the id for that gist into the demoGist variable
*/
/* REQUIRES: Put modules you need in your demo in this Array */

The prep-script.sh will setup the latest Node and install the latest perf version on your Linux box.

When you want to generate the flame graph, run the following (folder locations taken from install script):

sudo sysctl kernel/kptr_restrict=0

perf record -i -g -e cycles:u -- ~/sources/node/node --perf-basic-prof script.js

perf script | egrep -v "( __libc_start| LazyCompile | v8::internal::| Builtin:| Stub:| LoadIC:|\[unknown\]| LoadPolymorphicIC:)" | sed 's/ LazyCompile:[*~]\?/ /' | ~/sources/FlameGraph/stackcollapse-perf.pl &gt; out.perf-folded

Keybase proof

I hereby claim:

  • I am brycebaril on github.
  • I am brycebaril (https://keybase.io/brycebaril) on keybase.
  • I have a public key whose fingerprint is 602C 9953 7442 29B1 B9E2 DFD8 9425 9F4D 2F09 DCCC

To claim this, I am signing this object:

@brycebaril
brycebaril / linesplit.js
Created March 27, 2014 19:53
Split a file into a file per line of the input file.
var fs = require("fs")
var split = require("binary-split")
var terminus = require("terminus")
var path = require("path")
var input = process.argv[2]
var dir = path.dirname(input)
var basename = path.basename(input)
var count = 0