Skip to content

Instantly share code, notes, and snippets.

View mikegwhit's full-sized avatar
🎯
Focusing

Mike Whit mikegwhit

🎯
Focusing
View GitHub Profile
@mikegwhit
mikegwhit / gist:895dfd7a551d804e5f7c
Last active August 29, 2015 14:15
performs a JSON search using regex... goal is to return the associated keys, values, and parent key chain for any search result
JSON.search=function(o,str){
oobj = o;
o = JSON.stringify(o);
idx = o.search(str)
if ( idx == -1 )
return [];
ocpy = o;
starts = [idx];
while ( idx != -1 ) {
ocpy = ocpy.substr(idx+1);
@mikegwhit
mikegwhit / HashRouter.class.js
Last active February 11, 2017 00:42
Hash Router
/**
* Simple access to the Hashbang with listeners, filters and query string
* deconstruction.
*/
class HashRouter {
constructor() {
if (HashRouter.instance) {
return HashRouter.instance;
}
this.currentHash = HashRouter.toObject(window.location.hash);
/**
* Renders a model onto a template literal string. Renders the rendered text.
*/
function render(model, templateLiteral) {
// declare the vars in function scope needed for our replacement
for (let key in model) {
let value;
if (typeof model[key] == 'string') {
value = '"' + model[key] + '"';
} else {
/**
* Renders a model onto a template literal string. Renders the rendered text.
*/
function render(model, templateLiteral) {
// declare the vars in function scope needed for our replacement
for (let key in model) {
let value;
if (typeof model[key] == 'string') {
value = '"' + model[key] + '"';
} else {
@mikegwhit
mikegwhit / levenstein.js
Last active May 15, 2019 21:48
Levenshtein Distance
/**
* @license MIT
* Copyright 2019 @andrei-m
*
* See original which this code is based on:
* https://gist.github.com/andrei-m/982927/0efdf215b00e5d34c90fdc354639f87ddc3bd0a5
*
* Basic modifications include using ES6 `const` and `let`. Additionally
* condenses if statement. Changes are somewhat trivial overall :)
@mikegwhit
mikegwhit / scroll.class.js
Last active October 10, 2022 16:26
A class for wrapping window.scrollTo with a callback and a scroll queue.
/**
* ScrollOptions
*/
class ScrollOptions {
constructor(obj) {
/**
* @type {Function} Function called when a scroll in occurs.
*/
this.scrollIn = function() {};