Skip to content

Instantly share code, notes, and snippets.

View MD4's full-sized avatar
πŸ”₯
πŸ”₯πŸ”₯πŸ”₯

Martin DEQUATREMARE MD4

πŸ”₯
πŸ”₯πŸ”₯πŸ”₯
View GitHub Profile
@MD4
MD4 / jojoPromiseSeries.js
Last active July 20, 2016 09:31
πŸ’ Promise.series simple implementation !
Promise.series = promises => promises
.reduce(
(promise, current) => promise.then(current),
Promise.resolve()
)
@MD4
MD4 / jojoChainableForEach.js
Last active July 20, 2016 09:36
πŸ’ Chainable forEach monkey patch !
(function(oldForEach) {
Array.prototype.forEach = function() {
oldForEach.apply(this, arguments);
return this;
};
}(Array.prototype.forEach));
[1, 2, 3]
.forEach(item => console.log(1, item))
.forEach(item => console.log(2, item))
var generateLolilolPassword = (chars, length) => Array
.apply(null, { length })
.map(() => chars[ (Math.random() * chars.length) >> 0 ])
.join('')
generateLolilolPassword('azertyuiopqsdfghjklmwxcvbnAZERTYUIOPQSDFGHJKLMWXCVBN1234567890', 10) // cw49XRZWF0
var keys = [];
document.onkeyup = function(e) {
keys.unshift(e.keyCode);
keys = keys.slice(0, 10);
if (keys.join(';') === [65, 66, 39, 37, 39, 37, 40, 38, 40, 38].join(';')) {
alert('konami!');
}
}
@MD4
MD4 / Pixi2P2.js
Created May 7, 2015 07:37
P2 to PIXI mapping utils
define(function () {
return {
factor: 100,
pixi: function (value, y) {
return value * this.factor * (y ? -1: 1);
},
p2: function (value) {
@MD4
MD4 / bonsaipiechart.js
Last active August 29, 2015 14:20
BonsaΓ―.js pie chart
var slices = [
{value: 100, color: "red"},
{value: 33, color: "green"},
{value: 41, color: "blue"},
{value: 103, color: "yellow"},
{value: 145, color: "orange"},
];
var origin = {x: 200, y: 200},
radius = 100,
@MD4
MD4 / jojoBind.js
Last active July 20, 2016 09:31
πŸ’ Function.prototype.bind() monkey patch
Function.prototype.bind = Function.prototype.bind || function (oThis) {
if (typeof this !== "function") {
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
}
var aArgs = Array.prototype.slice.call(arguments, 1),
fToBind = this,
fNOP = function () {},
fBound = function () {
return fToBind.apply(
this instanceof fNOP && oThis