Skip to content

Instantly share code, notes, and snippets.

View jrburke's full-sized avatar

James Burke jrburke

View GitHub Profile
@jrburke
jrburke / a.js
Created November 23, 2011 05:25
Common module boilerplate that sets export value
// Define a module "a" that depends another module called "b". If
// that other module also uses this type of boilerplate, then
// in the browser, it will create a global .b that is used below.
// If you do not want to support the browser global path, then you
// can remove the `root` use and the passing `this` as the first arg to
// the top function.
(function(root, factory) {
if (typeof exports === 'object') {
@jrburke
jrburke / build.js
Created December 22, 2011 05:58
Doing multiple almond builds with a nodejs script, example
//Download jquery.js and place it in the build, do not use require-jquery.js
//in the build, since each of the build layers just needs almond and not the
//full require.js file.
//This file is run in nodejs to do the build: node build.js
//Load the requirejs optimizer
var requirejs = require('./r.js');
//Set up basic config, include config that is
//common to all the requirejs.optimize() calls.
var FakeAPI = (function(){
var api = {
add: null,
addWithCallback: null
}
function makeMethod(method) {
return function() {
var context = this;
var args = arguments;
@jrburke
jrburke / gist:1731666
Created February 3, 2012 18:40
kumascript with promises
//based on:
//https://github.com/lmorchard/kumascript/blob/master/lib/kumascript/templates.js
var q = require('q');
var EJSTemplate = ks_utils.Class(BaseTemplate, {
initialize: function (options) {
this._super('initialize', arguments);
this.template = require('ejs').compile(this.options.source);
},
@jrburke
jrburke / gist:3020525
Created June 29, 2012 20:43
Module concatenation format

Module concatenation format:

JS module systems, whether commonjs/node, AMD or es harmony modules all allow specifying dependencies inline. Example from node:

var a = require('a'),
    b = require('b');
@jrburke
jrburke / gist:3021061
Created June 29, 2012 22:26
volofile
/*jslint regexp: true */
/*global define, console, process */
var connect = require( "connect" ),
crypto = require('crypto'),
fs = require('fs'),
path = require('path'),
buildDir = 'www-built',
pagesDir = 'www-ghpages';
@jrburke
jrburke / config.js
Created November 8, 2012 05:55
RequireJS jQuery adapter approach
//Set up the adapter config, so that any module asking
//for jquery gets an adapter module that has modified
//jquery before other modules can use it.
//Needs RequireJS 2.0+ to work correctly
//More info on map config:
//http://requirejs.org/docs/api.html#config-map
requirejs.config({
map: {
'*': {
'jquery': 'jquery.adapter'
@jrburke
jrburke / DefaultRouter.js
Created November 21, 2012 19:40
wiring backbone views
//Store this file at CarePassMe/Controllers/DefaultRouter.js
define(['backbone', '../Collections/Course', '../Views/CourseList', '../Collections/Page', '../Views/Pages'],
function (Backbone, Course, CourseList, Page, Pages) {
//The default router for the application.
//If you wanted to keep the globals for use outside of requirejs modules,
//note the assignment as part of the return. Otherwise, if the globals
are not needed just return Backbone.Router.extend()...
// Filename: src/js/collections/store/ArticlesCollection.js
define([
'require',
'underscore',
'backbone',
'models/store/ArticleModel'
], function (require, _, Backbone, ArticleModel) {
var ArticlesCollection = Backbone.Collection.extend({
model: function () {
@jrburke
jrburke / gist:5303319
Last active February 11, 2024 23:19
config calls to run tests.
//in test1.js
define({
paths: {},
deps: ['test/_', 'test/$', 'dep1', 'dep2'],
callback: function (_, $, dep1, dep2) {
//test dep1 and dep2 in here
}
});
//in test2.js