Skip to content

Instantly share code, notes, and snippets.

View mattbontrager's full-sized avatar

Matt Rose mattbontrager

View GitHub Profile
@mattbontrager
mattbontrager / gist:3f366c327346cc35fa32e946c7cd8c90
Created August 30, 2017 18:36 — forked from rxaviers/gist:7360908
Complete list of github markdown emoji markup

People

:bowtie: :bowtie: 😄 :smile: 😆 :laughing:
😊 :blush: 😃 :smiley: ☺️ :relaxed:
😏 :smirk: 😍 :heart_eyes: 😘 :kissing_heart:
😚 :kissing_closed_eyes: 😳 :flushed: 😌 :relieved:
😆 :satisfied: 😁 :grin: 😉 :wink:
😜 :stuck_out_tongue_winking_eye: 😝 :stuck_out_tongue_closed_eyes: 😀 :grinning:
😗 :kissing: 😙 :kissing_smiling_eyes: 😛 :stuck_out_tongue:
@mattbontrager
mattbontrager / jquery.ba-whenthen.js
Created October 18, 2017 20:14 — forked from cowboy/jquery.ba-whenthen.js
jQuery's "when" and "then" all rolled up together.
/*!
* jQuery whenthen - v0.2 - 3/12/2011
* http://benalman.com/
*
* Copyright (c) 2011 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
@mattbontrager
mattbontrager / recursive-find-and-replace-on-mac.sh
Created January 29, 2018 22:15
Recursively find and replace a word or phrase from the command line on a Mac.
grep -rli 'old word or phrase' * | xargs -I@ sed -i '' 's/old word or phrase in regex/new word or phrase/g' @
var uk = createFuzzyScorer('United Kingdom');
var us = createFuzzyScorer('United States');
console.log([
uk('United') > uk('uk'),
uk('nited') > uk('ingdom'),
uk('united kingdom') > uk('united kingdo'),
uk('united dom') < uk('united kin'),
uk('knited k') > uk('dom'),
uk('_united_') < uk('united'),
@mattbontrager
mattbontrager / unique-in-array.js
Last active June 12, 2018 21:14
Easily store unique values from an array with multiples of those values.
var distinctValues = ['one', 'two', 'three', 'four', 'five', 'two', 'one', 'three', 'three', 'four'].filter((val, idx, me) => {
return me.indexOf(val) === idx;
});
console.log(distinctValues);
// ['one', 'two', 'three', 'four', 'five'];
@mattbontrager
mattbontrager / load-script-in-promise.js
Created June 12, 2018 21:09
Promise based load script
const loadScript = src => {
return new Promise((resolve, reject) => {
const script = document.createElement('script');
script.async = true;
script.src = src;
script.onload = resolve;
scrip.onerror = reject;
document.head.appendChild(script);
});
};
@mattbontrager
mattbontrager / frequency-count.js
Last active June 14, 2018 00:57
Count the frequency of a word (or pretty much anything).
var text = `To Sherlock Holmes she is always the woman. I have seldom heard him mention her under any other name. In his eyes she eclipses and predominates the whole of her sex. It was not that he felt any emotion akin to love for Irene Adler. All emotions, and that one particularly, were abhorrent to his cold, precise but admirably balanced mind. He was, I take it, the most perfect reasoning and observing machine that the world has seen, but as a lover he would have placed himself in a false position. He never spoke of the softer passions, save with a gibe and a sneer. They were admirable things for the observer—excellent for drawing the veil from men’s motives and actions. But for the trained reasoner to admit such intrusions into his own delicate and finely adjusted temperament was to introduce a distracting factor which might throw a doubt upon all his mental results. Grit in a sensitive instrument, or a crack in one of his own high-power lenses, would not be more disturbing than a strong emotion in a nat
@mattbontrager
mattbontrager / array-elements-in-common.js
Last active March 3, 2020 20:57
Find common elements between two arrays.
Array.prototype.same = function(arr2) {
let same = new Set();
let arr1 = this;
arr1.forEach(item => !!arr2.includes(item) && same.add(item));
arr2.forEach(item => !!arr1.includes(item) && same.add(item));
return Array.from(same);
};
@mattbontrager
mattbontrager / array-elements-difference.js
Last active March 3, 2020 20:55
Find different elements between two arrays.
Array.prototype.diff = function(arr2) {
let arr1 = this;
let diff = new Set();
arr1.forEach(item => !arr2.includes(item) && diff.add(item));
arr2.forEach(item => !arr1.includes(item) && diff.add(item));
return Array.from(diff);
};
@mattbontrager
mattbontrager / words-of-strings-in-common.js
Last active June 15, 2018 22:18
Find the words in common between two strings.
String.prototype.same = function(str2) {
const arr1 = this.split(/\W/);
const arr2 = str2.split(/\W/);
return arr1.inCommon(arr2).join(' ');
};
// requires use of this
// https://gist.github.com/mattbontrager/2a9b71c7110ab61f9ef948208646c85f