This file contains hidden or 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 arr = { | |
| max: function(array) { | |
| return Math.max.apply(null, array); | |
| }, | |
| min: function(array) { | |
| return Math.min.apply(null, array); | |
| }, | |
| range: function(array) { |
This file contains hidden or 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
| // call.js | |
| // chainable setTimeout and setInterval JavaScript wrapper | |
| // | |
| // By Daniel Hug: https://gist.github.com/Daniel-Hug/9062765 | |
| // MIT license: http://hug.mit-license.org/ | |
| // | |
| // use: | |
| // var timer = call(fn, scope, args).after(1000).start(); | |
| // var interval = call(fn, scope, args).every(1000).fire().start(); | |
| // timer.stop(); |
This file contains hidden or 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.prototype.bind=(function(){}).bind||function(b){if(typeof this!=="function"){throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");}function c(){}var a=[].slice,f=a.call(arguments,1),e=this,d=function(){return e.apply(this instanceof c?this:b||window,f.concat(a.call(arguments)));};c.prototype=this.prototype;d.prototype=new c();return d;}; |
This file contains hidden or 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
| // Check if rectangle a contains rectangle b | |
| // Each object (a and b) should have 2 properties to represent the | |
| // top-left corner (x1, y1) and 2 for the bottom-right corner (x2, y2). | |
| function contains(a, b) { | |
| return !( | |
| b.x1 < a.x1 || | |
| b.y1 < a.y1 || | |
| b.x2 > a.x2 || | |
| b.y2 > a.y2 | |
| ); |
This file contains hidden or 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
| /** | |
| * A "deeper" indented text effect with the :before and :after pseudo-elements. | |
| */ | |
| html, body { | |
| height: 100%; | |
| } | |
| body { | |
| margin: 0; |
This file contains hidden or 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 the text nodes which are descendants of the passed parent | |
| function getTextNodes(parent){ | |
| var all = []; | |
| for (parent = parent.firstChild; parent; parent = parent.nextSibling) { | |
| if (['SCRIPT','STYLE'].indexOf(parent.tagName) >= 0) continue; | |
| if (parent.nodeType === Node.TEXT_NODE) all.push(parent); | |
| else all = all.concat(getTextNodes(parent)); | |
| } | |
| return all; | |
| } |
This file contains hidden or 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
| // Replace tag name but keep element contents | |
| function changeTag(el, newTagName, keepAttributes) { | |
| var newEl = document.createElement(newTagName); | |
| // Copy the children | |
| while (el.firstChild) { | |
| newEl.appendChild(el.firstChild); // *Moves* the child | |
| } | |
| // Copy the attributes |
This file contains hidden or 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
| // probability that the event with the passed probability will NOT occur | |
| function complement(p) { | |
| return 1 - p; | |
| } | |
| // probability that a and b will happen when neither outcome | |
| // is affected by the other (accepts 1 or more arguments) | |
| function intersectionOfIndependentEvents(a, b) { | |
| var ret = a; | |
| for (var i = 1; i < arguments.length; i++) { |
This file contains hidden or 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 nearest parent element matching selector | |
| var closest = (function() { | |
| var el = HTMLElement.prototype; | |
| var matches = el.matches || el.webkitMatchesSelector || el.mozMatchesSelector || el.msMatchesSelector; | |
| return function closest(el, selector) { | |
| return matches.call(el, selector) ? el : closest(el.parentElement, selector); | |
| }; | |
| })(); |
This file contains hidden or 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
| /* | |
| * Pure CSS aspect ratio with no spacer images or js! :) | |
| */ | |
| body { | |
| width: 36%; | |
| margin: 8px auto; | |
| } | |
| div.stretchy-wrapper { |
NewerOlder