Skip to content

Instantly share code, notes, and snippets.

View pseudosavant's full-sized avatar

Paul Ellis pseudosavant

View GitHub Profile
@pseudosavant
pseudosavant / script-loader.js
Created February 27, 2017 22:14
Basic script loader in JavaScript with optional callback on `load`
// 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;
@pseudosavant
pseudosavant / windows-10-post-crapware-cleanup.ps1
Last active November 16, 2022 12:59
Powershell Script to remove most of the crapware that comes with Windows 10. Run direct from web: . { iwr -useb https://gist.githubusercontent.com/pseudosavant/dd49f164c8aaf88c5505b2bbec2e3221/raw/windows-10-post-crapware-cleanup.ps1 } | iex
# 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
@pseudosavant
pseudosavant / hash-maps.js
Created June 1, 2015 20:43
True hash maps / bare objects
// 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
@pseudosavant
pseudosavant / childless.js
Created April 20, 2015 22:04
Find all decendent text and element nodes that don't have any children
// 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]);
@pseudosavant
pseudosavant / hide-dom-elements.js
Created April 8, 2015 18:26
Bookmarklet to hide DOM elements
/*
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
*/
@pseudosavant
pseudosavant / us-phone-number-regex.js
Last active August 29, 2015 14:18
Regex for validating/finding U.S. phone numbers
// 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',
@pseudosavant
pseudosavant / randomBetween.js
Created March 10, 2015 18:33
Generates a random number between two values
// Generates a random number between two values
function randomBetween(bottom, top) {
return Math.floor((top-bottom) * Math.random() + bottom);
}
@pseudosavant
pseudosavant / bound.js
Created March 10, 2015 18:32
Bounding function to ensure a value doesn't exceed a given range
// 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
@pseudosavant
pseudosavant / denseArray.js
Created March 10, 2015 18:20
Create an empty dense array
// Create an empty dense array
function denseArray(length) {
return Array.apply(null, Array(length));
}
@pseudosavant
pseudosavant / camel-case.js
Created March 3, 2015 19:44
Camel case strings with dashes in them. E.g. 'camel-case' -> 'camelCase'
// 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) {