Skip to content

Instantly share code, notes, and snippets.

Avatar

Matt Bontrager mattbontrager

View GitHub Profile
@mattbontrager
mattbontrager / azimuth.js
Created Oct 8, 2019
Calculate heading from progression of latitude and longitude.
View azimuth.js
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 Jun 19, 2019
Current zshell config
View .zshrc
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 Jun 19, 2019
My current tmux configuration
View .tmux.conf
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 Jun 19, 2019
My current vimrc
View .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 Jul 5, 2018 — forked from evdokimovm/index.js
JavaScript Convert Radians to Degrees and Degrees to Radians
View index.js
// 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 Jul 17, 2018
Processing asynchronous operations (deferreds) in sequence, in a loop with jQuery.
View deferreds-in-a-loop-with-jquery.js
/* * /
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 Jun 15, 2018
Asynchronously load other JavaScript files.
View async-load-script.js
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 Jun 15, 2018
Find different words between to strings.
View words-of-strings-not-in-common.js
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 Jun 15, 2018
Find the words in common between two strings.
View words-of-strings-in-common.js
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 Mar 3, 2020
Find different elements between two arrays.
View array-elements-difference.js
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);
};