Skip to content

Instantly share code, notes, and snippets.

View keithnorm's full-sized avatar

Keith Norman keithnorm

View GitHub Profile
@keithnorm
keithnorm / bundle.js
Created July 22, 2012 22:05
build template files
#! /usr/bin/node
var browserify, bundle, fileify, fs, templates;
browserify = require('browserify');
fileify = require('fileify');
fs = require('fs');
@keithnorm
keithnorm / custom_error_class.coffee
Created April 14, 2012 20:05
Inheriting from Error in CoffeeScript doesn't work
class MyError extends Error
message: 'Some error happened'
# will create this javascript
MyError = (function(_super) {
__extends(MyError, _super);
function MyError() {
define('SomeModule', function() {
function SomeModule() {}
return SomeModule;
});
SomeModule = require('SomeModule');
=> Error: Module name 'SomeModule' has not been loaded yet for context
// I get that I should do this
@keithnorm
keithnorm / jquery.request.js
Created April 3, 2012 16:08
jquery request plugin
$.fn.request = function() {
var $form = $(this);
var url = $form.attr('url');
var data = $form.serialize();
return $.ajax({
type: $form.attr('method'),
data: data,
url: url
});
}
@keithnorm
keithnorm / backbonenode.md
Created March 5, 2012 00:10
backbone on node

Installation

run npm install then node app.js then hit localhost:3080.

How It Works

The code runs on both the client and server and generates the same output via a few light abstractions and monkey patches on a basic Backbone app. The main difference is splitting out Backbone.Router into an external routes.js file and separate controllers and actions for each route instead of defining callbacks within the router. This was an alternative to totally hacking Backbone.Router on the server. It allows the main abstraction to boil down to this:

// on the server
var app = express.createServer();
routes.init(app, App.dispatcher);
@keithnorm
keithnorm / anonymous.js
Created February 28, 2012 23:56 — forked from maml/anonymous.js
jquery anonymous pattern?
(function() {
var ghost = 'face';
function blah() {};
$(function() {
blah();
});
}).call(this);
@keithnorm
keithnorm / haml.js
Created February 28, 2012 19:19
haml js made compatible with the browser for benchmarking
// Haml - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
/**
* Module dependencies.
*/
/**
* Version.
*/
@keithnorm
keithnorm / example_controller.js
Created February 26, 2012 00:09
to module or not
// with the "environment" automatically loaded
App.Controllers.PostsController = ApplicationController.extend({
show: function() {
Post.fetch(this.params.id, {
success: function(post) {
this.render(new App.Views.PostView({ post: post });
}
});
}
})
@keithnorm
keithnorm / node-debug.js
Created January 23, 2012 19:26
Node-debug.js
break in node_modules/consolidate/lib/consolidate.js:264
262 var engine = requires.hogan || (requires.hogan = require('hogan.js'));
263 read(path, options, function(err, str){
264 debugger;
265 if (err) return fn(err);
266 try {
debug> print(path) <---- WHY DOESN'T THIS WORK?
ReferenceError: path is not defined
at repl:1:8
at Interface.controlEval (_debugger.js:930:21)
@keithnorm
keithnorm / shapes.js
Created October 27, 2011 19:06
shapes exercise
$(function() {
var parsedJSON = [
{
"type": "circle",
"color": "blue",
"height": "100",
"width": "100"
},