Skip to content

Instantly share code, notes, and snippets.

View trezy's full-sized avatar
🥳

Trezy trezy

🥳
View GitHub Profile
@trezy
trezy / backbone.radio.shim.coffee
Last active August 29, 2015 14:07
A shim to replace Backbone.Wreqr with Backbone.Radio in Marionette. Requires Marionette v2.1+ (Coffeescript)
# Based on https://gist.github.com/jmeas/7992474cdb1c5672d88b
radioShim = ( root, factory ) ->
if typeof define is 'function' and define.amd
define [
'backbone.marionette'
'backbone.radio'
'underscore'
], ( Marionette, Radio, _ ) ->
factory Marionette, Radio, _
module.exports = ( grunt, options ) ->
app:
options:
bare: true
sourceMap: true
expand: true
cwd: 'coffee'
src: '**/*.coffee'
dest: 'js'
ext: '.js'
@trezy
trezy / marionette.replaceElement.js
Last active August 29, 2015 14:10
Add `replaceElement` option to Marionette.Region
Marionette.Region.prototype.show = function(view, options) {
var forceShow, isChangingView, isDifferentView, preventDestroy, replaceElement, showOptions, _shouldDestroyView, _shouldReplaceElement, _shouldShowView;
this._ensureElement();
showOptions = options || {};
isDifferentView = view !== this.currentView;
preventDestroy = !!showOptions.preventDestroy;
forceShow = !!showOptions.forceShow;
replaceElement = !!showOptions.replaceElement;
@trezy
trezy / app.js
Created December 9, 2014 18:47
TrezyTV
define(['backbone.intercept', 'marionette'], function(BackboneIntercept, Marionette) {
var App;
return App = (function(_super) {
__extends(App, _super);
function App() {
return App.__super__.constructor.apply(this, arguments);
}
App.prototype.onStart = function() {
@trezy
trezy / gistbook.json
Last active August 29, 2015 14:11
Backbone.Marionette - replaceElement
{"title":"Backbone.Marionette - replaceElement","author":"trezy","pages":[{"pageName":"","sections":[{"type":"text","source":"My biggest gripe about Backbone.Marionette is that `Region`s require a wrapping element. Fortunately I've come up with a way to turn a Region's element into nothing but a placeholder so that it's removed when you use `Region.show()` to display a view. This will likely be in Marionette V3 but I don't want to wait that long so I've written this shim to implement the functionality today.\n\nFirst, we need to add a couple new methods to `Region`. `replaceEl()` will be called when we use `Region.show()` on an empty `Region` and `restoreEl()` will only be called when we use `Region.empty()` to make sure that we don't lose our `Region`'s position in the DOM."},{"type":"javascript","source":"Marionette.Region.prototype.replaceEl = function(view) {\n var parent;\n \n parent = this.el.parentNode;\n parent.replaceChild(view.el, this.el);\n this.replaced = true;\n};\n\nMarionette.Region.proto
@trezy
trezy / docket.js
Created January 26, 2016 20:37
auto docs for express / mongoose app
var _, getRoutes, getSchemas;
_ = require( 'lodash' );
getSchemas = function ( mongoose ) {
var docs, models;
docs = {};
models = mongoose.models;
@trezy
trezy / aggregate.js
Created May 10, 2016 15:54
Total / successful rescue aggregate
[
{
$project: {
successful: {
$cond: ['$successful', 1, 0]
}
},
}, {
$group: {
_id: null,
import Backbone from 'backbone'
import template from 'templates/BlogList.hbs'
export default class BlogList extends Backbone.Marionette.ItemView {
#!/usr/bin/env python
import pprint
import sys
sys.path.append('../pgoapi')
from pgoapi import PGoApi
position = (43.060792, -89.410350, 0)
function * bodyBuilder (next) {
this.body = {
links: {},
meta: {
start_ms: Date.now()
}
}
yield next