Skip to content

Instantly share code, notes, and snippets.

function myPromise(fn){
let done = false;
let next = [];
fn(() => {
done = true;
while (next.length > 0) next.pop()();
});
return {
then: fn => {
@mattcodez
mattcodez / thinArrow.js
Last active March 14, 2016 15:26
Proposal for temporary scope variables
//Proposal for temporary scope variables
let result = something.crazy.long.bar ? something.crazy.long.bar() : something.crazy.long.other();
//with() - Not 'strict' compliant
with (something.crazy.long){
result = bar ? bar() : other();
}
//fat arrow function
@mattcodez
mattcodez / mrdbg-es5.js
Created February 3, 2016 19:13
Mapreduce Debug (ES6 & ES5)
//Transpiled from Babel
"use strict";
function MRDbg() {
for (var _len = arguments.length, txt = Array(_len), _key = 0; _key < _len; _key++) {
txt[_key] = arguments[_key];
}
return function (prev, cur, i, arr) {
if (i === 1) {
//Use ES6 modules for your controllers in SailsJS
//requires https://github.com/artificialio/sails-hook-babel
export default {
controllerAction1(req, res) {
//...
},
controllerAction2(req, res) {
//...
@mattcodez
mattcodez / pixel.js
Created November 26, 2014 06:51
Simple function to write a single pixel to a canvas element
//Copied from http://stackoverflow.com/q/4899799/119909
function pixel(x,y){
d[0] = 255;//r
d[1] = 0;//g
d[2] = 0;//b
d[3] = 255;//a
ctx.putImageData( id, x, y );
}
var ctx = document.getElementById('c').getContext('2d');
var id = ctx.createImageData(1,1);