Skip to content

Instantly share code, notes, and snippets.

View TheBox193's full-sized avatar
:shipit:
Shipping code.

Sir.Nathan (Jonathan Stassen) TheBox193

:shipit:
Shipping code.
View GitHub Profile
@TheBox193
TheBox193 / gist:edb66f9e76d47d120bee
Last active August 29, 2015 14:18
Clean Backbone
Collection1 = Backbone.Collection.extend({
initialize: function(models, options){
// bad, causes things to crash if options.that doesn’t get passed.
this.doSomethingWithThat(options.that);
}
});
// Crashes since 'that' is not set
collection1 = new Collection1();
@TheBox193
TheBox193 / Default (OSX).sublime-keymap
Last active October 23, 2015 20:19
Reveal Current File in Sidebar for Sublime [Keybinding and Tab Context Menu]
[
{ "keys": ["ctrl+shift+r"], "command": "reveal_in_side_bar"}
]
@TheBox193
TheBox193 / _.compactObject
Last active October 27, 2015 15:44
loDash.js and Underscore.js Mixins
/**
* Removes all falsy and undefined values from an object
* @param {object} o Object to be compacted
* @return {object} Compact Object
* @link http://stackoverflow.com/a/14058408/417822
*/
_.mixin({'compactObject': function(o) {
var clone = _.clone(o);
_.each(clone, function(v, k) {
@TheBox193
TheBox193 / 2_keyboard_shortcuts.md
Last active November 18, 2015 17:44
Here are some things you can do with Gists in GistBox.

Create documentation for your projects. Like so:


Most popular keyboard shortcuts within GistBox

  • Up/Down - Previous/Next Gist
  • Ctrl+e - Edit a selected Gist
  • Ctrl+s - Save Gist
/**
* Recursivly flatten a deeply nested array
* @arr Array Array with nested values
* @return Array Flattend array
*/
function flatten(arr) {
return arr.reduce(function(result, current) {
if (current instanceof Array) {
return result.concat(flatten(current));
} else {
@TheBox193
TheBox193 / redux-action.sublime-snippet
Last active July 18, 2016 21:26
Redux Action Sublime Snippets
<snippet>
<content><![CDATA[
export function ${1:action_name}(${2:arguments}) {
return {
type: ${3:type},
payload: {
${2:arguments}
}
};
}
@TheBox193
TheBox193 / templateString.js
Created August 30, 2016 19:25
A functional style curried LoDash template function, taking in config first, then string, then values. With sample using mustache template.
templateString = _.curry(
(config, string, valueObj) => _.template(string, config )(valueObj)
)
templateMustache = templateString({interpolate: /{{([\s\S]+?)}}/g});
TempString = templateMustache('hello {{user}}!', { user: 'mustache' })
console.log(TempString)
@TheBox193
TheBox193 / ask.sh
Created February 3, 2017 16:19
Bash prompt with default value
# Description:
# A simple prompt for bash that supports a default value.
# ${ask} QUESTION DEFAULT
#
# Example:
# BRANCH=$(ask "Which Branch?" "master")
function ask(){
local QUESTION=$1
local DEFAULT=$2
local ANSWER
@TheBox193
TheBox193 / redux-error-log-middleware.js
Created May 17, 2017 17:41
Redux Middleware that tracks a history of dispatched actions for debugging.
const redux_log = [];
const errorLogMiddleware = (store) => (next) => (action) => {
const type = (action && action.type) || 'unknown action';
if ( type === 'LOG_ERROR' ) {
const log_str = redux_log.join(' -> ');
const error_str = (action && action.payload && action.payload.error) || 'Redux Error';
console.error(error_str + ': ' + log_str);
} else {
@TheBox193
TheBox193 / get-and-getIn.js
Last active October 10, 2017 13:32
Immutable get helper
const get = function(state, arrayPath, defaultValue) {
if (arrayPath.length === 1) {
return state.get(arrayPath[0], defaultValue);
} else {
return state.getIn(arrayPath, defaultValue);
}
}