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
// Loads an external js file and optionally calls a callback on completion | |
function loadScript(url, callback) { | |
var script = document.createElement('script'); | |
document.body.appendChild(script); | |
if (typeof callback === 'function') { | |
script.addEventListener('load', callback, false); | |
} | |
script.src = url; | |
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
# Sometimes | |
#Get-AppxPackage *bingweather* | Remove-AppxPackage | |
#Get-AppxPackage *bingnews* | Remove-AppxPackage | |
#Get-AppxPackage *bingfinance* | Remove-AppxPackage | |
#Get-AppxPackage *bingsports* | Remove-AppxPackage | |
#Get-AppxPackage *MSPaint* | Remove-AppxPackage | |
#Get-AppxPackage *people* | Remove-AppxPackage | |
#Get-AppxPackage *soundrecorder* | Remove-AppxPackage |
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
// See: http://ryanmorr.com/true-hash-maps-in-javascript/ | |
// This creates a 'bare object' that can be used as a true hash map. | |
// Safe to use `for...in` because it doesn't inherit `Object.prototype` | |
var map = Object.create(null); | |
map instanceof Object; // false | |
Object.prototype.isPrototypeOf(map); // false | |
Object.getPrototypeOf(map); // null |
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
// Find all decendent text and element nodes that don't have any children | |
function findChildless(currentNode) { | |
var nodes = []; | |
// Recursion | |
// If currentNode has children | |
if (currentNode.hasChildNodes()) { | |
// Run `findChildless` on all children | |
for (var i=0; i < currentNode.childNodes.length; i++) { | |
var results = findChildless(currentNode.childNodes[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
/* | |
Bookmarklet to hide DOM elements | |
Left-click: hide element | |
Right-click: undo last hide | |
Middle-click: stop altering document | |
JSBin: http://jsbin.com/nimilu/ | |
Convert to a bookmarklet here: http://ted.mielczarek.org/code/mozilla/bookmarklet.html | |
*/ |
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
// Regex for validating/finding U.S. phone numbers | |
// http://jsbin.com/hupupopiya/ | |
// http://regexr.com/3anot | |
var phoneRe = /^1?[\W\D]{0,2}([2-9]\d{2})[\W\D]{0,2}([2-9](?:1[02-9]|[02-9]\d))[\W\D]?(\d{4})$/; | |
var validNumbers = [ | |
'760-807-8178', | |
'17608078178', | |
'(760)807-8178', |
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
// Generates a random number between two values | |
function randomBetween(bottom, top) { | |
return Math.floor((top-bottom) * Math.random() + bottom); | |
} |
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
// Bounding function to ensure a value doesn't exceed a given range | |
function bound(bottom, top, v) { | |
return Math.max(bottom, Math.min(top, v)); | |
} | |
// Examples: | |
bound(0,1,2); // 1 | |
bound(0,3,2); // 2 | |
bound(0,1,-2); // 0 | |
bound(-3,1,-2); // -2 |
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
// Create an empty dense array | |
function denseArray(length) { | |
return Array.apply(null, Array(length)); | |
} |
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
// Camel case strings with dashes in them. E.g. 'camel-case' -> 'camelCase' | |
function camelCase(s) { | |
function upperCaseFirst(s) { | |
return s[0].toUpperCase() + s.slice(1); | |
} | |
var separator = '-'; | |
// Return early if no additional camel casing is needed | |
if (s.indexOf(separator) === -1) { |