Skip to content

Instantly share code, notes, and snippets.

@geraldfullam
geraldfullam / Sort by, then by.markdown
Last active January 30, 2020 19:59
Sort by, then by
@geraldfullam
geraldfullam / JS Get Query Param Value by Name
Created January 7, 2015 04:07
Get query parameter values by key name from window.location.search string
/* Based on: http://stackoverflow.com/a/901144/2502532 */
var getParam = function(key) {
key = key.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var val = window.location.search.match(new RegExp('[\\?&]' + key + '=([^&#]*)'));
return val === null ? '' : decodeURIComponent(val[1].replace(/\+/g, ' '));
};
console.log(getParam('foo'));
@geraldfullam
geraldfullam / window.location.query
Created January 6, 2015 21:41
JavaScript: Global access to query string variables as a map
// Source: http://stackoverflow.com/a/13455920/2502532
// -------------------------------------------------------------------
// Add prototype for 'window.location.query([source])' which contain an object
// of querystring keys and their values
// -------------------------------------------------------------------
if(!window.location.query) {
window.location.query = function(source){
var map = {};
source = source || this.search;
@geraldfullam
geraldfullam / RTE RegEx Replacements
Created October 31, 2014 18:24
Common RegEx Replacements for Rich Text Editors
content = content
// Replace hypen, if between number, with en-dash
.replace(/(\d+)-(\d+)/ig, '$1–$2')
// Replace hypen, if between spaces, with em-dash
.replace(/( +)-+( +)/ig, '$1—$2')
// Replace smart double quotes with straight double quotes
.replace(/“|”|„|‟|″|‶/ig, '"')