Skip to content

Instantly share code, notes, and snippets.

@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,
@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 / 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 / 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 / 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.
*
/*!
* 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 / 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
@Error601
Error601 / jquery.dataAttr.js
Last active August 12, 2016 17:02
Reconcile jQuery's .data() object with an element's [data-] attributes
/*!
* Get or set [data-] attributes and
* keep jQuery's .data object in sync
* with those attributes with special
* handling for non-string data and
* proper retrieval of functions stored
* in jQuery's .data object.
*/
@Error601
Error601 / firstDefined.js
Created May 21, 2015 22:06
Return first defined value from argument list.
/*!
* Return the first defined value from argument
* list. Vars must be declared before passing
* to the function - set equal to self to catch
* any existing value for that var name. Useful
* for fetching values from an outer scope that
* may or may not be defined yet, while providing
* a fallback of a known (explicitly) defined value.
*
* // vars declared and assigned to self
@Error601
Error601 / locash.js
Last active August 29, 2015 14:21
Useful helper functions inspired by (or lifted from) other libraries.
/*!
* Global general-purpose JavaScript convenience
* utlity helper functions, because the world
* needs yet ANOTHER JavaScript library for
* things that should just be native JavaScript
* methods in the first place!
*
* Some of these functions are taken straight from
* other libraries and transplanted here - thus
* the name 'locash' - a nod to lodash/underscore