Skip to content

Instantly share code, notes, and snippets.

View mattpardee's full-sized avatar

Matt Pardee mattpardee

View GitHub Profile
@mattpardee
mattpardee / gist:920497
Created April 14, 2011 20:45
Run-time creation of page and appending it to tab
//First you create your new page element to later be appended to the tab element
var amlPage = new apf.page({
id : "chatUser" + chatUserID,
caption : chatUserName,
name : "groupchat",
closebtn : "true",
childNodes : [
new apf.toolbar({
height : "6"
@mattpardee
mattpardee / mongoc9
Created February 18, 2012 22:10
Mongo and Cloud9
var mongoose = require("mongoose");
var config = require("./config");
// Assemble our connection details from config.js
var loginCredentials = config.username + ':' + config.password;
var dbUrl = config.databaseUrl;
var dbName = config.databaseName;
// Connect to the MongoLab database
mongoose.connect("mongodb://" + loginCredentials + "@" + dbUrl + "/" + dbName);
@mattpardee
mattpardee / gist:2655052
Created May 10, 2012 18:48
Possible spawn stdin problem
var spawn = require('child_process').spawn,
cs = spawn('/Users/mattpardee/Work/test/node_modules/coffee-script/bin/coffee', []);
cs.stdout.on('data', function (data) {
console.log('stdout: ' + data);
setInterval(function() {
console.log(cs.stdin.bytesWritten, cs.stdout.bytesRead);
cs.stdin.write('number = 42\n');
}, 1000);
});
@mattpardee
mattpardee / gist:3100207
Created July 12, 2012 19:08
New Issue template
Put this in your new bookmark "link":
javascript:document.body.appendChild(document.getElementsByName('issue[body]')[0].value="* description: \n* suggested assignee: @\n* environment:\n* expected behavior: \n* occurrence: %\n* browser: chrome, firefox, safari\n* steps to reproduce:\n 1)\n 2)\n 3)\n* screenshot:\n* console log:")
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
}
export PS1='
λ \[\033[1;33m\]\w\[\033[0m\]$(parse_git_branch)$ '

So far, our users#show action pulls down both a User model and a Repos collection for that model. If we were to navigate from users#index to users#show, we already have that user model cached in memory (because we fetched it in order to render the list), but we have to make a roundtrip to the server to fetch the Repos, which aren't part of the User attributes. This means that instead of immediately rendering the users/show view, we wait for the Repos API call to finish. But what if instead we want to lazy-load the Repos so we can render that view immediately for a better user experience?

We can achieve this by lazy-loading models or collections in our subviews. Check out the users#show_lazy action, which demonstrates this approach:

// app/controllers/users_controller.js
module.exports = {
  // ...
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
components.petition_manage.guides.part_
components.petition_manage.guides.part_
components.petition_manage.guides.part_
components.petition_manage.guides.part_eleven
components.petition_manage.guides.part_one
components.petition_manage.guides.part_two
components.petition_manage.guides.part_three
components.petition_manage.guides.part_four
components.petition_manage.guides.part_five
components.petition_manage.guides.part_six
components.petition_manage.guides.part_seven
components.petition_manage.guides.part_eight
components.petition_manage.guides.part_nine
components.petition_manage.guides.part_ten