Skip to content

Instantly share code, notes, and snippets.

@Error601
Error601 / css-animated-loader.html
Created January 31, 2017 17:19
Pure CSS animated loading widget
<style>
.loading-animation {
position: fixed;
top: 50%;
left: 50%;
margin-left: -50px;
width: 100px;
height: 80px;
text-align: center;
background-color: #fff;
@Error601
Error601 / add-aliases.sh
Last active April 7, 2016 20:44
Setup a folder to contain individual alias files that can be easily created.
#!/bin/bash
[[ ! -d ~/.bash_alias ]] && mkdir -p ~/.bash_alias
# path to individual alias files
APATH=~/.bash_alias
ALIASPATH=$APATH
AFILES=($APATH/*.sh)
ALIASFILES=$AFILES
@Error601
Error601 / spawn.js
Last active February 24, 2016 23:40
Spawn DOM elements, with *optional* jQuery support.
/*!
* DOM element spawner with *optional* jQuery functionality
*
* EXAMPLES:
* var p1 = spawn('p|id:p1', 'Text for paragraph 1.');
* var div2 = spawn('div|class=div2', ['Text for div2.', p1]) // inserts text and puts p1 inside div2
* var ul1 = spawn('ul', [['li', 'Content for <li> 1.'], ['li', 'Content for the next <li>.']]);
* div2.appendChild(ul1); // add ul1 to div2
*/
@Error601
Error601 / pattern-matching.sh
Created December 16, 2015 03:50
Bash pattern matching samples
#!/bin/bash
FILE=/home/user/src/prog.c
echo ${FILE#/*/} # ==> user/src/prog.c
echo ${FILE##/*/} # ==> prog.c
echo ${FILE%/*} # ==> /home/user/src
echo ${FILE%%/*} # ==> nil
echo ${FILE%.c} # ==> /home/user/src/prog
# All this from the excellent book: "A Practical Guide to Linux Commands, Editors, and
@Error601
Error601 / getFilePath.sh
Last active December 18, 2015 18:06
Recursively search parent folders for a specific file or folder.
#!/bin/bash
# The function below will recursively search parent folders
# from the current folder (or specified starting folder)
# until it finds a matching file or folder, then returns
# the full absolute path to that file or folder.
#
# Run this script where it's stored or call the 'getFilePath' function
# if included as a source in another script.
#
@Error601
Error601 / jquery.spawn.js
Last active January 28, 2016 20:06
Generate HTML elements, returning a jQuery object for the outermost element
/*!
* Create HTML elements from a config object
* https://gist.github.com/Error601/7a86fa6e34fbc98b31a6
*/
if (typeof jQuery == 'undefined') {
throw new Error('jQuery is required');
}
(function($, undefined){
@Error601
Error601 / camelDash.js
Last active August 29, 2015 14:22
Robust conversion between camelCase and hyph-en-ated text.
/*!
* Robust string conversion between
* hyphenated 'text-string' and
* camelCase 'textString'.
* Allows use of '_' (underscore),
* ' ' (space), '.' (period), and
* '-' (hyphen) as word delimiters,
* or an array of words.
*/
@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
@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 / 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.
*/