Skip to content

Instantly share code, notes, and snippets.

@Error601
Error601 / hipster-filler.js
Last active April 1, 2022 18:48
Hipster filler text generator.
/*!
* Hipster filler text generator.
* Inspired by (and words taken from):
* http://hipsum.co/
*
* Usage:
*
* // sentences only
* APP.utils.hipster.sentence(); // generates 1 sentence with 9, 12, or 18 words
* APP.utils.hipster.sentences(3); // generates 3 sentences
/*!
* jQuery.hasClasses plugin
*
* Check if an element has ALL classes
* or ANY of a number of classes
*
* usage:
* $('#el-id').hasClasses('foo || bar') <- has EITHER 'foo' or 'bar'
* $('#el-id').hasClasses('|| foo bar') <- has EITHER 'foo' or 'bar'
* $('#el-id').hasClasses('any: foo bar') <- has EITHER 'foo' or 'bar'
@Error601
Error601 / loadScripts.js
Last active August 29, 2015 14:16
loadScripts - run callback functions after a number of scripts have loaded (optionally into a specified element)
/*!
* The gist of this gist:
*
* This script is meant to be a *simple* way
* to ensure JavaScript dependencies are loaded
* before trying to run functions that need them.
* This is by no means an attempt to replace AMD
* modules or require.js - it's just a more lightweight
* option for loading dependencies.
*
@Error601
Error601 / basicUtils.js
Last active August 29, 2015 14:11
Some super basic JavaScript utility functions that I use a lot
/*!
* Very basic JavaScript utility functions
*/
function isObject(obj){
return Object.prototype.toString.call(obj) === '[object Object]';
}
function isFunction(func){
@Error601
Error601 / convertToText.js
Last active August 29, 2015 14:10
Heavy-handed conversion of JavaScript objects/arrays/functions/strings, etc. to text
/*!
* Convert an object to a string, for whatever reason.
* This can be useful for heavy-handed comparison
* (as in compareByText() function below),
* or printing out JavaScript objects or functions.
*
* Original source:
* http://stackoverflow.com/questions/5612787/converting-an-object-to-a-string
* ('extra' comma issue has been resolved in the code below)
*
@Error601
Error601 / extend.js
Last active August 29, 2015 14:10
jQuery's 'extend' method without the rest of jQuery
/*!
* Native JS version of jQuery's $.extend() method
* (code lifted from jQuery 1.11.1 and slightly modified)
* native JS implementations of $.isPlainObject(), $.isArray(), $.isFunction()
* https://gist.github.com/Error601/8fdffa6ff985cc374792
*/
function extend(){
var src, copyIsArray, copy, name, options, clone,
@Error601
Error601 / mergeObjects.js
Last active April 4, 2022 14:06
Merge/Extend Objects in native JS
/*!
* Replace some functionality of jQuery's $.extend() method
* with only native JavaScript. Unlike $.extend(), this
* function will ONLY merge plain objects (not arrays).
* https://gist.github.com/Error601/9a181a0b9f414b752c38
*/
function mergeObjects( /* [true ,] obj1, obj2 [, ...] */ ){
var args = arguments,