Skip to content

Instantly share code, notes, and snippets.

View spikebrehm's full-sized avatar

Spike Brehm spikebrehm

View GitHub Profile
var name = 'Bob';
var Person = function(name){
this.name = name;
console.log(name);
}
var me = Person('John');
console.log(name);
function Person(name) {
this.name = name;
}
Person.prototype = {
hello : function() {
return "Hello, " + this.name;
}
};
@spikebrehm
spikebrehm / gist:1716171
Created February 1, 2012 09:40
Serving mustache templates using Node and jsdom
var http = require('http'),
fs = require('fs'),
jsdom = require('jsdom'),
mustache = require('mustache');
var global = this;
var trips = [
{
@spikebrehm
spikebrehm / eventable.js
Created March 30, 2012 17:54
Add Backbone-style events to any function's prototype
/**
* This is intended to be a simple behavior mixin that allows Backbone-style event delegation to be added to any object's prototype.
*
* Use:
*
* function MyView(){ this.$el = $('#my_view'); this.delegateEvents(); }
* $.extend(MyView.prototype, Eventable);
* MyView.prototype.events = {'click a.close': 'close'};
* MyView.prototype.close = function(){ this.$el.hide(); }
*
@spikebrehm
spikebrehm / builder.coffee
Created August 16, 2012 17:08
Require not exported to the window?
...
bundle = browserify()
bundle.addEntry('./assets/coffeescripts/lib/renderer.coffee')
src = bundle.bundle()
fs.writeFileSync @config.coffeePath, src, 'utf8'
...
@spikebrehm
spikebrehm / modifierKey.js
Created September 19, 2012 02:50
Determine if a modifier key is pressed in JavaScript.
// modifierKey used to check if cmd+click, shift+click, etc.
!function($, global){
var $doc = $(document);
var keys;
global.modifierKey = false;
global.keys = keys = {
'UP': 38,
'DOWN': 40,
@spikebrehm
spikebrehm / Directory structure
Created January 22, 2013 23:09
Code for blog post: "We've launched our first Node.js app to production!"
| app
|-- collections
|-- controllers
|-- helpers
|-- models
|-- templates
|-- views
@spikebrehm
spikebrehm / users_controller.coffee
Last active December 11, 2015 12:18
Code for blog post: "We've launched our first Node.js app to production!"
module.exports =
index: (params, callback) ->
fetchSpec =
collection: {collection: 'Users', params: params}
@app.fetcher.fetch fetchSpec, (err, results) ->
callback(err, 'users_index_view', results)
show: (params, callback) ->
fetchSpec =
@spikebrehm
spikebrehm / routes.coffee
Last active December 11, 2015 12:18
Code for blog post: "We've launched our first Node.js app to production!"
module.exports = (match) ->
match 'users/:id', 'users#show'
match 'users', 'users#index'
match 'listings/:id', 'listings#show'
match 'search', 'listings#search', maxAge: 900
@spikebrehm
spikebrehm / listing_view.coffee
Last active December 11, 2015 12:28
Code for blog post: "We've launched our first Node.js app to production!"
BaseView = require('rendr/base/view')
_ = require('underscore')
module.exports = class ListingView extends BaseView
# Straight outta Backbone.View
tagName: 'section'
className: 'listing clearfix'
events:
'click .book_it': 'clickBookIt'