Skip to content

Instantly share code, notes, and snippets.

@andrewdeandrade
andrewdeandrade / gist:844569
Created February 25, 2011 21:55
updating model with nested collection attribute
Project = Backbone.Model.extend({
initialize: function() {
_.bindAll(this, 'getRules', 'saveRules');
this.getRules();
this.rules.bind('add', this.saveRules);
this.rules.bind('remove', this.saveRules);
},
getRules: function() {
// My controller:
pg.controllers.Main = Backbone.Controller.extend({
routes: { },
initialize: function () {
pg.account = new pg.model.Account(window.account);
Users = new pg.collections.UserList({ url: "/profiles" });
Backbone.history.start();
// The following is your top-level parent model in serialized JSON format:
var myModel = new Person({
"name" : {
"first_name" : "Andrew",
"last_name" : "de Andrade"
},
"address" : {
"street_address_1" : "Avenida Paulista 1000",
"street_address_2" : "Apt. 101",
@andrewdeandrade
andrewdeandrade / reverse_alphabetical_sort_in_backbone
Created May 1, 2011 04:10
Reverse Alphabetical Sort in Backbone.js
// Assumption: You have a model with a name.
comparator: function (User) {
if (User.get("name")) {
var str = User.get("name");
str = str.toLowerCase();
str = str.split("");
str = _.map(str, function(letter) { return String.fromCharCode(-(letter.charCodeAt(0))) });
return str;
};
namespace.views.MyWizard = Backbone.Views.extend({
initialize: function() {
_.bindAll(this, 'render', 'wizardMethod');
}
render: function() {
this.wizardMethod();
return this;
},
@andrewdeandrade
andrewdeandrade / backbone.history
Created February 5, 2012 23:37
Backbone.History
Backbone.History.prototype.urlHistory = {
stack: [],
currentIndex: 0,
current: function() {
return this.stack[this.currentIndex];
},
previous: function() {
@andrewdeandrade
andrewdeandrade / app.js
Created June 29, 2012 18:19
Node.js ('child_process').spawn bug with SSH
var spawn = require('child_process').spawn
var instance = {
ipAddress: "0.0.0.0"
};
var awsPreSharedKeyPath = '~/.ssh/aws-preshared-key.pem'; // make sure key has permissions 600 with chmod
var spawnArgs = [ '-tt', // force teletype since ssh uses a psuedo-terminal
@andrewdeandrade
andrewdeandrade / gist:3063591
Created July 7, 2012 00:29
Failing Casperjs tests
$ ./bin/casperjs test tests/suites
Test file: /Users/andrew/github/casperjs/tests/suites/casper/agent.js
PASS Default user agent matches /CasperJS/
PASS Default user agent matches /plop/
Test file: /Users/andrew/github/casperjs/tests/suites/casper/capture.js
# Casper.capture()
PASS Casper.capture() captured a screenshot
# Casper.captureBase64()
PASS Casper.captureBase64() rendered a page capture as base64
FAIL CasperError: No element matching selector found: ul
@andrewdeandrade
andrewdeandrade / 0001-Added-deregisterContext-method-to-Engine.patch
Last active August 29, 2015 14:03
0001-Added-deregisterContext-method-to-Engine.patch
From 63aae6759669ccafcf235dd0fdc17f2990cc5699 Mon Sep 17 00:00:00 2001
From: Andrew de Andrade <[email protected]>
Date: Fri, 27 Jun 2014 13:16:01 -0700
Subject: [PATCH] Added deregisterContext method to Engine
---
Engine.js | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/Engine.js b/Engine.js
@andrewdeandrade
andrewdeandrade / gist:4dff6114d9e3f2ef1540
Created November 14, 2014 04:23
syntastic log at log level 63
syntastic: 763.666280: &shell = '/bin/bash', &shellcmdflag = '-c', &shellpipe = '2>&1| tee', &shellquote = '', &shellredir = '>%s 2>&1', &shellslash = 0, &shelltemp = 1, &shellxquote = '', &shellxescape = ''
syntastic: 763.666593: g:syntastic_aggregate_errors = 0
syntastic: 763.666593: g:syntastic_always_populate_loc_list = 0
syntastic: 763.666593: g:syntastic_auto_jump = 0
syntastic: 763.666593: g:syntastic_auto_loc_list = 2
syntastic: 763.666593: g:syntastic_bash_hack = 0
syntastic: 763.666593: g:syntastic_check_on_open = 1
syntastic: 763.666593: g:syntastic_check_on_wq = 1
syntastic: 763.666593: g:syntastic_cursor_columns = 1, b:syntastic_cursor_columns = 1
syntastic: 763.666593: g:syntastic_debug = 63