Skip to content

Instantly share code, notes, and snippets.

View mattbontrager's full-sized avatar

Matt Rose mattbontrager

View GitHub Profile
@mattbontrager
mattbontrager / titleCase.js
Last active August 22, 2017 22:55
Title Case a string; one for automating method calls, another for titles of articles, books, etc.
/**
* use this helper function to convert captured html element attributes
* (or whatever) to a title cased string.
*
* @date 2017-08-22
* @author mattbontrager
* @param {String} string [the string to be converted to CamelCase]
* @return {String} [the CamelCased string]
*/
function titleCaseWithSymbols(string) {
@mattbontrager
mattbontrager / flatten-arbitrarily-nested-arrays.js
Last active June 18, 2018 22:30
Flatten arbitrarily nested arrays.
function flatten(arr) {
return arr.reduce((flat, toFlatten) => {
return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten);
}, []);
}
// usage:
flatten([[1, 2, 3], [4, 5]]); // [1, 2, 3, 4, 5]
flatten([[[1, [1.1]], 2, 3], [4, 5]]); // [1, 1.1, 2, 3, 4, 5]
@mattbontrager
mattbontrager / fetch-and-track-all-remote-branches.sh
Created October 21, 2016 20:54
Fetch and track all git branches
for remote in `git branch -r`; do git branch --track ${remote#origin/} $remote; done
git fetch --all
git pull --all
# credit to Wookie88 and Shadowfax @ http://stackoverflow.com/questions/10312521/how-to-fetch-all-git-branches
# saving this for quick reference and easy insertion.
@mattbontrager
mattbontrager / git-commit.md
Created February 17, 2017 21:37 — forked from batjaa/git-commit.md
Git Commit Messages

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
  • 🎉 :tada: Initial commit
[user]
name=namegoeshere
email=emailgoeshere
[credential]
# helper = osxkeychain
[color]
ui=auto
interactive=auto
[color "branch"]
current=yellow reverse
@mattbontrager
mattbontrager / example-ajax-handler-with-promises.js
Last active March 29, 2017 20:11
Custom Ajax handler (with jQuery Promises)
var App = (function() {
/**
* a development flag to easily silence console.logging
* @type {Boolean}
*/
var development = true,
self;
return {
init: function init() {
@mattbontrager
mattbontrager / .jscsrc
Last active August 29, 2017 23:05
my jscsrc template
{
"requireCurlyBraces": [
"if",
"else",
"for",
"while",
"do",
"try",
"catch"
],
@mattbontrager
mattbontrager / gist:5fec210b2672ddbadd95f92dafdda922
Last active August 22, 2017 17:35 — forked from christofluethi/gist:646ae60d797a46a706a5
Convert m4a to mp3 on OS X command line using ffmpeg
brew update
brew link yasm
brew link x264
brew link lame
brew link xvid
brew install ffmpeg
ffmpeg wiki:
https://trac.ffmpeg.org/wiki/Encode/MP3
@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
@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",