Instantly share code, notes, and snippets.

View mimic.js
function mimic(obj, opt_filter, opt_maxPathLength) {
function recurse(obj, ancestors, path) {
ancestors = ancestors.concat([obj]);
if (path.length > opt_maxPathLength) {
var e = new Error('Maximum path length exceeded.');
e.path = path;
e.root = obj;
throw e;
}
View swapProps.js
/**
* Swaps the specified properties between the target object and the source object.
* @param {*} target
* Target object from which the specified properties will be swapped.
* @param {*} source
* Source object from which the specified properties will be swapped.
* @param {Array<number|string>} keys
* Array of keys for the properties that should be swapped between source and
* target.
* @param {boolean=} [opt_dontDelete=false]
View getVideoImages.js
/**
* Gets one or more images from a video at the given times. Works for MP4s and
* at times MKVs.
* @param {string} path
* URL path to the video.
* @param {Array.<number|Function>|number|Function} times
* If a function it will be passed the duration and the return value will be
* used as the amount of seconds at which to grab the image. If a
* non-negative number this will be used as the amount of seconds at which
* to grab the image. If a negative number this will be used as the amount
View 4-corner-css3-gradient.html
<html>
<head>
<style>
.test {
background-image:
linear-gradient(315deg, hsl(0, 100%, 50%), rgba(255,255,255,0) 50%),
linear-gradient(45deg, hsl(90, 100%, 50%), rgba(255,255,255,0) 50%),
linear-gradient(135deg, hsl(180, 100%, 50%), rgba(255,255,255,0) 50%),
linear-gradient(225deg, hsl(270, 100%, 50%), rgba(255,255,255,0) 50%);
background-color: #808080;
View Color.js
(function (global, Math, names, namedColors, strColors) {
(function (factory) {
if (typeof define === "function" && define.amd) {
define(["exports"], factory);
}
else if (typeof exports !== "undefined") {
factory(exports);
}
else {
var mod = { exports: {} };
View sameSign.js
function sameSign() {
for (
var args = arguments, b = args[0], mustBeNeg = b === b ? (b < 0 || 1 / b < 0) : NaN, i = args.length;
b = args[--i], i && mustBeNeg === (b === b ? (b < 0 || 1 / b < 0) : NaN);
);
return !i;
}
//\\
sameSign(4, 0); // -> true
View copySign.js
function copySign(a, b) {
return (a < 0 || 1 / a < 0) === (b < 0 || 1 / b < 0) ? a : -a;
}
//\\
copySign(4, -0); // -> -4
//\\
copySign(-8, -0); // -> -8
//\\
copySign(0, -1); // -> -0
View array.js
// Creates an array with the specified length and filling it with the specified value.
function array(length, opt_filler, opt_callFiller) {
opt_callFiller = !!opt_callFiller && 'function' === typeof opt_filler;
for (var result = Array(length), i = 0; i < length; i++) {
result[i] = opt_callFiller ? opt_filler(result[i], i, result) : opt_filler;
}
return result;
}
View integer functions.js
// Creates the following functions: int8(), uint8(), int16(), uint16(), int32(), and uint32()
// The int functions convert a number into a signed integer that can be represented by the number of bits specified by the function name (int8() returns 8-bit signed integers).
// The uint functions convert a number into an unsigned integer that can be represented by the number of bits specified by the function name (uint8() returns 8-bit unsigned integers).
eval('uUi32I32uUi16I16uUi8I8'.replace(/(u?)([UI]i?)(\d\d?)/g, 'var $1int$3;(function(a){$1int$3=function(x){return a[0]=x,a[0]}})(new $2nt$3Array(1));'));
View fround.js
// Not available in IE.
//
var fround;
(function (array) {
fround = function(x) {
return array[0] = x, array[0];
};
})(new Float32Array(1));
//\\