Skip to content

Instantly share code, notes, and snippets.

View joneath's full-sized avatar

Jonathan Eatherly joneath

View GitHub Profile
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
@joneath
joneath / gist:2991912
Created June 25, 2012 22:42
Backbone Source Learnings

Backbone Source Learnings

Models

#previousAttributes()

previousAttributes internally uses _.clone(). Previous attributes are only shallow copies so nested objects will be references. This means nested objects will show the current state of the object not the previous!

General

Undefined Assignment

@joneath
joneath / gist:2699316
Created May 15, 2012 05:19
Backbone event awesomeness
openItem: function(item, e){...}
@joneath
joneath / gist:2699259
Created May 15, 2012 05:05
Backbone event sadness
// View
Myview = Backbone.View.extend({
events: {
"click .item": "openItem"
}
openItem: function(e) {
var item = this.collection.get($(e.eventTarget).attr("data-cid"));
...
}
@joneath
joneath / with-model.js
Created May 15, 2012 04:41
Helper method for Backbone.js views to add data bindings to DOM events. It's still up to the user to add data-cid attributes to bound DOM nodes.
// View Usage
// events: {
// "click .message": withModel("messageOverlay")
// },
function withModel(callback) {
return function(e) {
var model = this.collection.getByCid($(e.currentTarget).attr("data-cid"));
this[callback](model, e);
};
@joneath
joneath / typeof_ternary.coffee
Created May 6, 2012 05:42
CoffeeScript Typeof Ternary what?
# CoffeeScript version
params[@options.param] = if model[@options.untilAttr]?() then model[@options.untilAttr]() else model.get(@options.untilAttr)
# Compiled version
params[_this.options.param] = (typeof model[_name = _this.options.untilAttr] === "function" ? model[_name]() : void 0) ? model[_this.options.untilAttr]() : model.get(_this.options.untilAttr);
# Original JS version
params[self.options.param] = typeof(model[self.options.untilAttr]) === "function" ? model[self.options.untilAttr]() : model.get(self.options.untilAttr);
@joneath
joneath / source.coffee
Created May 6, 2012 05:29
Crazy CoffeeScript returns
@destroy = =>
$target.off("scroll", @watchScroll)
return
@enableFetch = ->
fetchOn = true
return
@disableFetch = ->
fetchOn = false
@joneath
joneath / compiled.js
Created May 6, 2012 05:28
Crazy CoffeeScript compiled returns
this.destroy = function() {
return $target.off("scroll", _this.watchScroll);
};
this.enableFetch = function() {
return fetchOn = true;
};
this.disableFetch = function() {
return fetchOn = false;
};
@joneath
joneath / Default (OSX).sublime-keymap.json
Created May 3, 2012 18:49
Sublime Text 2 Key Bindings
[
{ "keys": ["super+shift+y"], "command": "run_macro_file", "args": {"file": "Packages/Default/Delete Line.sublime-macro"} },
{ "keys": ["super+shift+n"], "command": "show_overlay", "args": {"overlay": "goto", "show_files": true} },
{ "keys": ["super+y"], "command": "run_macro_file", "args": {"file": "Packages/Default/Delete Line.sublime-macro"} },
{ "keys": ["super+d"], "command": "duplicate_line" },
{ "keys": ["super+shift+v"], "command": "paste" },
{ "keys": ["super+v"], "command": "paste_and_indent" }
]
@joneath
joneath / Preferences.sublime-settings.json
Created May 3, 2012 18:47
Sublime Text 2 User Preferences
{
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
"ensure_newline_at_eof_on_save": true,
"font_size": 16.0,
"save_on_focus_lost": true,
"tab_size": 2,
"translate_tabs_to_spaces": true,
"spell_check": true,
"fade_fold_buttons": true,
"highlight_line": false,