Skip to content

Instantly share code, notes, and snippets.

View mattbontrager's full-sized avatar

Matt Rose mattbontrager

View GitHub Profile
@mattbontrager
mattbontrager / azimuth.js
Created October 8, 2019 15:48
Calculate heading from progression of latitude and longitude.
class Azimuth {
constructor() {
this.watchId = null;
this.latitude = null;
this.longitude = null;
this.latLon = (lat, lon) => {
this.latitude = lat;
this.longitude = lon;
};
@mattbontrager
mattbontrager / .zshrc
Created June 19, 2019 17:55
Current zshell config
export TERM=xterm-256color
# If you come from bash you might have to change your $PATH.
export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH="/Users/pbontrag/.oh-my-zsh"
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
@mattbontrager
mattbontrager / .tmux.conf
Created June 19, 2019 17:54
My current tmux configuration
set -g default-terminal "screen-256color"
# remap prefix to Control + a
set -g prefix C-a
# bind 'C-a C-a' to type 'C-a'
bind C-a send-prefix
unbind C-b
set-option -g default-shell /usr/local/bin/zsh
@mattbontrager
mattbontrager / .vimrc
Created June 19, 2019 17:53
My current vimrc
set t_Co=256
set termguicolors
set nocompatible" be iMproved, required
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'mattn/emmet-vim'
@mattbontrager
mattbontrager / index.js
Created July 5, 2018 19:24 — forked from evdokimovm/index.js
JavaScript Convert Radians to Degrees and Degrees to Radians
// Convert from degrees to radians.
Math.radians = function(degrees) {
return degrees * Math.PI / 180;
}
Math.radians(90); // 1.5707963267948966
// Convert from radians to degrees.
Math.degrees = function(radians) {
return radians * 180 / Math.PI;
}
@mattbontrager
mattbontrager / deferreds-in-a-loop-with-jquery.js
Last active July 17, 2018 20:18
Processing asynchronous operations (deferreds) in sequence, in a loop with jQuery.
/* * /
Due to target constraints, it had to be done with jQuery (no new hotness allowed).
It took me some time to figure this out so, I thought I'd store it here for reference.
/* */
var doSomeDeferredStuff = function doSomeDeferredStuff(dvcs) {
console.log('in doSomeDeferredStuff');
var deferreds = [];
$.each(dvcs, function(i, dvc) {
@mattbontrager
mattbontrager / async-load-script.js
Created June 15, 2018 22:58
Asynchronously load other JavaScript files.
const loadScript = src => {
return new Promise((resolve, reject) => {
const script = document.createElement('script');
script.async = true;
script.src = src;
script.onload = resolve;
script.onerror = reject;
document.body.appendChild(script);
});
};
@mattbontrager
mattbontrager / words-of-strings-not-in-common.js
Last active June 15, 2018 22:18
Find different words between to strings.
String.prototype.different = function(str2) {
const arr1 = this.split(/\W/);
const arr2 = str2.split(/\W/);
return arr1.diff(arr2).join(' ');
};
// requires this as well
// https://gist.github.com/mattbontrager/7500cc5696ff4efe249f2ac0adbeb8ec
@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
@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);
};