Skip to content

Instantly share code, notes, and snippets.

View ngryman's full-sized avatar

Nicolas Gryman ngryman

View GitHub Profile
@ngryman
ngryman / hearbeat.js
Created February 11, 2016 17:02
Heartbeat relative to mouse position
/**
* Heartbeat rhythm
*/
var heart = document.querySelector('footer span')
var heartBounds = heart.getBoundingClientRect()
var rhythm
document.body.addEventListener('mousemove', function(e) {
var mx = e.clientX
var my = e.clientY
@ngryman
ngryman / transcode.js
Created June 5, 2015 14:47
transcode stream.
var PassThrough = require('stream').PassThrough
, util = require('util')
, spawn = require('child_process').spawn
, os = require('os');
function Transcoder() {
PassThrough.call(this);
this.on('pipe', function(inStream) {
// inStream.unpipe(this)
@ngryman
ngryman / trace.js
Created May 31, 2015 22:20
Trace optimizations in v8
// warm up
fn()
fn()
// try to optimize
;%OptimizeFunctionOnNextCall(compare)
// call optimized
fn()
@ngryman
ngryman / code.asm
Created May 30, 2015 14:02
Strange deopt.
[deoptimize global object @ 0x30ea29d106e9]
--- FUNCTION SOURCE (optCompare) id{0,0} ---
(a, b) {
return a['foo'] === b['foo']
}
--- END ---
--- FUNCTION SOURCE (deoptCompare) id{1,0} ---
(a, b) {
var prop = 'foo'
@ngryman
ngryman / gulp+browserify.js
Created May 26, 2015 18:51
gulp + browserify
var browserify = require('browserify')
, gulp = require('gulp')
, gutil = require('gulp-util')
, mocha = require('gulp-mocha')
, source = require('vinyl-source-stream')
, watchify = require('watchify');
var b = watchify(browserify({
entries: ['./app/index.js'],
debug: true
@ngryman
ngryman / waterfall-metrics.js
Created March 21, 2015 23:57
Waterfall with promises.
function waterfall(tasks, callback) {
var firstTask = tasks.shift();
return tasks.reduce(function(prevPromise, task) {
return prevPromise.then(function() {
var args = Array.prototype.slice.call(arguments);
args.unshift(task);
return makePromise.apply(null, args);
});
}, makePromise(firstTask));
@ngryman
ngryman / without-diatrics.js
Created August 22, 2014 21:33
Strip diatrics from a string.
var withoutDiatrics = function() {
var diatrics = 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž';
var stripped = 'AAAAAAaaaaaaOOOOOOOooooooEEEEeeeeeCcDIIIIiiiiUUUUuuuuNnSsYyyZz';
return function(str) {
var len = str.length, out = '';
for (var i = 0; i < len; i++) {
var index = diatrics.indexOf(str[i]);
out += (-1 != index ? stripped[index] : str[i]);
@ngryman
ngryman / package.json
Created June 27, 2014 22:12
Scrapper for Jerem
{
"name": "grabber",
"version": "0.0.0",
"description": "Jeremy se lance dans le bis",
"main": "grabber.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
@ngryman
ngryman / art.md
Created April 7, 2014 22:46
An awesome pixel art chef d'oeuvre
@ngryman
ngryman / 0_reuse_code.js
Created January 22, 2014 19:16
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console