Type | Maximum length | Size (bytes)
-----------+----------------+------------------
TINYTEXT | 255 | (2^8−1)
TEXT | 65,535 | (2^16−1) = 64 KiB
MEDIUMTEXT | 16,777,215 | (2^24−1) = 16 MiB
LONGTEXT | 4,294,967,295 | (2^32−1) = 4 GiB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get a random floating point number between `min` and `max`. | |
* | |
* @param {number} min - min number | |
* @param {number} max - max number | |
* @return {number} a random floating point number | |
*/ | |
function getRandomFloat(min, max) { | |
return Math.random() * (max - min) + min; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/ | |
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating | |
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel | |
// MIT license | |
(function() { | |
var lastTime = 0; | |
var vendors = ['ms', 'moz', 'webkit', 'o']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The polling function | |
function poll(fn, callback, timeout, interval) { | |
var endTime = Number(new Date()) + (timeout || 2000); | |
interval = interval || 100; | |
(function p() { | |
// If the condition is met, we're done! | |
if (fn()) { | |
callback(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Sum two big numbers given as strings. | |
* | |
* @param {string} a | |
* @param {string} b | |
* @return {string} | |
*/ | |
function sumStrings(a, b) { | |
var zrx = /^0+/; // remove leading zeros | |
a = a.replace(zrx, '').split('').reverse(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
module.exports = function CustomError(message, extra) { | |
Error.captureStackTrace(this, this.constructor); | |
this.name = this.constructor.name; | |
this.message = message; | |
this.extra = extra; | |
}; | |
require('util').inherits(module.exports, Error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// instead of using `expect(object).to.exist`, assert things | |
// through `.to.be.a(type)` which make failures more informative | |
expect(result).to.be.an('object') | |
.that.includes({ | |
foo: 'bar', | |
baz: 'quux' | |
}); | |
// to assert property value types i.e. date: | |
expect(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const array = []; // array to iterate | |
const promise = array.reduce((p, entry) => { | |
p.then(() => { | |
return new Promise((resolve, reject) => {...}); | |
}); | |
}, Promise.resolve()); | |
promise | |
.then(() => console.log('done!')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const chai = require('chai'); | |
// globalize sinon | |
global.sinon = require('sinon'); | |
// initialize chai plugins | |
chai.use(require('sinon-chai')); | |
chai.use(require('chai-as-promised')); | |
chai.use(require('chai-datetime')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Executes a given `fn` at the beginning of the next second. | |
* @param {function} fn – a function to execute | |
* @return {number} setTimeout's resulting timeout id, to give ability to cancel execution | |
*/ | |
function nextSecond(fn) { | |
const time = (new Date()).getTime(); | |
return setTimeout(fn, (Math.ceil(time / 1000) * 1000) - time); | |
} |
OlderNewer