Skip to content

Instantly share code, notes, and snippets.

@twalker
twalker / destroyable.js
Created October 31, 2012 18:52
zombie killer: a backbone view mixin
/**
* View mixin to properly cleanup dom, backbone, and custom event listeners.
* A view zombie killer.
* e.g. myView.destroy(); OR destroyable.destroy.call(myView);
*
* CAVEAT:
* Although custom events will stop triggering, custom event listeners
* are not automatically removed since the binding context is unknown. e.g.
* otherView.on('foo', thisView.doSomething, thisView);
*
@twalker
twalker / .jshintrc
Last active December 9, 2015 17:18
jshint settings
{
"maxcomplexity": 5,
"asi": true,
"strict": false,
"maxstatements": 15,
"maxlen": 120,
"maxdepth": 4,
"maxparams": 4,
"indent": 2,
"smarttabs": true,
@twalker
twalker / sublimetext_useful_shortcuts_pc.md
Last active July 10, 2021 11:34
A fork of useful sublime text keyboard shortcuts. Using markdown and making more readable from github.

Sublime Text - Useful Shortcuts (linux)

Sublime Text 3 documentation
= Right Mouse Button
= Left Mouse Button
= Shift
= Delete
= Enter
←↑→↓ = Arrow keys

Editing

<snippet>
<content><![CDATA[
/**
* ${1:name} model
*/
define(function(require, exports, module){
var Backbone = require('backbone');
return Backbone.Model.extend({
defaults: {
<snippet>
<content><![CDATA[
/**
* ${1:name} collection
*/
define(function(require, exports, module){
var Backbone = require('backbone'),
${1:name} = require('models/${1:name}'),
Globals = require('app/globals');
<snippet>
<content><![CDATA[
/**
* ${1:name} module
*/
define(function(require, exports, module){
return {
${0}
};
@twalker
twalker / mixer.js
Last active December 17, 2015 23:09
utility for mixing methods into objects and backbone klasses.
/**
* Mixer of mixins.
* A utility to copy functionality from mixins to objects.
*/
define(['underscore'], function(lodash){
// Monkey patch a destination object (i.e. Model.prototype, View.prototype, etc.)
// by combining member values that are object literals (e.g. events, defaults),
// functions (e.g. initialize), or arrays (e.g.relations).
// Heavily inspired by: https://github.com/onsi/cocktail
/**
* ## Merging mixin views in backbone.js ##
*
* really just more a test for tumblr gistr
*/
/**
* Merge the mixin (a Backbone.View) into another Backbone.View. Automatically merge events, defaults, and call the parent initializer.
**/
function mergeMixin(view, mixin) {
@twalker
twalker / weight-watcher-test.js
Created July 24, 2013 19:06
Weight watcher mixin for Backbone models to track whether they are thin (fetched by collection) or fat (fetched by model).
require([
'mocha',
'chai',
'sinon',
'mixer',
'backbone',
'models/mixins/weight-watcher'
], function(mocha, chai, sinon, mixer, Backbone, weightWatcher){
// setup
@twalker
twalker / ready.js
Last active December 20, 2015 05:09
ready is Backbone view mixin to indicate when a view has rendered, returning a promise.
/**
* View.ready indicates when a view has rendered, returning a promise.
*
* Needs to be patched into a view's prototype due to the initialize and render methods.
* e.g. mixer.patch(View2.prototype, ready);
**/
define(function(require){
var jQuery = require('jquery');
return {