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
<?php | |
/** | |
* Shuffles an array using mt_rand() instead of rand(). | |
* CAUTION: Unlike shuffle(), returns a new array, leaving the source untouched. It's better that way. | |
* CAUTION: Won't work with associative arrays. Who would shuffle an associative array anyways? | |
* | |
* @param array $deck The index-based array to be shuffled. | |
* @return array A new array containing exactly the same elements in a random order. | |
* | |
* @see http://stackoverflow.com/questions/5694319/how-random-is-phps-shuffle-function |
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
// Cartesian product of arrays | |
// @takes N arrays -- arguments *must* be arrays | |
// @returns an array of X arrays of N elements, X being the product of the input arrays' lengths. | |
function cartesianProduct(...arrays) { | |
function _inner(...args) { | |
if (arguments.length > 1) { | |
let arr2 = args.pop(); // arr of arrs of elems | |
let arr1 = args.pop(); // arr of elems | |
return _inner(...args, |
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
//////// | |
// CustomEase for GSAP (ES5) | |
//////// | |
// Written using code from greensock/GreenSock-JS : | |
// https://github.com/greensock/GreenSock-JS/blob/master/src/uncompressed/easing/EasePack.js | |
var _gsScope = (typeof(module) !== "undefined" && module.exports && typeof(global) !== "undefined") ? global : this || window; //helps ensure compatibility with AMD/RequireJS and CommonJS/Node | |
var gs = (_gsScope.GreenSockGlobals || _gsScope).com.greensock; | |
var CustomEase = gs._class("easing.CustomEase", function(func) { |
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
function drawRoundedRect(context, x, y, width, height, borderRadius) { | |
if (!borderRadius) { | |
context.rect(x, y, width, height); | |
} else { | |
var widthMinusRad = width - borderRadius; | |
var heightMinusRad = height - borderRadius; | |
context.translate(x, y); | |
context.arc(borderRadius, borderRadius, borderRadius, Math.PI, Math.PI * 1.5); | |
context.lineTo(widthMinusRad, 0); | |
context.arc(widthMinusRad, borderRadius, borderRadius, Math.PI * 1.5, Math.PI * 2); |
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
var Handlebars = require('handlebars'); | |
// with `ctx` = [a, b, c, d, e, f, g, h] and `count` = 3 | |
// will iterate over [[a, b, c], [d, e, f], [g, h]] | |
Handlebars.registerHelper('each-paginate', function(context, opts) { | |
// similar to Python's range | |
var range = n => Array.from(new Array(n).keys()); | |
// items per page and page count - defaults to a single page with all the items | |
var perPage = opts.hash.perPage || context.length; |