Skip to content

Instantly share code, notes, and snippets.

var static = require('node-static');
var file = new(static.Server)('./public', {cache: 1});
require('http').createServer(function (request, response) {
request.addListener('end', function () {
file.serve(request, response, function (e, res) {
if (e && (e.status === 404)) { //still serve the index file
file.serveFile('/index.html', 200, {cache: 84000}, request, response);
}
});
});
@nambrot
nambrot / Bootstrap
Created January 5, 2012 20:50
public/app
var bootstrap = {
loginSuccessful: function() {
FB.api('/me', function (resp) {
userid = resp.id;
});
$('#message').text("Successfully logged in.").addClass('animated fadeIn');
a = new A();
// Start it motherfuckers
Backbone.history.start({pushState: true})
},
var bootstrap = {
loginSuccessful: function() {
FB.api('/me', function (resp) {
userid = resp.id;
});
$('#message').text("Successfully logged in.").addClass('animated fadeIn');
a = new A();
// Start it motherfuckers
Backbone.history.start({pushState: true})
},
newsfeed: function () {
// save current mainpanemodel
a.mainpane.saveState();
// we never fetch the newsfeed to get the latest stuff
var feed = new Feed();
feed.bind('load:finished', this.loadFinished, this);
feed.bind('load:start', this.loadStart, this);
feed.bind('load:end', this.loadEnd, this);
feed.fetch();
a.mainpane.addModel(feed, 0);
@nambrot
nambrot / gist:1567352
Created January 5, 2012 21:17
newsfeed route
newsfeed: function () {
// save current mainpanemodel
a.mainpane.saveState();
// we never fetch the newsfeed to get the latest stuff
var feed = new Feed();
feed.bind('load:finished', this.loadFinished, this);
feed.bind('load:start', this.loadStart, this);
feed.bind('load:end', this.loadEnd, this);
feed.fetch();
a.mainpane.addModel(feed, 0);
addModel: function (model, scroll) {
// remove the old model
var old = $(this.contentview).children();
old.addClass('animated bounceOutLeft');
window.setTimeout(function () {
old.removeClass('animated bounceOutLeft');
old.remove();
}, 1000);
// attach the new model
this.model = model;
// fetch paged responses
sync: function(method, model, options) {
this.trigger('load:start', this);
if (!this.next)
FB.api('/me/home', {'limit': '100'}, options.success)
else
FB.api(this.next.replace(/^(?:\/\/|[^\/]+)*\//, '/'), options.success);
},
parse: function(resp, xhr){
// create scope
var that = this;
// proper parsing of the response paging fields
if (resp.paging && resp.paging.next)
{
this.next = resp.paging.next;
}
else
{
//CollectionView
addItem: function (item) {
// receive the appropriate view from the map in the application object
var view = new a.modelmap[item.get('type')].thumbView({model: item});
// append it to the view
$(this.el).append(view.el);
// update masonry
this.update();
},
// PhotoThumbView
showPhoto: function () {
// remove the selected class from other elements
$(this.el).siblings().removeClass('selected');
// add it
$(this.el).addClass('selected');
// add the photo to the viewer
a.viewer.addModel(this.model, $(a.mainpane.el).scrollTop());
// add object to history
a.navigate('photo/'+this.model.get('id'), false);