Skip to content

Instantly share code, notes, and snippets.

View mattbontrager's full-sized avatar

Matt Rose mattbontrager

View GitHub Profile
@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 / 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 / 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 / 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'];
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 / 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' @
@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 / 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 / Preferences.sublime-settings
Created August 29, 2017 22:55
My user settings for Sublime Text 3 text editor.
{
"always_show_minimap_viewport": false,
"auto_complete_triggers":
[
{
"characters": "<",
"selector": "text.html"
},
{
"characters": "bs3",
@mattbontrager
mattbontrager / .gitmessage
Last active March 21, 2018 17:11
A custom git message template
## Git Commit Messages
# - Use the Present Tense ("Add feature" not "Added feature").
# - Use the Imperative Mood ("Move cursor to..." not "Moves cursor to...").
# - Limit the subject line to 50 characters
# - Wrap the body at 72 characters
# - Reference issues and pull requests
# - When only changing documentation, include `[ci skip]` in the commit description
# - Be creative with emojies